Lines Matching full:state

683 static int stv090x_read_reg(struct stv090x_state *state, unsigned int reg)  in stv090x_read_reg()  argument
685 const struct stv090x_config *config = state->config; in stv090x_read_reg()
696 ret = i2c_transfer(state->i2c, msg, 2); in stv090x_read_reg()
705 if (unlikely(*state->verbose >= FE_DEBUGREG)) in stv090x_read_reg()
712 static int stv090x_write_regs(struct stv090x_state *state, unsigned int reg, u8 *data, u32 count) in stv090x_write_regs() argument
714 const struct stv090x_config *config = state->config; in stv090x_write_regs()
733 ret = i2c_transfer(state->i2c, &i2c_msg, 1); in stv090x_write_regs()
744 static int stv090x_write_reg(struct stv090x_state *state, unsigned int reg, u8 data) in stv090x_write_reg() argument
748 return stv090x_write_regs(state, reg, &tmp, 1); in stv090x_write_reg()
751 static inline void stv090x_tuner_i2c_lock(struct stv090x_state *state) in stv090x_tuner_i2c_lock() argument
753 if (state->config->tuner_i2c_lock) in stv090x_tuner_i2c_lock()
754 state->config->tuner_i2c_lock(&state->frontend, 1); in stv090x_tuner_i2c_lock()
756 mutex_lock(&state->internal->tuner_lock); in stv090x_tuner_i2c_lock()
759 static inline void stv090x_tuner_i2c_unlock(struct stv090x_state *state) in stv090x_tuner_i2c_unlock() argument
761 if (state->config->tuner_i2c_lock) in stv090x_tuner_i2c_unlock()
762 state->config->tuner_i2c_lock(&state->frontend, 0); in stv090x_tuner_i2c_unlock()
764 mutex_unlock(&state->internal->tuner_lock); in stv090x_tuner_i2c_unlock()
767 static int stv090x_i2c_gate_ctrl(struct stv090x_state *state, int enable) in stv090x_i2c_gate_ctrl() argument
772 * NOTE! A lock is used as a FSM to control the state in which in stv090x_i2c_gate_ctrl()
781 stv090x_tuner_i2c_lock(state); in stv090x_i2c_gate_ctrl()
783 reg = STV090x_READ_DEMOD(state, I2CRPT); in stv090x_i2c_gate_ctrl()
787 if (STV090x_WRITE_DEMOD(state, I2CRPT, reg) < 0) in stv090x_i2c_gate_ctrl()
793 if ((STV090x_WRITE_DEMOD(state, I2CRPT, reg)) < 0) in stv090x_i2c_gate_ctrl()
798 stv090x_tuner_i2c_unlock(state); in stv090x_i2c_gate_ctrl()
803 stv090x_tuner_i2c_unlock(state); in stv090x_i2c_gate_ctrl()
807 static void stv090x_get_lock_tmg(struct stv090x_state *state) in stv090x_get_lock_tmg() argument
809 switch (state->algo) { in stv090x_get_lock_tmg()
812 if (state->srate <= 1500000) { /*10Msps< SR <=15Msps*/ in stv090x_get_lock_tmg()
813 state->DemodTimeout = 1500; in stv090x_get_lock_tmg()
814 state->FecTimeout = 400; in stv090x_get_lock_tmg()
815 } else if (state->srate <= 5000000) { /*10Msps< SR <=15Msps*/ in stv090x_get_lock_tmg()
816 state->DemodTimeout = 1000; in stv090x_get_lock_tmg()
817 state->FecTimeout = 300; in stv090x_get_lock_tmg()
819 state->DemodTimeout = 700; in stv090x_get_lock_tmg()
820 state->FecTimeout = 100; in stv090x_get_lock_tmg()
828 if (state->srate <= 1000000) { /*SR <=1Msps*/ in stv090x_get_lock_tmg()
829 state->DemodTimeout = 4500; in stv090x_get_lock_tmg()
830 state->FecTimeout = 1700; in stv090x_get_lock_tmg()
831 } else if (state->srate <= 2000000) { /*1Msps < SR <= 2Msps */ in stv090x_get_lock_tmg()
832 state->DemodTimeout = 2500; in stv090x_get_lock_tmg()
833 state->FecTimeout = 1100; in stv090x_get_lock_tmg()
834 } else if (state->srate <= 5000000) { /*2Msps < SR <= 5Msps */ in stv090x_get_lock_tmg()
835 state->DemodTimeout = 1000; in stv090x_get_lock_tmg()
836 state->FecTimeout = 550; in stv090x_get_lock_tmg()
837 } else if (state->srate <= 10000000) { /*5Msps < SR <= 10Msps */ in stv090x_get_lock_tmg()
838 state->DemodTimeout = 700; in stv090x_get_lock_tmg()
839 state->FecTimeout = 250; in stv090x_get_lock_tmg()
840 } else if (state->srate <= 20000000) { /*10Msps < SR <= 20Msps */ in stv090x_get_lock_tmg()
841 state->DemodTimeout = 400; in stv090x_get_lock_tmg()
842 state->FecTimeout = 130; in stv090x_get_lock_tmg()
844 state->DemodTimeout = 300; in stv090x_get_lock_tmg()
845 state->FecTimeout = 100; in stv090x_get_lock_tmg()
850 if (state->algo == STV090x_WARM_SEARCH) in stv090x_get_lock_tmg()
851 state->DemodTimeout /= 2; in stv090x_get_lock_tmg()
854 static int stv090x_set_srate(struct stv090x_state *state, u32 srate) in stv090x_set_srate() argument
860 sym /= (state->internal->mclk >> 12); in stv090x_set_srate()
863 sym /= (state->internal->mclk >> 10); in stv090x_set_srate()
866 sym /= (state->internal->mclk >> 7); in stv090x_set_srate()
869 if (STV090x_WRITE_DEMOD(state, SFRINIT1, (sym >> 8) & 0x7f) < 0) /* MSB */ in stv090x_set_srate()
871 if (STV090x_WRITE_DEMOD(state, SFRINIT0, (sym & 0xff)) < 0) /* LSB */ in stv090x_set_srate()
880 static int stv090x_set_max_srate(struct stv090x_state *state, u32 clk, u32 srate) in stv090x_set_max_srate() argument
887 sym /= (state->internal->mclk >> 12); in stv090x_set_max_srate()
890 sym /= (state->internal->mclk >> 10); in stv090x_set_max_srate()
893 sym /= (state->internal->mclk >> 7); in stv090x_set_max_srate()
897 if (STV090x_WRITE_DEMOD(state, SFRUP1, (sym >> 8) & 0x7f) < 0) /* MSB */ in stv090x_set_max_srate()
899 if (STV090x_WRITE_DEMOD(state, SFRUP0, sym & 0xff) < 0) /* LSB */ in stv090x_set_max_srate()
902 if (STV090x_WRITE_DEMOD(state, SFRUP1, 0x7f) < 0) /* MSB */ in stv090x_set_max_srate()
904 if (STV090x_WRITE_DEMOD(state, SFRUP0, 0xff) < 0) /* LSB */ in stv090x_set_max_srate()
914 static int stv090x_set_min_srate(struct stv090x_state *state, u32 clk, u32 srate) in stv090x_set_min_srate() argument
921 sym /= (state->internal->mclk >> 12); in stv090x_set_min_srate()
924 sym /= (state->internal->mclk >> 10); in stv090x_set_min_srate()
927 sym /= (state->internal->mclk >> 7); in stv090x_set_min_srate()
930 if (STV090x_WRITE_DEMOD(state, SFRLOW1, ((sym >> 8) & 0x7f)) < 0) /* MSB */ in stv090x_set_min_srate()
932 if (STV090x_WRITE_DEMOD(state, SFRLOW0, (sym & 0xff)) < 0) /* LSB */ in stv090x_set_min_srate()
960 static int stv090x_set_vit_thacq(struct stv090x_state *state) in stv090x_set_vit_thacq() argument
962 if (STV090x_WRITE_DEMOD(state, VTH12, 0x96) < 0) in stv090x_set_vit_thacq()
964 if (STV090x_WRITE_DEMOD(state, VTH23, 0x64) < 0) in stv090x_set_vit_thacq()
966 if (STV090x_WRITE_DEMOD(state, VTH34, 0x36) < 0) in stv090x_set_vit_thacq()
968 if (STV090x_WRITE_DEMOD(state, VTH56, 0x23) < 0) in stv090x_set_vit_thacq()
970 if (STV090x_WRITE_DEMOD(state, VTH67, 0x1e) < 0) in stv090x_set_vit_thacq()
972 if (STV090x_WRITE_DEMOD(state, VTH78, 0x19) < 0) in stv090x_set_vit_thacq()
980 static int stv090x_set_vit_thtracq(struct stv090x_state *state) in stv090x_set_vit_thtracq() argument
982 if (STV090x_WRITE_DEMOD(state, VTH12, 0xd0) < 0) in stv090x_set_vit_thtracq()
984 if (STV090x_WRITE_DEMOD(state, VTH23, 0x7d) < 0) in stv090x_set_vit_thtracq()
986 if (STV090x_WRITE_DEMOD(state, VTH34, 0x53) < 0) in stv090x_set_vit_thtracq()
988 if (STV090x_WRITE_DEMOD(state, VTH56, 0x2f) < 0) in stv090x_set_vit_thtracq()
990 if (STV090x_WRITE_DEMOD(state, VTH67, 0x24) < 0) in stv090x_set_vit_thtracq()
992 if (STV090x_WRITE_DEMOD(state, VTH78, 0x1f) < 0) in stv090x_set_vit_thtracq()
1000 static int stv090x_set_viterbi(struct stv090x_state *state) in stv090x_set_viterbi() argument
1002 switch (state->search_mode) { in stv090x_set_viterbi()
1004 if (STV090x_WRITE_DEMOD(state, FECM, 0x10) < 0) /* DVB-S and DVB-S2 */ in stv090x_set_viterbi()
1006 if (STV090x_WRITE_DEMOD(state, PRVIT, 0x3f) < 0) /* all puncture rate */ in stv090x_set_viterbi()
1010 if (STV090x_WRITE_DEMOD(state, FECM, 0x00) < 0) /* disable DSS */ in stv090x_set_viterbi()
1012 switch (state->fec) { in stv090x_set_viterbi()
1014 if (STV090x_WRITE_DEMOD(state, PRVIT, 0x01) < 0) in stv090x_set_viterbi()
1019 if (STV090x_WRITE_DEMOD(state, PRVIT, 0x02) < 0) in stv090x_set_viterbi()
1024 if (STV090x_WRITE_DEMOD(state, PRVIT, 0x04) < 0) in stv090x_set_viterbi()
1029 if (STV090x_WRITE_DEMOD(state, PRVIT, 0x08) < 0) in stv090x_set_viterbi()
1034 if (STV090x_WRITE_DEMOD(state, PRVIT, 0x20) < 0) in stv090x_set_viterbi()
1039 if (STV090x_WRITE_DEMOD(state, PRVIT, 0x2f) < 0) /* all */ in stv090x_set_viterbi()
1045 if (STV090x_WRITE_DEMOD(state, FECM, 0x80) < 0) in stv090x_set_viterbi()
1047 switch (state->fec) { in stv090x_set_viterbi()
1049 if (STV090x_WRITE_DEMOD(state, PRVIT, 0x01) < 0) in stv090x_set_viterbi()
1054 if (STV090x_WRITE_DEMOD(state, PRVIT, 0x02) < 0) in stv090x_set_viterbi()
1059 if (STV090x_WRITE_DEMOD(state, PRVIT, 0x10) < 0) in stv090x_set_viterbi()
1064 if (STV090x_WRITE_DEMOD(state, PRVIT, 0x13) < 0) /* 1/2, 2/3, 6/7 */ in stv090x_set_viterbi()
1078 static int stv090x_stop_modcod(struct stv090x_state *state) in stv090x_stop_modcod() argument
1080 if (STV090x_WRITE_DEMOD(state, MODCODLST0, 0xff) < 0) in stv090x_stop_modcod()
1082 if (STV090x_WRITE_DEMOD(state, MODCODLST1, 0xff) < 0) in stv090x_stop_modcod()
1084 if (STV090x_WRITE_DEMOD(state, MODCODLST2, 0xff) < 0) in stv090x_stop_modcod()
1086 if (STV090x_WRITE_DEMOD(state, MODCODLST3, 0xff) < 0) in stv090x_stop_modcod()
1088 if (STV090x_WRITE_DEMOD(state, MODCODLST4, 0xff) < 0) in stv090x_stop_modcod()
1090 if (STV090x_WRITE_DEMOD(state, MODCODLST5, 0xff) < 0) in stv090x_stop_modcod()
1092 if (STV090x_WRITE_DEMOD(state, MODCODLST6, 0xff) < 0) in stv090x_stop_modcod()
1094 if (STV090x_WRITE_DEMOD(state, MODCODLST7, 0xff) < 0) in stv090x_stop_modcod()
1096 if (STV090x_WRITE_DEMOD(state, MODCODLST8, 0xff) < 0) in stv090x_stop_modcod()
1098 if (STV090x_WRITE_DEMOD(state, MODCODLST9, 0xff) < 0) in stv090x_stop_modcod()
1100 if (STV090x_WRITE_DEMOD(state, MODCODLSTA, 0xff) < 0) in stv090x_stop_modcod()
1102 if (STV090x_WRITE_DEMOD(state, MODCODLSTB, 0xff) < 0) in stv090x_stop_modcod()
1104 if (STV090x_WRITE_DEMOD(state, MODCODLSTC, 0xff) < 0) in stv090x_stop_modcod()
1106 if (STV090x_WRITE_DEMOD(state, MODCODLSTD, 0xff) < 0) in stv090x_stop_modcod()
1108 if (STV090x_WRITE_DEMOD(state, MODCODLSTE, 0xff) < 0) in stv090x_stop_modcod()
1110 if (STV090x_WRITE_DEMOD(state, MODCODLSTF, 0xff) < 0) in stv090x_stop_modcod()
1118 static int stv090x_activate_modcod(struct stv090x_state *state) in stv090x_activate_modcod() argument
1120 if (STV090x_WRITE_DEMOD(state, MODCODLST0, 0xff) < 0) in stv090x_activate_modcod()
1122 if (STV090x_WRITE_DEMOD(state, MODCODLST1, 0xfc) < 0) in stv090x_activate_modcod()
1124 if (STV090x_WRITE_DEMOD(state, MODCODLST2, 0xcc) < 0) in stv090x_activate_modcod()
1126 if (STV090x_WRITE_DEMOD(state, MODCODLST3, 0xcc) < 0) in stv090x_activate_modcod()
1128 if (STV090x_WRITE_DEMOD(state, MODCODLST4, 0xcc) < 0) in stv090x_activate_modcod()
1130 if (STV090x_WRITE_DEMOD(state, MODCODLST5, 0xcc) < 0) in stv090x_activate_modcod()
1132 if (STV090x_WRITE_DEMOD(state, MODCODLST6, 0xcc) < 0) in stv090x_activate_modcod()
1134 if (STV090x_WRITE_DEMOD(state, MODCODLST7, 0xcc) < 0) in stv090x_activate_modcod()
1136 if (STV090x_WRITE_DEMOD(state, MODCODLST8, 0xcc) < 0) in stv090x_activate_modcod()
1138 if (STV090x_WRITE_DEMOD(state, MODCODLST9, 0xcc) < 0) in stv090x_activate_modcod()
1140 if (STV090x_WRITE_DEMOD(state, MODCODLSTA, 0xcc) < 0) in stv090x_activate_modcod()
1142 if (STV090x_WRITE_DEMOD(state, MODCODLSTB, 0xcc) < 0) in stv090x_activate_modcod()
1144 if (STV090x_WRITE_DEMOD(state, MODCODLSTC, 0xcc) < 0) in stv090x_activate_modcod()
1146 if (STV090x_WRITE_DEMOD(state, MODCODLSTD, 0xcc) < 0) in stv090x_activate_modcod()
1148 if (STV090x_WRITE_DEMOD(state, MODCODLSTE, 0xcc) < 0) in stv090x_activate_modcod()
1150 if (STV090x_WRITE_DEMOD(state, MODCODLSTF, 0xcf) < 0) in stv090x_activate_modcod()
1159 static int stv090x_activate_modcod_single(struct stv090x_state *state) in stv090x_activate_modcod_single() argument
1162 if (STV090x_WRITE_DEMOD(state, MODCODLST0, 0xff) < 0) in stv090x_activate_modcod_single()
1164 if (STV090x_WRITE_DEMOD(state, MODCODLST1, 0xf0) < 0) in stv090x_activate_modcod_single()
1166 if (STV090x_WRITE_DEMOD(state, MODCODLST2, 0x00) < 0) in stv090x_activate_modcod_single()
1168 if (STV090x_WRITE_DEMOD(state, MODCODLST3, 0x00) < 0) in stv090x_activate_modcod_single()
1170 if (STV090x_WRITE_DEMOD(state, MODCODLST4, 0x00) < 0) in stv090x_activate_modcod_single()
1172 if (STV090x_WRITE_DEMOD(state, MODCODLST5, 0x00) < 0) in stv090x_activate_modcod_single()
1174 if (STV090x_WRITE_DEMOD(state, MODCODLST6, 0x00) < 0) in stv090x_activate_modcod_single()
1176 if (STV090x_WRITE_DEMOD(state, MODCODLST7, 0x00) < 0) in stv090x_activate_modcod_single()
1178 if (STV090x_WRITE_DEMOD(state, MODCODLST8, 0x00) < 0) in stv090x_activate_modcod_single()
1180 if (STV090x_WRITE_DEMOD(state, MODCODLST9, 0x00) < 0) in stv090x_activate_modcod_single()
1182 if (STV090x_WRITE_DEMOD(state, MODCODLSTA, 0x00) < 0) in stv090x_activate_modcod_single()
1184 if (STV090x_WRITE_DEMOD(state, MODCODLSTB, 0x00) < 0) in stv090x_activate_modcod_single()
1186 if (STV090x_WRITE_DEMOD(state, MODCODLSTC, 0x00) < 0) in stv090x_activate_modcod_single()
1188 if (STV090x_WRITE_DEMOD(state, MODCODLSTD, 0x00) < 0) in stv090x_activate_modcod_single()
1190 if (STV090x_WRITE_DEMOD(state, MODCODLSTE, 0x00) < 0) in stv090x_activate_modcod_single()
1192 if (STV090x_WRITE_DEMOD(state, MODCODLSTF, 0x0f) < 0) in stv090x_activate_modcod_single()
1202 static int stv090x_vitclk_ctl(struct stv090x_state *state, int enable) in stv090x_vitclk_ctl() argument
1206 switch (state->demod) { in stv090x_vitclk_ctl()
1208 mutex_lock(&state->internal->demod_lock); in stv090x_vitclk_ctl()
1209 reg = stv090x_read_reg(state, STV090x_STOPCLK2); in stv090x_vitclk_ctl()
1211 if (stv090x_write_reg(state, STV090x_STOPCLK2, reg) < 0) in stv090x_vitclk_ctl()
1213 mutex_unlock(&state->internal->demod_lock); in stv090x_vitclk_ctl()
1217 mutex_lock(&state->internal->demod_lock); in stv090x_vitclk_ctl()
1218 reg = stv090x_read_reg(state, STV090x_STOPCLK2); in stv090x_vitclk_ctl()
1220 if (stv090x_write_reg(state, STV090x_STOPCLK2, reg) < 0) in stv090x_vitclk_ctl()
1222 mutex_unlock(&state->internal->demod_lock); in stv090x_vitclk_ctl()
1231 mutex_unlock(&state->internal->demod_lock); in stv090x_vitclk_ctl()
1236 static int stv090x_dvbs_track_crl(struct stv090x_state *state) in stv090x_dvbs_track_crl() argument
1238 if (state->internal->dev_ver >= 0x30) { in stv090x_dvbs_track_crl()
1240 if (state->srate >= 15000000) { in stv090x_dvbs_track_crl()
1241 if (STV090x_WRITE_DEMOD(state, ACLC, 0x2b) < 0) in stv090x_dvbs_track_crl()
1243 if (STV090x_WRITE_DEMOD(state, BCLC, 0x1a) < 0) in stv090x_dvbs_track_crl()
1245 } else if ((state->srate >= 7000000) && (15000000 > state->srate)) { in stv090x_dvbs_track_crl()
1246 if (STV090x_WRITE_DEMOD(state, ACLC, 0x0c) < 0) in stv090x_dvbs_track_crl()
1248 if (STV090x_WRITE_DEMOD(state, BCLC, 0x1b) < 0) in stv090x_dvbs_track_crl()
1250 } else if (state->srate < 7000000) { in stv090x_dvbs_track_crl()
1251 if (STV090x_WRITE_DEMOD(state, ACLC, 0x2c) < 0) in stv090x_dvbs_track_crl()
1253 if (STV090x_WRITE_DEMOD(state, BCLC, 0x1c) < 0) in stv090x_dvbs_track_crl()
1259 if (STV090x_WRITE_DEMOD(state, ACLC, 0x1a) < 0) in stv090x_dvbs_track_crl()
1261 if (STV090x_WRITE_DEMOD(state, BCLC, 0x09) < 0) in stv090x_dvbs_track_crl()
1270 static int stv090x_delivery_search(struct stv090x_state *state) in stv090x_delivery_search() argument
1274 switch (state->search_mode) { in stv090x_delivery_search()
1277 reg = STV090x_READ_DEMOD(state, DMDCFGMD); in stv090x_delivery_search()
1280 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) in stv090x_delivery_search()
1286 if (stv090x_vitclk_ctl(state, 0) < 0) in stv090x_delivery_search()
1289 if (stv090x_dvbs_track_crl(state) < 0) in stv090x_delivery_search()
1292 if (STV090x_WRITE_DEMOD(state, CAR2CFG, 0x22) < 0) /* disable DVB-S2 */ in stv090x_delivery_search()
1295 if (stv090x_set_vit_thacq(state) < 0) in stv090x_delivery_search()
1297 if (stv090x_set_viterbi(state) < 0) in stv090x_delivery_search()
1302 reg = STV090x_READ_DEMOD(state, DMDCFGMD); in stv090x_delivery_search()
1305 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) in stv090x_delivery_search()
1309 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) in stv090x_delivery_search()
1312 if (stv090x_vitclk_ctl(state, 1) < 0) in stv090x_delivery_search()
1315 if (STV090x_WRITE_DEMOD(state, ACLC, 0x1a) < 0) /* stop DVB-S CR loop */ in stv090x_delivery_search()
1317 if (STV090x_WRITE_DEMOD(state, BCLC, 0x09) < 0) in stv090x_delivery_search()
1320 if (state->internal->dev_ver <= 0x20) { in stv090x_delivery_search()
1322 if (STV090x_WRITE_DEMOD(state, CAR2CFG, 0x26) < 0) in stv090x_delivery_search()
1326 if (STV090x_WRITE_DEMOD(state, CAR2CFG, 0x66) < 0) in stv090x_delivery_search()
1330 if (state->demod_mode != STV090x_SINGLE) { in stv090x_delivery_search()
1332 if (stv090x_activate_modcod(state) < 0) in stv090x_delivery_search()
1339 if (stv090x_activate_modcod_single(state) < 0) in stv090x_delivery_search()
1343 if (stv090x_set_vit_thtracq(state) < 0) in stv090x_delivery_search()
1350 reg = STV090x_READ_DEMOD(state, DMDCFGMD); in stv090x_delivery_search()
1353 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) in stv090x_delivery_search()
1357 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) in stv090x_delivery_search()
1360 if (stv090x_vitclk_ctl(state, 0) < 0) in stv090x_delivery_search()
1363 if (stv090x_dvbs_track_crl(state) < 0) in stv090x_delivery_search()
1366 if (state->internal->dev_ver <= 0x20) { in stv090x_delivery_search()
1368 if (STV090x_WRITE_DEMOD(state, CAR2CFG, 0x26) < 0) in stv090x_delivery_search()
1372 if (STV090x_WRITE_DEMOD(state, CAR2CFG, 0x66) < 0) in stv090x_delivery_search()
1376 if (state->demod_mode != STV090x_SINGLE) { in stv090x_delivery_search()
1378 if (stv090x_activate_modcod(state) < 0) in stv090x_delivery_search()
1385 if (stv090x_activate_modcod_single(state) < 0) in stv090x_delivery_search()
1389 if (stv090x_set_vit_thacq(state) < 0) in stv090x_delivery_search()
1392 if (stv090x_set_viterbi(state) < 0) in stv090x_delivery_search()
1402 static int stv090x_start_search(struct stv090x_state *state) in stv090x_start_search() argument
1408 reg = STV090x_READ_DEMOD(state, DMDISTATE); in stv090x_start_search()
1410 if (STV090x_WRITE_DEMOD(state, DMDISTATE, reg) < 0) in stv090x_start_search()
1413 if (state->internal->dev_ver <= 0x20) { in stv090x_start_search()
1414 if (state->srate <= 5000000) { in stv090x_start_search()
1415 if (STV090x_WRITE_DEMOD(state, CARCFG, 0x44) < 0) in stv090x_start_search()
1417 if (STV090x_WRITE_DEMOD(state, CFRUP1, 0x0f) < 0) in stv090x_start_search()
1419 if (STV090x_WRITE_DEMOD(state, CFRUP0, 0xff) < 0) in stv090x_start_search()
1421 if (STV090x_WRITE_DEMOD(state, CFRLOW1, 0xf0) < 0) in stv090x_start_search()
1423 if (STV090x_WRITE_DEMOD(state, CFRLOW0, 0x00) < 0) in stv090x_start_search()
1427 if (STV090x_WRITE_DEMOD(state, RTCS2, 0x68) < 0) in stv090x_start_search()
1432 if (STV090x_WRITE_DEMOD(state, CARCFG, 0xc4) < 0) in stv090x_start_search()
1435 if (STV090x_WRITE_DEMOD(state, RTCS2, 0x44) < 0) in stv090x_start_search()
1440 if (state->srate <= 5000000) { in stv090x_start_search()
1442 STV090x_WRITE_DEMOD(state, RTCS2, 0x68); in stv090x_start_search()
1445 STV090x_WRITE_DEMOD(state, RTCS2, 0x44); in stv090x_start_search()
1449 STV090x_WRITE_DEMOD(state, CARCFG, 0x46); in stv090x_start_search()
1451 if (state->algo == STV090x_WARM_SEARCH) { in stv090x_start_search()
1457 freq_abs /= (state->internal->mclk / 1000); in stv090x_start_search()
1465 freq_abs = (state->search_range / 2000) + 600; in stv090x_start_search()
1467 freq_abs /= (state->internal->mclk / 1000); in stv090x_start_search()
1471 if (STV090x_WRITE_DEMOD(state, CFRUP1, MSB(freq)) < 0) in stv090x_start_search()
1473 if (STV090x_WRITE_DEMOD(state, CFRUP0, LSB(freq)) < 0) in stv090x_start_search()
1478 if (STV090x_WRITE_DEMOD(state, CFRLOW1, MSB(freq)) < 0) in stv090x_start_search()
1480 if (STV090x_WRITE_DEMOD(state, CFRLOW0, LSB(freq)) < 0) in stv090x_start_search()
1485 if (STV090x_WRITE_DEMOD(state, CFRINIT1, 0) < 0) in stv090x_start_search()
1487 if (STV090x_WRITE_DEMOD(state, CFRINIT0, 0) < 0) in stv090x_start_search()
1490 if (state->internal->dev_ver >= 0x20) { in stv090x_start_search()
1491 if (STV090x_WRITE_DEMOD(state, EQUALCFG, 0x41) < 0) in stv090x_start_search()
1493 if (STV090x_WRITE_DEMOD(state, FFECFG, 0x41) < 0) in stv090x_start_search()
1496 if ((state->search_mode == STV090x_SEARCH_DVBS1) || in stv090x_start_search()
1497 (state->search_mode == STV090x_SEARCH_DSS) || in stv090x_start_search()
1498 (state->search_mode == STV090x_SEARCH_AUTO)) { in stv090x_start_search()
1500 if (STV090x_WRITE_DEMOD(state, VITSCALE, 0x82) < 0) in stv090x_start_search()
1502 if (STV090x_WRITE_DEMOD(state, VAVSRVIT, 0x00) < 0) in stv090x_start_search()
1507 if (STV090x_WRITE_DEMOD(state, SFRSTEP, 0x00) < 0) in stv090x_start_search()
1509 if (STV090x_WRITE_DEMOD(state, TMGTHRISE, 0xe0) < 0) in stv090x_start_search()
1511 if (STV090x_WRITE_DEMOD(state, TMGTHFALL, 0xc0) < 0) in stv090x_start_search()
1514 reg = STV090x_READ_DEMOD(state, DMDCFGMD); in stv090x_start_search()
1517 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) in stv090x_start_search()
1519 reg = STV090x_READ_DEMOD(state, DMDCFG2); in stv090x_start_search()
1521 if (STV090x_WRITE_DEMOD(state, DMDCFG2, reg) < 0) in stv090x_start_search()
1524 if (STV090x_WRITE_DEMOD(state, RTC, 0x88) < 0) in stv090x_start_search()
1527 if (state->internal->dev_ver >= 0x20) { in stv090x_start_search()
1529 if (state->srate < 2000000) { in stv090x_start_search()
1530 if (state->internal->dev_ver <= 0x20) { in stv090x_start_search()
1532 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x39) < 0) in stv090x_start_search()
1536 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x89) < 0) in stv090x_start_search()
1539 if (STV090x_WRITE_DEMOD(state, CARHDR, 0x40) < 0) in stv090x_start_search()
1541 } else if (state->srate < 10000000) { in stv090x_start_search()
1542 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x4c) < 0) in stv090x_start_search()
1544 if (STV090x_WRITE_DEMOD(state, CARHDR, 0x20) < 0) in stv090x_start_search()
1547 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x4b) < 0) in stv090x_start_search()
1549 if (STV090x_WRITE_DEMOD(state, CARHDR, 0x20) < 0) in stv090x_start_search()
1553 if (state->srate < 10000000) { in stv090x_start_search()
1554 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0xef) < 0) in stv090x_start_search()
1557 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0xed) < 0) in stv090x_start_search()
1562 switch (state->algo) { in stv090x_start_search()
1567 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x1f) < 0) in stv090x_start_search()
1569 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x18) < 0) in stv090x_start_search()
1575 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x1f) < 0) in stv090x_start_search()
1577 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x15) < 0) in stv090x_start_search()
1590 static int stv090x_get_agc2_min_level(struct stv090x_state *state) in stv090x_get_agc2_min_level() argument
1595 if (STV090x_WRITE_DEMOD(state, AGC2REF, 0x38) < 0) in stv090x_get_agc2_min_level()
1597 reg = STV090x_READ_DEMOD(state, DMDCFGMD); in stv090x_get_agc2_min_level()
1600 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) in stv090x_get_agc2_min_level()
1603 if (STV090x_WRITE_DEMOD(state, SFRUP1, 0x83) < 0) /* SR = 65 Msps Max */ in stv090x_get_agc2_min_level()
1605 if (STV090x_WRITE_DEMOD(state, SFRUP0, 0xc0) < 0) in stv090x_get_agc2_min_level()
1607 if (STV090x_WRITE_DEMOD(state, SFRLOW1, 0x82) < 0) /* SR= 400 ksps Min */ in stv090x_get_agc2_min_level()
1609 if (STV090x_WRITE_DEMOD(state, SFRLOW0, 0xa0) < 0) in stv090x_get_agc2_min_level()
1611 if (STV090x_WRITE_DEMOD(state, DMDTOM, 0x00) < 0) /* stop acq @ coarse carrier state */ in stv090x_get_agc2_min_level()
1613 if (stv090x_set_srate(state, 1000000) < 0) in stv090x_get_agc2_min_level()
1616 steps = state->search_range / 1000000; in stv090x_get_agc2_min_level()
1621 freq_step = (1000000 * 256) / (state->internal->mclk / 256); in stv090x_get_agc2_min_level()
1632 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x5c) < 0) /* Demod RESET */ in stv090x_get_agc2_min_level()
1634 if (STV090x_WRITE_DEMOD(state, CFRINIT1, (freq_init >> 8) & 0xff) < 0) in stv090x_get_agc2_min_level()
1636 if (STV090x_WRITE_DEMOD(state, CFRINIT0, freq_init & 0xff) < 0) in stv090x_get_agc2_min_level()
1638 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x58) < 0) /* Demod RESET */ in stv090x_get_agc2_min_level()
1644 agc2 += (STV090x_READ_DEMOD(state, AGC2I1) << 8) | in stv090x_get_agc2_min_level()
1645 STV090x_READ_DEMOD(state, AGC2I0); in stv090x_get_agc2_min_level()
1658 static u32 stv090x_get_srate(struct stv090x_state *state, u32 clk) in stv090x_get_srate() argument
1663 r3 = STV090x_READ_DEMOD(state, SFR3); in stv090x_get_srate()
1664 r2 = STV090x_READ_DEMOD(state, SFR2); in stv090x_get_srate()
1665 r1 = STV090x_READ_DEMOD(state, SFR1); in stv090x_get_srate()
1666 r0 = STV090x_READ_DEMOD(state, SFR0); in stv090x_get_srate()
1683 static u32 stv090x_srate_srch_coarse(struct stv090x_state *state) in stv090x_srate_srch_coarse() argument
1685 struct dvb_frontend *fe = &state->frontend; in stv090x_srate_srch_coarse()
1692 if (state->internal->dev_ver >= 0x30) in stv090x_srate_srch_coarse()
1697 reg = STV090x_READ_DEMOD(state, DMDISTATE); in stv090x_srate_srch_coarse()
1699 if (STV090x_WRITE_DEMOD(state, DMDISTATE, reg) < 0) in stv090x_srate_srch_coarse()
1701 if (STV090x_WRITE_DEMOD(state, TMGCFG, 0x12) < 0) in stv090x_srate_srch_coarse()
1703 if (STV090x_WRITE_DEMOD(state, TMGCFG2, 0xc0) < 0) in stv090x_srate_srch_coarse()
1705 if (STV090x_WRITE_DEMOD(state, TMGTHRISE, 0xf0) < 0) in stv090x_srate_srch_coarse()
1707 if (STV090x_WRITE_DEMOD(state, TMGTHFALL, 0xe0) < 0) in stv090x_srate_srch_coarse()
1709 reg = STV090x_READ_DEMOD(state, DMDCFGMD); in stv090x_srate_srch_coarse()
1712 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) in stv090x_srate_srch_coarse()
1715 if (STV090x_WRITE_DEMOD(state, SFRUP1, 0x83) < 0) in stv090x_srate_srch_coarse()
1717 if (STV090x_WRITE_DEMOD(state, SFRUP0, 0xc0) < 0) in stv090x_srate_srch_coarse()
1719 if (STV090x_WRITE_DEMOD(state, SFRLOW1, 0x82) < 0) in stv090x_srate_srch_coarse()
1721 if (STV090x_WRITE_DEMOD(state, SFRLOW0, 0xa0) < 0) in stv090x_srate_srch_coarse()
1723 if (STV090x_WRITE_DEMOD(state, DMDTOM, 0x00) < 0) in stv090x_srate_srch_coarse()
1725 if (STV090x_WRITE_DEMOD(state, AGC2REF, 0x50) < 0) in stv090x_srate_srch_coarse()
1728 if (state->internal->dev_ver >= 0x30) { in stv090x_srate_srch_coarse()
1729 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x99) < 0) in stv090x_srate_srch_coarse()
1731 if (STV090x_WRITE_DEMOD(state, SFRSTEP, 0x98) < 0) in stv090x_srate_srch_coarse()
1734 } else if (state->internal->dev_ver >= 0x20) { in stv090x_srate_srch_coarse()
1735 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x6a) < 0) in stv090x_srate_srch_coarse()
1737 if (STV090x_WRITE_DEMOD(state, SFRSTEP, 0x95) < 0) in stv090x_srate_srch_coarse()
1741 if (state->srate <= 2000000) in stv090x_srate_srch_coarse()
1743 else if (state->srate <= 5000000) in stv090x_srate_srch_coarse()
1745 else if (state->srate <= 12000000) in stv090x_srate_srch_coarse()
1750 steps = -1 + ((state->search_range / 1000) / car_step); in stv090x_srate_srch_coarse()
1757 car_step = (state->search_range / 1000) / 10; in stv090x_srate_srch_coarse()
1761 freq = state->frequency; in stv090x_srate_srch_coarse()
1764 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x5f) < 0) /* Demod RESET */ in stv090x_srate_srch_coarse()
1766 if (STV090x_WRITE_DEMOD(state, CFRINIT1, 0x00) < 0) in stv090x_srate_srch_coarse()
1768 if (STV090x_WRITE_DEMOD(state, CFRINIT0, 0x00) < 0) in stv090x_srate_srch_coarse()
1770 if (STV090x_WRITE_DEMOD(state, SFRINIT1, 0x00) < 0) in stv090x_srate_srch_coarse()
1772 if (STV090x_WRITE_DEMOD(state, SFRINIT0, 0x00) < 0) in stv090x_srate_srch_coarse()
1775 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x40) < 0) in stv090x_srate_srch_coarse()
1779 reg = STV090x_READ_DEMOD(state, DSTATUS); in stv090x_srate_srch_coarse()
1782 agc2 += (STV090x_READ_DEMOD(state, AGC2I1) << 8) | in stv090x_srate_srch_coarse()
1783 STV090x_READ_DEMOD(state, AGC2I0); in stv090x_srate_srch_coarse()
1786 srate_coarse = stv090x_get_srate(state, state->internal->mclk); in stv090x_srate_srch_coarse()
1799 if (stv090x_i2c_gate_ctrl(state, 1) < 0) in stv090x_srate_srch_coarse()
1802 if (state->config->tuner_set_frequency) { in stv090x_srate_srch_coarse()
1803 if (state->config->tuner_set_frequency(fe, freq) < 0) in stv090x_srate_srch_coarse()
1807 if (state->config->tuner_set_bandwidth) { in stv090x_srate_srch_coarse()
1808 if (state->config->tuner_set_bandwidth(fe, state->tuner_bw) < 0) in stv090x_srate_srch_coarse()
1812 if (stv090x_i2c_gate_ctrl(state, 0) < 0) in stv090x_srate_srch_coarse()
1817 if (stv090x_i2c_gate_ctrl(state, 1) < 0) in stv090x_srate_srch_coarse()
1820 if (state->config->tuner_get_status) { in stv090x_srate_srch_coarse()
1821 if (state->config->tuner_get_status(fe, &reg) < 0) in stv090x_srate_srch_coarse()
1830 if (stv090x_i2c_gate_ctrl(state, 0) < 0) in stv090x_srate_srch_coarse()
1838 srate_coarse = stv090x_get_srate(state, state->internal->mclk); in stv090x_srate_srch_coarse()
1843 stv090x_i2c_gate_ctrl(state, 0); in stv090x_srate_srch_coarse()
1849 static u32 stv090x_srate_srch_fine(struct stv090x_state *state) in stv090x_srate_srch_fine() argument
1853 srate_coarse = stv090x_get_srate(state, state->internal->mclk); in stv090x_srate_srch_fine()
1854 freq_coarse = STV090x_READ_DEMOD(state, CFR2) << 8; in stv090x_srate_srch_fine()
1855 freq_coarse |= STV090x_READ_DEMOD(state, CFR1); in stv090x_srate_srch_fine()
1858 if (sym < state->srate) in stv090x_srate_srch_fine()
1861 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x1f) < 0) /* Demod RESET */ in stv090x_srate_srch_fine()
1863 if (STV090x_WRITE_DEMOD(state, TMGCFG2, 0xc1) < 0) in stv090x_srate_srch_fine()
1865 if (STV090x_WRITE_DEMOD(state, TMGTHRISE, 0x20) < 0) in stv090x_srate_srch_fine()
1867 if (STV090x_WRITE_DEMOD(state, TMGTHFALL, 0x00) < 0) in stv090x_srate_srch_fine()
1869 if (STV090x_WRITE_DEMOD(state, TMGCFG, 0xd2) < 0) in stv090x_srate_srch_fine()
1871 reg = STV090x_READ_DEMOD(state, DMDCFGMD); in stv090x_srate_srch_fine()
1873 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) in stv090x_srate_srch_fine()
1876 if (STV090x_WRITE_DEMOD(state, AGC2REF, 0x38) < 0) in stv090x_srate_srch_fine()
1879 if (state->internal->dev_ver >= 0x30) { in stv090x_srate_srch_fine()
1880 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x79) < 0) in stv090x_srate_srch_fine()
1882 } else if (state->internal->dev_ver >= 0x20) { in stv090x_srate_srch_fine()
1883 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x49) < 0) in stv090x_srate_srch_fine()
1890 sym /= (state->internal->mclk / 1000); in stv090x_srate_srch_fine()
1891 if (STV090x_WRITE_DEMOD(state, SFRUP1, (sym >> 8) & 0x7f) < 0) in stv090x_srate_srch_fine()
1893 if (STV090x_WRITE_DEMOD(state, SFRUP0, sym & 0xff) < 0) in stv090x_srate_srch_fine()
1897 sym /= (state->internal->mclk / 1000); in stv090x_srate_srch_fine()
1898 if (STV090x_WRITE_DEMOD(state, SFRLOW1, (sym >> 8) & 0x7f) < 0) in stv090x_srate_srch_fine()
1900 if (STV090x_WRITE_DEMOD(state, SFRLOW0, sym & 0xff) < 0) in stv090x_srate_srch_fine()
1903 sym /= (state->internal->mclk / 1000); in stv090x_srate_srch_fine()
1904 if (STV090x_WRITE_DEMOD(state, SFRINIT1, (sym >> 8) & 0xff) < 0) in stv090x_srate_srch_fine()
1906 if (STV090x_WRITE_DEMOD(state, SFRINIT0, sym & 0xff) < 0) in stv090x_srate_srch_fine()
1911 sym /= (state->internal->mclk / 100); in stv090x_srate_srch_fine()
1912 if (STV090x_WRITE_DEMOD(state, SFRUP1, (sym >> 8) & 0x7f) < 0) in stv090x_srate_srch_fine()
1914 if (STV090x_WRITE_DEMOD(state, SFRUP0, sym & 0xff) < 0) in stv090x_srate_srch_fine()
1918 sym /= (state->internal->mclk / 100); in stv090x_srate_srch_fine()
1919 if (STV090x_WRITE_DEMOD(state, SFRLOW1, (sym >> 8) & 0x7f) < 0) in stv090x_srate_srch_fine()
1921 if (STV090x_WRITE_DEMOD(state, SFRLOW0, sym & 0xff) < 0) in stv090x_srate_srch_fine()
1924 sym /= (state->internal->mclk / 100); in stv090x_srate_srch_fine()
1925 if (STV090x_WRITE_DEMOD(state, SFRINIT1, (sym >> 8) & 0xff) < 0) in stv090x_srate_srch_fine()
1927 if (STV090x_WRITE_DEMOD(state, SFRINIT0, sym & 0xff) < 0) in stv090x_srate_srch_fine()
1930 if (STV090x_WRITE_DEMOD(state, DMDTOM, 0x20) < 0) in stv090x_srate_srch_fine()
1932 if (STV090x_WRITE_DEMOD(state, CFRINIT1, (freq_coarse >> 8) & 0xff) < 0) in stv090x_srate_srch_fine()
1934 if (STV090x_WRITE_DEMOD(state, CFRINIT0, freq_coarse & 0xff) < 0) in stv090x_srate_srch_fine()
1936 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x15) < 0) /* trigger acquisition */ in stv090x_srate_srch_fine()
1947 static int stv090x_get_dmdlock(struct stv090x_state *state, s32 timeout) in stv090x_get_dmdlock() argument
1954 reg = STV090x_READ_DEMOD(state, DMDSTATE); in stv090x_get_dmdlock()
1966 reg = STV090x_READ_DEMOD(state, DSTATUS); in stv090x_get_dmdlock()
1981 static int stv090x_blind_search(struct stv090x_state *state) in stv090x_blind_search() argument
1992 agc2 = stv090x_get_agc2_min_level(state); in stv090x_blind_search()
1994 if (agc2 > STV090x_SEARCH_AGC2_TH(state->internal->dev_ver)) { in stv090x_blind_search()
1998 if (state->internal->dev_ver <= 0x20) { in stv090x_blind_search()
1999 if (STV090x_WRITE_DEMOD(state, CARCFG, 0xc4) < 0) in stv090x_blind_search()
2003 if (STV090x_WRITE_DEMOD(state, CARCFG, 0x06) < 0) in stv090x_blind_search()
2007 if (STV090x_WRITE_DEMOD(state, RTCS2, 0x44) < 0) in stv090x_blind_search()
2010 if (state->internal->dev_ver >= 0x20) { in stv090x_blind_search()
2011 if (STV090x_WRITE_DEMOD(state, EQUALCFG, 0x41) < 0) in stv090x_blind_search()
2013 if (STV090x_WRITE_DEMOD(state, FFECFG, 0x41) < 0) in stv090x_blind_search()
2015 if (STV090x_WRITE_DEMOD(state, VITSCALE, 0x82) < 0) in stv090x_blind_search()
2017 if (STV090x_WRITE_DEMOD(state, VAVSRVIT, 0x00) < 0) /* set viterbi hysteresis */ in stv090x_blind_search()
2023 if (STV090x_WRITE_DEMOD(state, KREFTMG, k_ref) < 0) in stv090x_blind_search()
2025 if (stv090x_srate_srch_coarse(state) != 0) { in stv090x_blind_search()
2026 srate_coarse = stv090x_srate_srch_fine(state); in stv090x_blind_search()
2028 stv090x_get_lock_tmg(state); in stv090x_blind_search()
2029 lock = stv090x_get_dmdlock(state, in stv090x_blind_search()
2030 state->DemodTimeout); in stv090x_blind_search()
2038 agc2 += (STV090x_READ_DEMOD(state, AGC2I1) << 8) | in stv090x_blind_search()
2039 STV090x_READ_DEMOD(state, AGC2I0); in stv090x_blind_search()
2042 reg = STV090x_READ_DEMOD(state, DSTATUS2); in stv090x_blind_search()
2064 static int stv090x_chk_tmg(struct stv090x_state *state) in stv090x_chk_tmg() argument
2071 freq = STV090x_READ_DEMOD(state, CARFREQ); in stv090x_chk_tmg()
2072 tmg_thh = STV090x_READ_DEMOD(state, TMGTHRISE); in stv090x_chk_tmg()
2073 tmg_thl = STV090x_READ_DEMOD(state, TMGTHFALL); in stv090x_chk_tmg()
2074 if (STV090x_WRITE_DEMOD(state, TMGTHRISE, 0x20) < 0) in stv090x_chk_tmg()
2076 if (STV090x_WRITE_DEMOD(state, TMGTHFALL, 0x00) < 0) in stv090x_chk_tmg()
2079 reg = STV090x_READ_DEMOD(state, DMDCFGMD); in stv090x_chk_tmg()
2081 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) in stv090x_chk_tmg()
2083 if (STV090x_WRITE_DEMOD(state, RTC, 0x80) < 0) in stv090x_chk_tmg()
2086 if (STV090x_WRITE_DEMOD(state, RTCS2, 0x40) < 0) in stv090x_chk_tmg()
2088 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x00) < 0) in stv090x_chk_tmg()
2091 if (STV090x_WRITE_DEMOD(state, CFRINIT1, 0x00) < 0) /* set car ofset to 0 */ in stv090x_chk_tmg()
2093 if (STV090x_WRITE_DEMOD(state, CFRINIT0, 0x00) < 0) in stv090x_chk_tmg()
2095 if (STV090x_WRITE_DEMOD(state, AGC2REF, 0x65) < 0) in stv090x_chk_tmg()
2098 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x18) < 0) /* trigger acquisition */ in stv090x_chk_tmg()
2103 reg = STV090x_READ_DEMOD(state, DSTATUS); in stv090x_chk_tmg()
2111 if (STV090x_WRITE_DEMOD(state, AGC2REF, 0x38) < 0) in stv090x_chk_tmg()
2113 if (STV090x_WRITE_DEMOD(state, RTC, 0x88) < 0) /* DVB-S1 timing */ in stv090x_chk_tmg()
2115 if (STV090x_WRITE_DEMOD(state, RTCS2, 0x68) < 0) /* DVB-S2 timing */ in stv090x_chk_tmg()
2118 if (STV090x_WRITE_DEMOD(state, CARFREQ, freq) < 0) in stv090x_chk_tmg()
2120 if (STV090x_WRITE_DEMOD(state, TMGTHRISE, tmg_thh) < 0) in stv090x_chk_tmg()
2122 if (STV090x_WRITE_DEMOD(state, TMGTHFALL, tmg_thl) < 0) in stv090x_chk_tmg()
2132 static int stv090x_get_coldlock(struct stv090x_state *state, s32 timeout_dmd) in stv090x_get_coldlock() argument
2134 struct dvb_frontend *fe = &state->frontend; in stv090x_get_coldlock()
2140 if (state->srate >= 10000000) in stv090x_get_coldlock()
2145 lock = stv090x_get_dmdlock(state, timeout_lock); /* cold start wait */ in stv090x_get_coldlock()
2149 if (state->srate >= 10000000) { in stv090x_get_coldlock()
2150 if (stv090x_chk_tmg(state)) { in stv090x_get_coldlock()
2151 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x1f) < 0) in stv090x_get_coldlock()
2153 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x15) < 0) in stv090x_get_coldlock()
2155 return stv090x_get_dmdlock(state, timeout_dmd); in stv090x_get_coldlock()
2160 if (state->srate <= 4000000) in stv090x_get_coldlock()
2162 else if (state->srate <= 7000000) in stv090x_get_coldlock()
2164 else if (state->srate <= 10000000) in stv090x_get_coldlock()
2169 steps = (state->search_range / 1000) / car_step; in stv090x_get_coldlock()
2180 freq = state->frequency; in stv090x_get_coldlock()
2181 state->tuner_bw = stv090x_car_width(state->srate, state->rolloff) + state->srate; in stv090x_get_coldlock()
2189 if (stv090x_i2c_gate_ctrl(state, 1) < 0) in stv090x_get_coldlock()
2192 if (state->config->tuner_set_frequency) { in stv090x_get_coldlock()
2193 if (state->config->tuner_set_frequency(fe, freq) < 0) in stv090x_get_coldlock()
2197 if (state->config->tuner_set_bandwidth) { in stv090x_get_coldlock()
2198 if (state->config->tuner_set_bandwidth(fe, state->tuner_bw) < 0) in stv090x_get_coldlock()
2202 if (stv090x_i2c_gate_ctrl(state, 0) < 0) in stv090x_get_coldlock()
2207 if (stv090x_i2c_gate_ctrl(state, 1) < 0) in stv090x_get_coldlock()
2210 if (state->config->tuner_get_status) { in stv090x_get_coldlock()
2211 if (state->config->tuner_get_status(fe, &reg) < 0) in stv090x_get_coldlock()
2219 if (stv090x_i2c_gate_ctrl(state, 0) < 0) in stv090x_get_coldlock()
2222 STV090x_WRITE_DEMOD(state, DMDISTATE, 0x1c); in stv090x_get_coldlock()
2223 if (STV090x_WRITE_DEMOD(state, CFRINIT1, 0x00) < 0) in stv090x_get_coldlock()
2225 if (STV090x_WRITE_DEMOD(state, CFRINIT0, 0x00) < 0) in stv090x_get_coldlock()
2227 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x1f) < 0) in stv090x_get_coldlock()
2229 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x15) < 0) in stv090x_get_coldlock()
2231 lock = stv090x_get_dmdlock(state, (timeout_dmd / 3)); in stv090x_get_coldlock()
2240 stv090x_i2c_gate_ctrl(state, 0); in stv090x_get_coldlock()
2246 static int stv090x_get_loop_params(struct stv090x_state *state, s32 *freq_inc, s32 *timeout_sw, s32… in stv090x_get_loop_params() argument
2250 srate = state->srate; in stv090x_get_loop_params()
2251 car_max = state->search_range / 1000; in stv090x_get_loop_params()
2254 car_max /= (state->internal->mclk / 1000); in stv090x_get_loop_params()
2260 inc /= state->internal->mclk / 1000; in stv090x_get_loop_params()
2265 switch (state->search_mode) { in stv090x_get_loop_params()
2306 static int stv090x_chk_signal(struct stv090x_state *state) in stv090x_chk_signal() argument
2311 offst_car = STV090x_READ_DEMOD(state, CFR2) << 8; in stv090x_chk_signal()
2312 offst_car |= STV090x_READ_DEMOD(state, CFR1); in stv090x_chk_signal()
2315 agc2 = STV090x_READ_DEMOD(state, AGC2I1) << 8; in stv090x_chk_signal()
2316 agc2 |= STV090x_READ_DEMOD(state, AGC2I0); in stv090x_chk_signal()
2317 car_max = state->search_range / 1000; in stv090x_chk_signal()
2321 car_max /= state->internal->mclk / 1000; in stv090x_chk_signal()
2337 static int stv090x_search_car_loop(struct stv090x_state *state, s32 inc, s32 timeout, int zigzag, s… in stv090x_search_car_loop() argument
2343 car_max = state->search_range / 1000; in stv090x_search_car_loop()
2346 car_max /= (state->internal->mclk / 1000); in stv090x_search_car_loop()
2356 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x1c) < 0) in stv090x_search_car_loop()
2358 if (STV090x_WRITE_DEMOD(state, CFRINIT1, ((offst_freq / 256) & 0xff)) < 0) in stv090x_search_car_loop()
2360 if (STV090x_WRITE_DEMOD(state, CFRINIT0, offst_freq & 0xff) < 0) in stv090x_search_car_loop()
2362 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x18) < 0) in stv090x_search_car_loop()
2365 reg = STV090x_READ_DEMOD(state, PDELCTRL1); in stv090x_search_car_loop()
2367 if (STV090x_WRITE_DEMOD(state, PDELCTRL1, reg) < 0) in stv090x_search_car_loop()
2381 lock = stv090x_get_dmdlock(state, timeout); in stv090x_search_car_loop()
2382 no_signal = stv090x_chk_signal(state); in stv090x_search_car_loop()
2390 reg = STV090x_READ_DEMOD(state, PDELCTRL1); in stv090x_search_car_loop()
2392 if (STV090x_WRITE_DEMOD(state, PDELCTRL1, reg) < 0) in stv090x_search_car_loop()
2401 static int stv090x_sw_algo(struct stv090x_state *state) in stv090x_sw_algo() argument
2410 stv090x_get_loop_params(state, &inc, &timeout_step, &steps_max); in stv090x_sw_algo()
2412 switch (state->search_mode) { in stv090x_sw_algo()
2416 if (state->internal->dev_ver >= 0x20) { in stv090x_sw_algo()
2417 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x3B) < 0) in stv090x_sw_algo()
2421 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, 0x49) < 0) in stv090x_sw_algo()
2427 if (state->internal->dev_ver >= 0x20) { in stv090x_sw_algo()
2428 if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x79) < 0) in stv090x_sw_algo()
2432 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, 0x89) < 0) in stv090x_sw_algo()
2440 if (state->internal->dev_ver >= 0x20) { in stv090x_sw_algo()
2441 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x3b) < 0) in stv090x_sw_algo()
2443 if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x79) < 0) in stv090x_sw_algo()
2447 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, 0xc9) < 0) in stv090x_sw_algo()
2455 lock = stv090x_search_car_loop(state, inc, timeout_step, zigzag, steps_max); in stv090x_sw_algo()
2456 no_signal = stv090x_chk_signal(state); in stv090x_sw_algo()
2462 if (state->internal->dev_ver >= 0x20) { in stv090x_sw_algo()
2463 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x49) < 0) in stv090x_sw_algo()
2465 if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x9e) < 0) in stv090x_sw_algo()
2469 reg = STV090x_READ_DEMOD(state, DMDSTATE); in stv090x_sw_algo()
2473 reg = STV090x_READ_DEMOD(state, DMDFLYW); in stv090x_sw_algo()
2477 reg = STV090x_READ_DEMOD(state, DMDFLYW); in stv090x_sw_algo()
2484 if (state->internal->dev_ver >= 0x20) { in stv090x_sw_algo()
2485 if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x79) < 0) in stv090x_sw_algo()
2489 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, 0x89) < 0) in stv090x_sw_algo()
2503 static enum stv090x_delsys stv090x_get_std(struct stv090x_state *state) in stv090x_get_std() argument
2508 reg = STV090x_READ_DEMOD(state, DMDSTATE); in stv090x_get_std()
2512 reg = STV090x_READ_DEMOD(state, FECM); in stv090x_get_std()
2525 static s32 stv090x_get_car_freq(struct stv090x_state *state, u32 mclk) in stv090x_get_car_freq() argument
2529 derot = STV090x_READ_DEMOD(state, CFR2) << 16; in stv090x_get_car_freq()
2530 derot |= STV090x_READ_DEMOD(state, CFR1) << 8; in stv090x_get_car_freq()
2531 derot |= STV090x_READ_DEMOD(state, CFR0); in stv090x_get_car_freq()
2548 static int stv090x_get_viterbi(struct stv090x_state *state) in stv090x_get_viterbi() argument
2552 reg = STV090x_READ_DEMOD(state, VITCURPUN); in stv090x_get_viterbi()
2557 state->fec = STV090x_PR12; in stv090x_get_viterbi()
2561 state->fec = STV090x_PR23; in stv090x_get_viterbi()
2565 state->fec = STV090x_PR34; in stv090x_get_viterbi()
2569 state->fec = STV090x_PR56; in stv090x_get_viterbi()
2573 state->fec = STV090x_PR67; in stv090x_get_viterbi()
2577 state->fec = STV090x_PR78; in stv090x_get_viterbi()
2581 state->fec = STV090x_PRERR; in stv090x_get_viterbi()
2588 static enum stv090x_signal_state stv090x_get_sig_params(struct stv090x_state *state) in stv090x_get_sig_params() argument
2590 struct dvb_frontend *fe = &state->frontend; in stv090x_get_sig_params()
2598 if (state->algo == STV090x_BLIND_SEARCH) { in stv090x_get_sig_params()
2599 tmg = STV090x_READ_DEMOD(state, TMGREG2); in stv090x_get_sig_params()
2600 STV090x_WRITE_DEMOD(state, SFRSTEP, 0x5c); in stv090x_get_sig_params()
2602 tmg = STV090x_READ_DEMOD(state, TMGREG2); in stv090x_get_sig_params()
2607 state->delsys = stv090x_get_std(state); in stv090x_get_sig_params()
2609 if (stv090x_i2c_gate_ctrl(state, 1) < 0) in stv090x_get_sig_params()
2612 if (state->config->tuner_get_frequency) { in stv090x_get_sig_params()
2613 if (state->config->tuner_get_frequency(fe, &state->frequency) < 0) in stv090x_get_sig_params()
2617 if (stv090x_i2c_gate_ctrl(state, 0) < 0) in stv090x_get_sig_params()
2620 offst_freq = stv090x_get_car_freq(state, state->internal->mclk) / 1000; in stv090x_get_sig_params()
2621 state->frequency += offst_freq; in stv090x_get_sig_params()
2623 if (stv090x_get_viterbi(state) < 0) in stv090x_get_sig_params()
2626 reg = STV090x_READ_DEMOD(state, DMDMODCOD); in stv090x_get_sig_params()
2627 state->modcod = STV090x_GETFIELD_Px(reg, DEMOD_MODCOD_FIELD); in stv090x_get_sig_params()
2628 state->pilots = STV090x_GETFIELD_Px(reg, DEMOD_TYPE_FIELD) & 0x01; in stv090x_get_sig_params()
2629 state->frame_len = STV090x_GETFIELD_Px(reg, DEMOD_TYPE_FIELD) >> 1; in stv090x_get_sig_params()
2630 reg = STV090x_READ_DEMOD(state, TMGOBS); in stv090x_get_sig_params()
2631 state->rolloff = STV090x_GETFIELD_Px(reg, ROLLOFF_STATUS_FIELD); in stv090x_get_sig_params()
2632 reg = STV090x_READ_DEMOD(state, FECM); in stv090x_get_sig_params()
2633 state->inversion = STV090x_GETFIELD_Px(reg, IQINV_FIELD); in stv090x_get_sig_params()
2635 if ((state->algo == STV090x_BLIND_SEARCH) || (state->srate < 10000000)) { in stv090x_get_sig_params()
2637 if (stv090x_i2c_gate_ctrl(state, 1) < 0) in stv090x_get_sig_params()
2640 if (state->config->tuner_get_frequency) { in stv090x_get_sig_params()
2641 if (state->config->tuner_get_frequency(fe, &state->frequency) < 0) in stv090x_get_sig_params()
2645 if (stv090x_i2c_gate_ctrl(state, 0) < 0) in stv090x_get_sig_params()
2648 if (abs(offst_freq) <= ((state->search_range / 2000) + 500)) in stv090x_get_sig_params()
2650 else if (abs(offst_freq) <= (stv090x_car_width(state->srate, state->rolloff) / 2000)) in stv090x_get_sig_params()
2653 if (abs(offst_freq) <= ((state->search_range / 2000) + 500)) in stv090x_get_sig_params()
2660 stv090x_i2c_gate_ctrl(state, 0); in stv090x_get_sig_params()
2666 static u32 stv090x_get_tmgoffst(struct stv090x_state *state, u32 srate) in stv090x_get_tmgoffst() argument
2670 offst_tmg = STV090x_READ_DEMOD(state, TMGREG2) << 16; in stv090x_get_tmgoffst()
2671 offst_tmg |= STV090x_READ_DEMOD(state, TMGREG1) << 8; in stv090x_get_tmgoffst()
2672 offst_tmg |= STV090x_READ_DEMOD(state, TMGREG0); in stv090x_get_tmgoffst()
2684 static u8 stv090x_optimize_carloop(struct stv090x_state *state, enum stv090x_modcod modcod, s32 pil… in stv090x_optimize_carloop() argument
2690 if (state->internal->dev_ver == 0x20) { in stv090x_optimize_carloop()
2726 if (state->srate <= 3000000) in stv090x_optimize_carloop()
2728 else if (state->srate <= 7000000) in stv090x_optimize_carloop()
2730 else if (state->srate <= 15000000) in stv090x_optimize_carloop()
2732 else if (state->srate <= 25000000) in stv090x_optimize_carloop()
2737 if (state->srate <= 3000000) in stv090x_optimize_carloop()
2739 else if (state->srate <= 7000000) in stv090x_optimize_carloop()
2741 else if (state->srate <= 15000000) in stv090x_optimize_carloop()
2743 else if (state->srate <= 25000000) in stv090x_optimize_carloop()
2751 if (state->srate <= 3000000) in stv090x_optimize_carloop()
2753 else if (state->srate <= 7000000) in stv090x_optimize_carloop()
2755 else if (state->srate <= 15000000) in stv090x_optimize_carloop()
2757 else if (state->srate <= 25000000) in stv090x_optimize_carloop()
2762 if (state->srate <= 3000000) in stv090x_optimize_carloop()
2764 else if (state->srate <= 7000000) in stv090x_optimize_carloop()
2766 else if (state->srate <= 15000000) in stv090x_optimize_carloop()
2768 else if (state->srate <= 25000000) in stv090x_optimize_carloop()
2780 if (state->srate <= 3000000) in stv090x_optimize_carloop()
2782 else if (state->srate <= 7000000) in stv090x_optimize_carloop()
2784 else if (state->srate <= 15000000) in stv090x_optimize_carloop()
2786 else if (state->srate <= 25000000) in stv090x_optimize_carloop()
2795 static u8 stv090x_optimize_carloop_short(struct stv090x_state *state) in stv090x_optimize_carloop_short() argument
2801 switch (state->modulation) { in stv090x_optimize_carloop_short()
2817 if (state->internal->dev_ver >= 0x30) { in stv090x_optimize_carloop_short()
2825 if (state->srate <= 3000000) in stv090x_optimize_carloop_short()
2827 else if (state->srate <= 7000000) in stv090x_optimize_carloop_short()
2829 else if (state->srate <= 15000000) in stv090x_optimize_carloop_short()
2831 else if (state->srate <= 25000000) in stv090x_optimize_carloop_short()
2839 static int stv090x_optimize_track(struct stv090x_state *state) in stv090x_optimize_track() argument
2841 struct dvb_frontend *fe = &state->frontend; in stv090x_optimize_track()
2848 srate = stv090x_get_srate(state, state->internal->mclk); in stv090x_optimize_track()
2849 srate += stv090x_get_tmgoffst(state, srate); in stv090x_optimize_track()
2851 switch (state->delsys) { in stv090x_optimize_track()
2854 if (state->search_mode == STV090x_SEARCH_AUTO) { in stv090x_optimize_track()
2855 reg = STV090x_READ_DEMOD(state, DMDCFGMD); in stv090x_optimize_track()
2858 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) in stv090x_optimize_track()
2861 reg = STV090x_READ_DEMOD(state, DEMOD); in stv090x_optimize_track()
2862 STV090x_SETFIELD_Px(reg, ROLLOFF_CONTROL_FIELD, state->rolloff); in stv090x_optimize_track()
2864 if (STV090x_WRITE_DEMOD(state, DEMOD, reg) < 0) in stv090x_optimize_track()
2867 if (state->internal->dev_ver >= 0x30) { in stv090x_optimize_track()
2868 if (stv090x_get_viterbi(state) < 0) in stv090x_optimize_track()
2871 if (state->fec == STV090x_PR12) { in stv090x_optimize_track()
2872 if (STV090x_WRITE_DEMOD(state, GAUSSR0, 0x98) < 0) in stv090x_optimize_track()
2874 if (STV090x_WRITE_DEMOD(state, CCIR0, 0x18) < 0) in stv090x_optimize_track()
2877 if (STV090x_WRITE_DEMOD(state, GAUSSR0, 0x18) < 0) in stv090x_optimize_track()
2879 if (STV090x_WRITE_DEMOD(state, CCIR0, 0x18) < 0) in stv090x_optimize_track()
2884 if (STV090x_WRITE_DEMOD(state, ERRCTRL1, 0x75) < 0) in stv090x_optimize_track()
2889 reg = STV090x_READ_DEMOD(state, DMDCFGMD); in stv090x_optimize_track()
2892 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) in stv090x_optimize_track()
2894 if (state->internal->dev_ver >= 0x30) { in stv090x_optimize_track()
2895 if (STV090x_WRITE_DEMOD(state, ACLC, 0) < 0) in stv090x_optimize_track()
2897 if (STV090x_WRITE_DEMOD(state, BCLC, 0) < 0) in stv090x_optimize_track()
2900 if (state->frame_len == STV090x_LONG_FRAME) { in stv090x_optimize_track()
2901 reg = STV090x_READ_DEMOD(state, DMDMODCOD); in stv090x_optimize_track()
2904 aclc = stv090x_optimize_carloop(state, modcod, pilots); in stv090x_optimize_track()
2906 STV090x_WRITE_DEMOD(state, ACLC2S2Q, aclc); in stv090x_optimize_track()
2908 if (STV090x_WRITE_DEMOD(state, ACLC2S2Q, 0x2a) < 0) in stv090x_optimize_track()
2910 if (STV090x_WRITE_DEMOD(state, ACLC2S28, aclc) < 0) in stv090x_optimize_track()
2913 if ((state->demod_mode == STV090x_SINGLE) && (modcod > STV090x_8PSK_910)) { in stv090x_optimize_track()
2915 if (STV090x_WRITE_DEMOD(state, ACLC2S2Q, 0x2a) < 0) in stv090x_optimize_track()
2917 if (STV090x_WRITE_DEMOD(state, ACLC2S216A, aclc) < 0) in stv090x_optimize_track()
2920 if (STV090x_WRITE_DEMOD(state, ACLC2S2Q, 0x2a) < 0) in stv090x_optimize_track()
2922 if (STV090x_WRITE_DEMOD(state, ACLC2S232A, aclc) < 0) in stv090x_optimize_track()
2928 aclc = stv090x_optimize_carloop_short(state); in stv090x_optimize_track()
2929 if (state->modulation == STV090x_QPSK) { in stv090x_optimize_track()
2930 if (STV090x_WRITE_DEMOD(state, ACLC2S2Q, aclc) < 0) in stv090x_optimize_track()
2932 } else if (state->modulation == STV090x_8PSK) { in stv090x_optimize_track()
2933 if (STV090x_WRITE_DEMOD(state, ACLC2S2Q, 0x2a) < 0) in stv090x_optimize_track()
2935 if (STV090x_WRITE_DEMOD(state, ACLC2S28, aclc) < 0) in stv090x_optimize_track()
2937 } else if (state->modulation == STV090x_16APSK) { in stv090x_optimize_track()
2938 if (STV090x_WRITE_DEMOD(state, ACLC2S2Q, 0x2a) < 0) in stv090x_optimize_track()
2940 if (STV090x_WRITE_DEMOD(state, ACLC2S216A, aclc) < 0) in stv090x_optimize_track()
2942 } else if (state->modulation == STV090x_32APSK) { in stv090x_optimize_track()
2943 if (STV090x_WRITE_DEMOD(state, ACLC2S2Q, 0x2a) < 0) in stv090x_optimize_track()
2945 if (STV090x_WRITE_DEMOD(state, ACLC2S232A, aclc) < 0) in stv090x_optimize_track()
2950 STV090x_WRITE_DEMOD(state, ERRCTRL1, 0x67); /* PER */ in stv090x_optimize_track()
2955 reg = STV090x_READ_DEMOD(state, DMDCFGMD); in stv090x_optimize_track()
2958 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) in stv090x_optimize_track()
2963 f_1 = STV090x_READ_DEMOD(state, CFR2); in stv090x_optimize_track()
2964 f_0 = STV090x_READ_DEMOD(state, CFR1); in stv090x_optimize_track()
2965 reg = STV090x_READ_DEMOD(state, TMGOBS); in stv090x_optimize_track()
2967 if (state->algo == STV090x_BLIND_SEARCH) { in stv090x_optimize_track()
2968 STV090x_WRITE_DEMOD(state, SFRSTEP, 0x00); in stv090x_optimize_track()
2969 reg = STV090x_READ_DEMOD(state, DMDCFGMD); in stv090x_optimize_track()
2972 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) in stv090x_optimize_track()
2974 if (STV090x_WRITE_DEMOD(state, TMGCFG2, 0xc1) < 0) in stv090x_optimize_track()
2977 if (stv090x_set_srate(state, srate) < 0) in stv090x_optimize_track()
2981 if (stv090x_dvbs_track_crl(state) < 0) in stv090x_optimize_track()
2985 if (state->internal->dev_ver >= 0x20) { in stv090x_optimize_track()
2986 if ((state->search_mode == STV090x_SEARCH_DVBS1) || in stv090x_optimize_track()
2987 (state->search_mode == STV090x_SEARCH_DSS) || in stv090x_optimize_track()
2988 (state->search_mode == STV090x_SEARCH_AUTO)) { in stv090x_optimize_track()
2990 if (STV090x_WRITE_DEMOD(state, VAVSRVIT, 0x0a) < 0) in stv090x_optimize_track()
2992 if (STV090x_WRITE_DEMOD(state, VITSCALE, 0x00) < 0) in stv090x_optimize_track()
2997 if (STV090x_WRITE_DEMOD(state, AGC2REF, 0x38) < 0) in stv090x_optimize_track()
3001 if (STV090x_WRITE_DEMOD(state, SFRUP1, 0x80) < 0) in stv090x_optimize_track()
3004 if (STV090x_WRITE_DEMOD(state, SFRLOW1, 0x80) < 0) in stv090x_optimize_track()
3007 if ((state->internal->dev_ver >= 0x20) || (blind_tune == 1) || in stv090x_optimize_track()
3008 (state->srate < 10000000)) { in stv090x_optimize_track()
3010 if (STV090x_WRITE_DEMOD(state, CFRINIT1, f_1) < 0) in stv090x_optimize_track()
3012 if (STV090x_WRITE_DEMOD(state, CFRINIT0, f_0) < 0) in stv090x_optimize_track()
3014 state->tuner_bw = stv090x_car_width(srate, state->rolloff) + 10000000; in stv090x_optimize_track()
3016 if ((state->internal->dev_ver >= 0x20) || (blind_tune == 1)) { in stv090x_optimize_track()
3018 if (state->algo != STV090x_WARM_SEARCH) { in stv090x_optimize_track()
3020 if (stv090x_i2c_gate_ctrl(state, 1) < 0) in stv090x_optimize_track()
3023 if (state->config->tuner_set_bandwidth) { in stv090x_optimize_track()
3024 if (state->config->tuner_set_bandwidth(fe, state->tuner_bw) < 0) in stv090x_optimize_track()
3028 if (stv090x_i2c_gate_ctrl(state, 0) < 0) in stv090x_optimize_track()
3033 if ((state->algo == STV090x_BLIND_SEARCH) || (state->srate < 10000000)) in stv090x_optimize_track()
3038 stv090x_get_lock_tmg(state); in stv090x_optimize_track()
3040 if (!(stv090x_get_dmdlock(state, (state->DemodTimeout / 2)))) { in stv090x_optimize_track()
3041 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x1f) < 0) in stv090x_optimize_track()
3043 if (STV090x_WRITE_DEMOD(state, CFRINIT1, f_1) < 0) in stv090x_optimize_track()
3045 if (STV090x_WRITE_DEMOD(state, CFRINIT0, f_0) < 0) in stv090x_optimize_track()
3047 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x18) < 0) in stv090x_optimize_track()
3052 while ((!(stv090x_get_dmdlock(state, (state->DemodTimeout / 2)))) && (i <= 2)) { in stv090x_optimize_track()
3054 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x1f) < 0) in stv090x_optimize_track()
3056 if (STV090x_WRITE_DEMOD(state, CFRINIT1, f_1) < 0) in stv090x_optimize_track()
3058 if (STV090x_WRITE_DEMOD(state, CFRINIT0, f_0) < 0) in stv090x_optimize_track()
3060 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x18) < 0) in stv090x_optimize_track()
3068 if (state->internal->dev_ver >= 0x20) { in stv090x_optimize_track()
3069 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x49) < 0) in stv090x_optimize_track()
3073 if ((state->delsys == STV090x_DVBS1) || (state->delsys == STV090x_DSS)) in stv090x_optimize_track()
3074 stv090x_set_vit_thtracq(state); in stv090x_optimize_track()
3079 stv090x_i2c_gate_ctrl(state, 0); in stv090x_optimize_track()
3085 static int stv090x_get_feclock(struct stv090x_state *state, s32 timeout) in stv090x_get_feclock() argument
3091 reg = STV090x_READ_DEMOD(state, DMDSTATE); in stv090x_get_feclock()
3102 reg = STV090x_READ_DEMOD(state, PDELSTATUS1); in stv090x_get_feclock()
3107 reg = STV090x_READ_DEMOD(state, VSTATUSVIT); in stv090x_get_feclock()
3119 static int stv090x_get_lock(struct stv090x_state *state, s32 timeout_dmd, s32 timeout_fec) in stv090x_get_lock() argument
3125 lock = stv090x_get_dmdlock(state, timeout_dmd); in stv090x_get_lock()
3127 lock = stv090x_get_feclock(state, timeout_fec); in stv090x_get_lock()
3133 reg = STV090x_READ_DEMOD(state, TSSTATUS); in stv090x_get_lock()
3143 static int stv090x_set_s2rolloff(struct stv090x_state *state) in stv090x_set_s2rolloff() argument
3147 if (state->internal->dev_ver <= 0x20) { in stv090x_set_s2rolloff()
3149 reg = STV090x_READ_DEMOD(state, DEMOD); in stv090x_set_s2rolloff()
3151 if (STV090x_WRITE_DEMOD(state, DEMOD, reg) < 0) in stv090x_set_s2rolloff()
3155 reg = STV090x_READ_DEMOD(state, DEMOD); in stv090x_set_s2rolloff()
3157 if (STV090x_WRITE_DEMOD(state, DEMOD, reg) < 0) in stv090x_set_s2rolloff()
3167 static enum stv090x_signal_state stv090x_algo(struct stv090x_state *state) in stv090x_algo() argument
3169 struct dvb_frontend *fe = &state->frontend; in stv090x_algo()
3175 reg = STV090x_READ_DEMOD(state, TSCFGH); in stv090x_algo()
3177 if (STV090x_WRITE_DEMOD(state, TSCFGH, reg) < 0) in stv090x_algo()
3180 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x5c) < 0) /* Demod stop */ in stv090x_algo()
3183 if (state->internal->dev_ver >= 0x20) { in stv090x_algo()
3184 if (state->srate > 5000000) { in stv090x_algo()
3185 if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x9e) < 0) in stv090x_algo()
3188 if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x82) < 0) in stv090x_algo()
3193 stv090x_get_lock_tmg(state); in stv090x_algo()
3195 if (state->algo == STV090x_BLIND_SEARCH) { in stv090x_algo()
3196 state->tuner_bw = 2 * 36000000; /* wide bw for unknown srate */ in stv090x_algo()
3197 if (STV090x_WRITE_DEMOD(state, TMGCFG2, 0xc0) < 0) /* wider srate scan */ in stv090x_algo()
3199 if (STV090x_WRITE_DEMOD(state, CORRELMANT, 0x70) < 0) in stv090x_algo()
3201 if (stv090x_set_srate(state, 1000000) < 0) /* initial srate = 1Msps */ in stv090x_algo()
3205 if (STV090x_WRITE_DEMOD(state, DMDTOM, 0x20) < 0) in stv090x_algo()
3207 if (STV090x_WRITE_DEMOD(state, TMGCFG, 0xd2) < 0) in stv090x_algo()
3210 if (state->srate < 2000000) { in stv090x_algo()
3212 if (STV090x_WRITE_DEMOD(state, CORRELMANT, 0x63) < 0) in stv090x_algo()
3216 if (STV090x_WRITE_DEMOD(state, CORRELMANT, 0x70) < 0) in stv090x_algo()
3220 if (STV090x_WRITE_DEMOD(state, AGC2REF, 0x38) < 0) in stv090x_algo()
3223 if (state->internal->dev_ver >= 0x20) { in stv090x_algo()
3224 if (STV090x_WRITE_DEMOD(state, KREFTMG, 0x5a) < 0) in stv090x_algo()
3226 if (state->algo == STV090x_COLD_SEARCH) in stv090x_algo()
3227 state->tuner_bw = (15 * (stv090x_car_width(state->srate, state->rolloff) + 10000000)) / 10; in stv090x_algo()
3228 else if (state->algo == STV090x_WARM_SEARCH) in stv090x_algo()
3229 state->tuner_bw = stv090x_car_width(state->srate, state->rolloff) + 10000000; in stv090x_algo()
3235 if (STV090x_WRITE_DEMOD(state, TMGCFG2, 0xc1) < 0) /* narrow srate scan */ in stv090x_algo()
3238 if (stv090x_set_srate(state, state->srate) < 0) in stv090x_algo()
3241 if (stv090x_set_max_srate(state, state->internal->mclk, in stv090x_algo()
3242 state->srate) < 0) in stv090x_algo()
3244 if (stv090x_set_min_srate(state, state->internal->mclk, in stv090x_algo()
3245 state->srate) < 0) in stv090x_algo()
3248 if (state->srate >= 10000000) in stv090x_algo()
3255 if (stv090x_i2c_gate_ctrl(state, 1) < 0) in stv090x_algo()
3258 if (state->config->tuner_set_bbgain) { in stv090x_algo()
3259 reg = state->config->tuner_bbgain; in stv090x_algo()
3262 if (state->config->tuner_set_bbgain(fe, reg) < 0) in stv090x_algo()
3266 if (state->config->tuner_set_frequency) { in stv090x_algo()
3267 if (state->config->tuner_set_frequency(fe, state->frequency) < 0) in stv090x_algo()
3271 if (state->config->tuner_set_bandwidth) { in stv090x_algo()
3272 if (state->config->tuner_set_bandwidth(fe, state->tuner_bw) < 0) in stv090x_algo()
3276 if (stv090x_i2c_gate_ctrl(state, 0) < 0) in stv090x_algo()
3281 if (state->config->tuner_get_status) { in stv090x_algo()
3282 if (stv090x_i2c_gate_ctrl(state, 1) < 0) in stv090x_algo()
3284 if (state->config->tuner_get_status(fe, &reg) < 0) in stv090x_algo()
3286 if (stv090x_i2c_gate_ctrl(state, 0) < 0) in stv090x_algo()
3298 agc1_power = MAKEWORD16(STV090x_READ_DEMOD(state, AGCIQIN1), in stv090x_algo()
3299 STV090x_READ_DEMOD(state, AGCIQIN0)); in stv090x_algo()
3306 power_iq += (STV090x_READ_DEMOD(state, POWERI) + in stv090x_algo()
3307 STV090x_READ_DEMOD(state, POWERQ)) >> 1; in stv090x_algo()
3317 reg = STV090x_READ_DEMOD(state, DEMOD); in stv090x_algo()
3318 STV090x_SETFIELD_Px(reg, SPECINV_CONTROL_FIELD, state->inversion); in stv090x_algo()
3320 if (state->internal->dev_ver <= 0x20) { in stv090x_algo()
3327 if (STV090x_WRITE_DEMOD(state, DEMOD, reg) < 0) in stv090x_algo()
3330 if (stv090x_delivery_search(state) < 0) in stv090x_algo()
3333 if (state->algo != STV090x_BLIND_SEARCH) { in stv090x_algo()
3334 if (stv090x_start_search(state) < 0) in stv090x_algo()
3342 if (state->algo == STV090x_BLIND_SEARCH) in stv090x_algo()
3343 lock = stv090x_blind_search(state); in stv090x_algo()
3345 else if (state->algo == STV090x_COLD_SEARCH) in stv090x_algo()
3346 lock = stv090x_get_coldlock(state, state->DemodTimeout); in stv090x_algo()
3348 else if (state->algo == STV090x_WARM_SEARCH) in stv090x_algo()
3349 lock = stv090x_get_dmdlock(state, state->DemodTimeout); in stv090x_algo()
3351 if ((!lock) && (state->algo == STV090x_COLD_SEARCH)) { in stv090x_algo()
3353 if (stv090x_chk_tmg(state)) in stv090x_algo()
3354 lock = stv090x_sw_algo(state); in stv090x_algo()
3359 signal_state = stv090x_get_sig_params(state); in stv090x_algo()
3362 stv090x_optimize_track(state); in stv090x_algo()
3364 if (state->internal->dev_ver >= 0x20) { in stv090x_algo()
3368 reg = STV090x_READ_DEMOD(state, TSCFGH); in stv090x_algo()
3370 if (STV090x_WRITE_DEMOD(state, TSCFGH, reg) < 0) in stv090x_algo()
3376 if (STV090x_WRITE_DEMOD(state, TSCFGH, reg) < 0) in stv090x_algo()
3380 if (STV090x_WRITE_DEMOD(state, TSCFGH, reg) < 0) in stv090x_algo()
3384 lock = stv090x_get_lock(state, state->FecTimeout, in stv090x_algo()
3385 state->FecTimeout); in stv090x_algo()
3387 if (state->delsys == STV090x_DVBS2) { in stv090x_algo()
3388 stv090x_set_s2rolloff(state); in stv090x_algo()
3390 reg = STV090x_READ_DEMOD(state, PDELCTRL2); in stv090x_algo()
3392 if (STV090x_WRITE_DEMOD(state, PDELCTRL2, reg) < 0) in stv090x_algo()
3395 reg = STV090x_READ_DEMOD(state, PDELCTRL2); in stv090x_algo()
3397 if (STV090x_WRITE_DEMOD(state, PDELCTRL2, reg) < 0) in stv090x_algo()
3400 if (STV090x_WRITE_DEMOD(state, ERRCTRL1, 0x67) < 0) /* PER */ in stv090x_algo()
3403 if (STV090x_WRITE_DEMOD(state, ERRCTRL1, 0x75) < 0) in stv090x_algo()
3407 if (STV090x_WRITE_DEMOD(state, FBERCPT4, 0x00) < 0) in stv090x_algo()
3410 if (STV090x_WRITE_DEMOD(state, ERRCTRL2, 0xc1) < 0) in stv090x_algo()
3414 stv090x_chk_signal(state); in stv090x_algo()
3420 stv090x_i2c_gate_ctrl(state, 0); in stv090x_algo()
3426 static int stv090x_set_pls(struct stv090x_state *state, u32 pls_code) in stv090x_set_pls() argument
3429 if (STV090x_WRITE_DEMOD(state, PLROOT0, pls_code & 0xff) < 0) in stv090x_set_pls()
3431 if (STV090x_WRITE_DEMOD(state, PLROOT1, (pls_code >> 8) & 0xff) < 0) in stv090x_set_pls()
3433 if (STV090x_WRITE_DEMOD(state, PLROOT2, 0x04 | (pls_code >> 16)) < 0) in stv090x_set_pls()
3441 static int stv090x_set_mis(struct stv090x_state *state, int mis) in stv090x_set_mis() argument
3447 reg = STV090x_READ_DEMOD(state, PDELCTRL1); in stv090x_set_mis()
3449 if (STV090x_WRITE_DEMOD(state, PDELCTRL1, reg) < 0) in stv090x_set_mis()
3453 reg = STV090x_READ_DEMOD(state, PDELCTRL1); in stv090x_set_mis()
3455 if (STV090x_WRITE_DEMOD(state, PDELCTRL1, reg) < 0) in stv090x_set_mis()
3457 if (STV090x_WRITE_DEMOD(state, ISIENTRY, mis) < 0) in stv090x_set_mis()
3459 if (STV090x_WRITE_DEMOD(state, ISIBITENA, 0xff) < 0) in stv090x_set_mis()
3470 struct stv090x_state *state = fe->demodulator_priv; in stv090x_search() local
3478 state->delsys = STV090x_DSS; in stv090x_search()
3481 state->delsys = STV090x_DVBS1; in stv090x_search()
3484 state->delsys = STV090x_DVBS2; in stv090x_search()
3490 state->frequency = props->frequency; in stv090x_search()
3491 state->srate = props->symbol_rate; in stv090x_search()
3492 state->search_mode = STV090x_SEARCH_AUTO; in stv090x_search()
3493 state->algo = STV090x_COLD_SEARCH; in stv090x_search()
3494 state->fec = STV090x_PRERR; in stv090x_search()
3495 if (state->srate > 10000000) { in stv090x_search()
3497 state->search_range = 10000000; in stv090x_search()
3500 state->search_range = 5000000; in stv090x_search()
3503 stv090x_set_pls(state, props->scrambling_sequence_index); in stv090x_search()
3504 stv090x_set_mis(state, props->stream_id); in stv090x_search()
3506 if (stv090x_algo(state) == STV090x_RANGEOK) { in stv090x_search()
3519 struct stv090x_state *state = fe->demodulator_priv; in stv090x_read_status() local
3525 dstatus = STV090x_READ_DEMOD(state, DSTATUS); in stv090x_read_status()
3529 reg = STV090x_READ_DEMOD(state, DMDSTATE); in stv090x_read_status()
3542 reg = STV090x_READ_DEMOD(state, PDELSTATUS1); in stv090x_read_status()
3545 reg = STV090x_READ_DEMOD(state, TSSTATUS); in stv090x_read_status()
3555 reg = STV090x_READ_DEMOD(state, VSTATUSVIT); in stv090x_read_status()
3558 reg = STV090x_READ_DEMOD(state, TSSTATUS); in stv090x_read_status()
3571 struct stv090x_state *state = fe->demodulator_priv; in stv090x_read_per() local
3582 reg = STV090x_READ_DEMOD(state, ERRCNT22); in stv090x_read_per()
3585 reg = STV090x_READ_DEMOD(state, ERRCNT21); in stv090x_read_per()
3588 reg = STV090x_READ_DEMOD(state, ERRCNT20); in stv090x_read_per()
3593 count_4 = STV090x_READ_DEMOD(state, FBERCPT4); in stv090x_read_per()
3594 count_3 = STV090x_READ_DEMOD(state, FBERCPT3); in stv090x_read_per()
3595 count_2 = STV090x_READ_DEMOD(state, FBERCPT2); in stv090x_read_per()
3596 count_1 = STV090x_READ_DEMOD(state, FBERCPT1); in stv090x_read_per()
3597 count_0 = STV090x_READ_DEMOD(state, FBERCPT0); in stv090x_read_per()
3609 if (STV090x_WRITE_DEMOD(state, FBERCPT4, 0) < 0) in stv090x_read_per()
3611 if (STV090x_WRITE_DEMOD(state, ERRCTRL2, 0xc1) < 0) in stv090x_read_per()
3658 struct stv090x_state *state = fe->demodulator_priv; in stv090x_read_signal_strength() local
3663 reg = STV090x_READ_DEMOD(state, AGCIQIN1); in stv090x_read_signal_strength()
3665 reg = STV090x_READ_DEMOD(state, AGCIQIN0); in stv090x_read_signal_strength()
3682 struct stv090x_state *state = fe->demodulator_priv; in stv090x_read_cnr() local
3689 switch (state->delsys) { in stv090x_read_cnr()
3691 reg = STV090x_READ_DEMOD(state, DSTATUS); in stv090x_read_cnr()
3696 reg_1 = STV090x_READ_DEMOD(state, NNOSPLHT1); in stv090x_read_cnr()
3698 reg_0 = STV090x_READ_DEMOD(state, NNOSPLHT0); in stv090x_read_cnr()
3716 reg = STV090x_READ_DEMOD(state, DSTATUS); in stv090x_read_cnr()
3721 reg_1 = STV090x_READ_DEMOD(state, NOSDATAT1); in stv090x_read_cnr()
3723 reg_0 = STV090x_READ_DEMOD(state, NOSDATAT0); in stv090x_read_cnr()
3745 struct stv090x_state *state = fe->demodulator_priv; in stv090x_set_tone() local
3748 reg = STV090x_READ_DEMOD(state, DISTXCTL); in stv090x_set_tone()
3753 if (STV090x_WRITE_DEMOD(state, DISTXCTL, reg) < 0) in stv090x_set_tone()
3756 if (STV090x_WRITE_DEMOD(state, DISTXCTL, reg) < 0) in stv090x_set_tone()
3763 if (STV090x_WRITE_DEMOD(state, DISTXCTL, reg) < 0) in stv090x_set_tone()
3784 struct stv090x_state *state = fe->demodulator_priv; in stv090x_send_diseqc_msg() local
3788 reg = STV090x_READ_DEMOD(state, DISTXCTL); in stv090x_send_diseqc_msg()
3791 (state->config->diseqc_envelope_mode) ? 4 : 2); in stv090x_send_diseqc_msg()
3793 if (STV090x_WRITE_DEMOD(state, DISTXCTL, reg) < 0) in stv090x_send_diseqc_msg()
3796 if (STV090x_WRITE_DEMOD(state, DISTXCTL, reg) < 0) in stv090x_send_diseqc_msg()
3800 if (STV090x_WRITE_DEMOD(state, DISTXCTL, reg) < 0) in stv090x_send_diseqc_msg()
3806 reg = STV090x_READ_DEMOD(state, DISTXSTATUS); in stv090x_send_diseqc_msg()
3810 if (STV090x_WRITE_DEMOD(state, DISTXDATA, cmd->msg[i]) < 0) in stv090x_send_diseqc_msg()
3813 reg = STV090x_READ_DEMOD(state, DISTXCTL); in stv090x_send_diseqc_msg()
3815 if (STV090x_WRITE_DEMOD(state, DISTXCTL, reg) < 0) in stv090x_send_diseqc_msg()
3821 reg = STV090x_READ_DEMOD(state, DISTXSTATUS); in stv090x_send_diseqc_msg()
3836 struct stv090x_state *state = fe->demodulator_priv; in stv090x_send_diseqc_burst() local
3841 reg = STV090x_READ_DEMOD(state, DISTXCTL); in stv090x_send_diseqc_burst()
3844 mode = (state->config->diseqc_envelope_mode) ? 5 : 3; in stv090x_send_diseqc_burst()
3847 mode = (state->config->diseqc_envelope_mode) ? 4 : 2; in stv090x_send_diseqc_burst()
3853 if (STV090x_WRITE_DEMOD(state, DISTXCTL, reg) < 0) in stv090x_send_diseqc_burst()
3856 if (STV090x_WRITE_DEMOD(state, DISTXCTL, reg) < 0) in stv090x_send_diseqc_burst()
3860 if (STV090x_WRITE_DEMOD(state, DISTXCTL, reg) < 0) in stv090x_send_diseqc_burst()
3864 reg = STV090x_READ_DEMOD(state, DISTXSTATUS); in stv090x_send_diseqc_burst()
3868 if (STV090x_WRITE_DEMOD(state, DISTXDATA, value) < 0) in stv090x_send_diseqc_burst()
3871 reg = STV090x_READ_DEMOD(state, DISTXCTL); in stv090x_send_diseqc_burst()
3873 if (STV090x_WRITE_DEMOD(state, DISTXCTL, reg) < 0) in stv090x_send_diseqc_burst()
3879 reg = STV090x_READ_DEMOD(state, DISTXSTATUS); in stv090x_send_diseqc_burst()
3893 struct stv090x_state *state = fe->demodulator_priv; in stv090x_recv_slave_reply() local
3899 reg = STV090x_READ_DEMOD(state, DISRX_ST0); in stv090x_recv_slave_reply()
3906 reply->msg[i] = STV090x_READ_DEMOD(state, DISRXDATA); in stv090x_recv_slave_reply()
3914 struct stv090x_state *state = fe->demodulator_priv; in stv090x_sleep() local
3918 if (stv090x_i2c_gate_ctrl(state, 1) < 0) in stv090x_sleep()
3921 if (state->config->tuner_sleep) { in stv090x_sleep()
3922 if (state->config->tuner_sleep(fe) < 0) in stv090x_sleep()
3926 if (stv090x_i2c_gate_ctrl(state, 0) < 0) in stv090x_sleep()
3930 state->device == STV0900 ? "STV0900" : "STV0903", in stv090x_sleep()
3931 state->demod); in stv090x_sleep()
3933 mutex_lock(&state->internal->demod_lock); in stv090x_sleep()
3935 switch (state->demod) { in stv090x_sleep()
3938 reg = stv090x_read_reg(state, STV090x_TSTTNR1); in stv090x_sleep()
3940 if (stv090x_write_reg(state, STV090x_TSTTNR1, reg) < 0) in stv090x_sleep()
3943 reg = stv090x_read_reg(state, STV090x_TSTTNR2); in stv090x_sleep()
3945 if (stv090x_write_reg(state, STV090x_TSTTNR2, reg) < 0) in stv090x_sleep()
3950 reg = stv090x_read_reg(state, STV090x_TSTTNR3); in stv090x_sleep()
3955 reg = stv090x_read_reg(state, STV090x_STOPCLK1); in stv090x_sleep()
3964 if (stv090x_write_reg(state, STV090x_STOPCLK1, reg) < 0) in stv090x_sleep()
3966 reg = stv090x_read_reg(state, STV090x_STOPCLK2); in stv090x_sleep()
3975 if (stv090x_write_reg(state, STV090x_STOPCLK2, reg) < 0) in stv090x_sleep()
3981 reg = stv090x_read_reg(state, STV090x_TSTTNR3); in stv090x_sleep()
3983 if (stv090x_write_reg(state, STV090x_TSTTNR3, reg) < 0) in stv090x_sleep()
3986 reg = stv090x_read_reg(state, STV090x_TSTTNR4); in stv090x_sleep()
3988 if (stv090x_write_reg(state, STV090x_TSTTNR4, reg) < 0) in stv090x_sleep()
3993 reg = stv090x_read_reg(state, STV090x_TSTTNR1); in stv090x_sleep()
3998 reg = stv090x_read_reg(state, STV090x_STOPCLK1); in stv090x_sleep()
4007 if (stv090x_write_reg(state, STV090x_STOPCLK1, reg) < 0) in stv090x_sleep()
4009 reg = stv090x_read_reg(state, STV090x_STOPCLK2); in stv090x_sleep()
4018 if (stv090x_write_reg(state, STV090x_STOPCLK2, reg) < 0) in stv090x_sleep()
4029 reg = stv090x_read_reg(state, STV090x_SYNTCTRL); in stv090x_sleep()
4031 if (stv090x_write_reg(state, STV090x_SYNTCTRL, reg) < 0) in stv090x_sleep()
4035 mutex_unlock(&state->internal->demod_lock); in stv090x_sleep()
4039 stv090x_i2c_gate_ctrl(state, 0); in stv090x_sleep()
4042 mutex_unlock(&state->internal->demod_lock); in stv090x_sleep()
4050 struct stv090x_state *state = fe->demodulator_priv; in stv090x_wakeup() local
4054 state->device == STV0900 ? "STV0900" : "STV0903", in stv090x_wakeup()
4055 state->demod); in stv090x_wakeup()
4057 mutex_lock(&state->internal->demod_lock); in stv090x_wakeup()
4060 reg = stv090x_read_reg(state, STV090x_SYNTCTRL); in stv090x_wakeup()
4062 if (stv090x_write_reg(state, STV090x_SYNTCTRL, reg) < 0) in stv090x_wakeup()
4065 switch (state->demod) { in stv090x_wakeup()
4068 reg = stv090x_read_reg(state, STV090x_TSTTNR1); in stv090x_wakeup()
4070 if (stv090x_write_reg(state, STV090x_TSTTNR1, reg) < 0) in stv090x_wakeup()
4073 reg = stv090x_read_reg(state, STV090x_TSTTNR2); in stv090x_wakeup()
4075 if (stv090x_write_reg(state, STV090x_TSTTNR2, reg) < 0) in stv090x_wakeup()
4079 reg = stv090x_read_reg(state, STV090x_STOPCLK1); in stv090x_wakeup()
4086 if (stv090x_write_reg(state, STV090x_STOPCLK1, reg) < 0) in stv090x_wakeup()
4088 reg = stv090x_read_reg(state, STV090x_STOPCLK2); in stv090x_wakeup()
4095 if (stv090x_write_reg(state, STV090x_STOPCLK2, reg) < 0) in stv090x_wakeup()
4101 reg = stv090x_read_reg(state, STV090x_TSTTNR3); in stv090x_wakeup()
4103 if (stv090x_write_reg(state, STV090x_TSTTNR3, reg) < 0) in stv090x_wakeup()
4106 reg = stv090x_read_reg(state, STV090x_TSTTNR4); in stv090x_wakeup()
4108 if (stv090x_write_reg(state, STV090x_TSTTNR4, reg) < 0) in stv090x_wakeup()
4112 reg = stv090x_read_reg(state, STV090x_STOPCLK1); in stv090x_wakeup()
4119 if (stv090x_write_reg(state, STV090x_STOPCLK1, reg) < 0) in stv090x_wakeup()
4121 reg = stv090x_read_reg(state, STV090x_STOPCLK2); in stv090x_wakeup()
4128 if (stv090x_write_reg(state, STV090x_STOPCLK2, reg) < 0) in stv090x_wakeup()
4137 mutex_unlock(&state->internal->demod_lock); in stv090x_wakeup()
4140 mutex_unlock(&state->internal->demod_lock); in stv090x_wakeup()
4147 struct stv090x_state *state = fe->demodulator_priv; in stv090x_release() local
4149 state->internal->num_used--; in stv090x_release()
4150 if (state->internal->num_used <= 0) { in stv090x_release()
4154 remove_dev(state->internal); in stv090x_release()
4155 kfree(state->internal); in stv090x_release()
4158 kfree(state); in stv090x_release()
4161 static int stv090x_ldpc_mode(struct stv090x_state *state, enum stv090x_mode ldpc_mode) in stv090x_ldpc_mode() argument
4165 reg = stv090x_read_reg(state, STV090x_GENCFG); in stv090x_ldpc_mode()
4170 if ((state->demod_mode != STV090x_DUAL) || (STV090x_GETFIELD(reg, DDEMOD_FIELD) != 1)) { in stv090x_ldpc_mode()
4172 if (stv090x_write_reg(state, STV090x_GENCFG, 0x1d) < 0) in stv090x_ldpc_mode()
4175 state->demod_mode = STV090x_DUAL; in stv090x_ldpc_mode()
4177 reg = stv090x_read_reg(state, STV090x_TSTRES0); in stv090x_ldpc_mode()
4179 if (stv090x_write_reg(state, STV090x_TSTRES0, reg) < 0) in stv090x_ldpc_mode()
4182 if (stv090x_write_reg(state, STV090x_TSTRES0, reg) < 0) in stv090x_ldpc_mode()
4185 if (STV090x_WRITE_DEMOD(state, MODCODLST0, 0xff) < 0) in stv090x_ldpc_mode()
4187 if (STV090x_WRITE_DEMOD(state, MODCODLST1, 0xff) < 0) in stv090x_ldpc_mode()
4189 if (STV090x_WRITE_DEMOD(state, MODCODLST2, 0xff) < 0) in stv090x_ldpc_mode()
4191 if (STV090x_WRITE_DEMOD(state, MODCODLST3, 0xff) < 0) in stv090x_ldpc_mode()
4193 if (STV090x_WRITE_DEMOD(state, MODCODLST4, 0xff) < 0) in stv090x_ldpc_mode()
4195 if (STV090x_WRITE_DEMOD(state, MODCODLST5, 0xff) < 0) in stv090x_ldpc_mode()
4197 if (STV090x_WRITE_DEMOD(state, MODCODLST6, 0xff) < 0) in stv090x_ldpc_mode()
4200 if (STV090x_WRITE_DEMOD(state, MODCODLST7, 0xcc) < 0) in stv090x_ldpc_mode()
4202 if (STV090x_WRITE_DEMOD(state, MODCODLST8, 0xcc) < 0) in stv090x_ldpc_mode()
4204 if (STV090x_WRITE_DEMOD(state, MODCODLST9, 0xcc) < 0) in stv090x_ldpc_mode()
4206 if (STV090x_WRITE_DEMOD(state, MODCODLSTA, 0xcc) < 0) in stv090x_ldpc_mode()
4208 if (STV090x_WRITE_DEMOD(state, MODCODLSTB, 0xcc) < 0) in stv090x_ldpc_mode()
4210 if (STV090x_WRITE_DEMOD(state, MODCODLSTC, 0xcc) < 0) in stv090x_ldpc_mode()
4212 if (STV090x_WRITE_DEMOD(state, MODCODLSTD, 0xcc) < 0) in stv090x_ldpc_mode()
4215 if (STV090x_WRITE_DEMOD(state, MODCODLSTE, 0xff) < 0) in stv090x_ldpc_mode()
4217 if (STV090x_WRITE_DEMOD(state, MODCODLSTF, 0xcf) < 0) in stv090x_ldpc_mode()
4223 if (stv090x_stop_modcod(state) < 0) in stv090x_ldpc_mode()
4225 if (stv090x_activate_modcod_single(state) < 0) in stv090x_ldpc_mode()
4228 if (state->demod == STV090x_DEMODULATOR_1) { in stv090x_ldpc_mode()
4229 if (stv090x_write_reg(state, STV090x_GENCFG, 0x06) < 0) /* path 2 */ in stv090x_ldpc_mode()
4232 if (stv090x_write_reg(state, STV090x_GENCFG, 0x04) < 0) /* path 1 */ in stv090x_ldpc_mode()
4236 reg = stv090x_read_reg(state, STV090x_TSTRES0); in stv090x_ldpc_mode()
4238 if (stv090x_write_reg(state, STV090x_TSTRES0, reg) < 0) in stv090x_ldpc_mode()
4241 if (stv090x_write_reg(state, STV090x_TSTRES0, reg) < 0) in stv090x_ldpc_mode()
4244 reg = STV090x_READ_DEMOD(state, PDELCTRL1); in stv090x_ldpc_mode()
4246 if (STV090x_WRITE_DEMOD(state, PDELCTRL1, reg) < 0) in stv090x_ldpc_mode()
4249 if (STV090x_WRITE_DEMOD(state, PDELCTRL1, reg) < 0) in stv090x_ldpc_mode()
4261 static u32 stv090x_get_mclk(struct stv090x_state *state) in stv090x_get_mclk() argument
4263 const struct stv090x_config *config = state->config; in stv090x_get_mclk()
4267 div = stv090x_read_reg(state, STV090x_NCOARSE); in stv090x_get_mclk()
4268 reg = stv090x_read_reg(state, STV090x_SYNTCTRL); in stv090x_get_mclk()
4274 static int stv090x_set_mclk(struct stv090x_state *state, u32 mclk, u32 clk) in stv090x_set_mclk() argument
4276 const struct stv090x_config *config = state->config; in stv090x_set_mclk()
4279 reg = stv090x_read_reg(state, STV090x_SYNTCTRL); in stv090x_set_mclk()
4284 reg = stv090x_read_reg(state, STV090x_NCOARSE); in stv090x_set_mclk()
4286 if (stv090x_write_reg(state, STV090x_NCOARSE, reg) < 0) in stv090x_set_mclk()
4289 state->internal->mclk = stv090x_get_mclk(state); in stv090x_set_mclk()
4292 div = state->internal->mclk / 704000; in stv090x_set_mclk()
4293 if (STV090x_WRITE_DEMOD(state, F22TX, div) < 0) in stv090x_set_mclk()
4295 if (STV090x_WRITE_DEMOD(state, F22RX, div) < 0) in stv090x_set_mclk()
4304 static int stv0900_set_tspath(struct stv090x_state *state) in stv0900_set_tspath() argument
4308 if (state->internal->dev_ver >= 0x20) { in stv0900_set_tspath()
4309 switch (state->config->ts1_mode) { in stv0900_set_tspath()
4312 switch (state->config->ts2_mode) { in stv0900_set_tspath()
4316 stv090x_write_reg(state, STV090x_TSGENERAL, 0x00); in stv0900_set_tspath()
4321 if (stv090x_write_reg(state, STV090x_TSGENERAL, 0x06) < 0) /* Mux'd stream mode */ in stv0900_set_tspath()
4323 reg = stv090x_read_reg(state, STV090x_P1_TSCFGM); in stv0900_set_tspath()
4325 if (stv090x_write_reg(state, STV090x_P1_TSCFGM, reg) < 0) in stv0900_set_tspath()
4327 reg = stv090x_read_reg(state, STV090x_P2_TSCFGM); in stv0900_set_tspath()
4329 if (stv090x_write_reg(state, STV090x_P2_TSCFGM, reg) < 0) in stv0900_set_tspath()
4331 if (stv090x_write_reg(state, STV090x_P1_TSSPEED, 0x14) < 0) in stv0900_set_tspath()
4333 if (stv090x_write_reg(state, STV090x_P2_TSSPEED, 0x28) < 0) in stv0900_set_tspath()
4342 switch (state->config->ts2_mode) { in stv0900_set_tspath()
4346 if (stv090x_write_reg(state, STV090x_TSGENERAL, 0x0c) < 0) in stv0900_set_tspath()
4352 if (stv090x_write_reg(state, STV090x_TSGENERAL, 0x0a) < 0) in stv0900_set_tspath()
4359 switch (state->config->ts1_mode) { in stv0900_set_tspath()
4362 switch (state->config->ts2_mode) { in stv0900_set_tspath()
4366 stv090x_write_reg(state, STV090x_TSGENERAL1X, 0x10); in stv0900_set_tspath()
4371 stv090x_write_reg(state, STV090x_TSGENERAL1X, 0x16); in stv0900_set_tspath()
4372 reg = stv090x_read_reg(state, STV090x_P1_TSCFGM); in stv0900_set_tspath()
4374 if (stv090x_write_reg(state, STV090x_P1_TSCFGM, reg) < 0) in stv0900_set_tspath()
4376 reg = stv090x_read_reg(state, STV090x_P1_TSCFGM); in stv0900_set_tspath()
4378 if (stv090x_write_reg(state, STV090x_P1_TSCFGM, reg) < 0) in stv0900_set_tspath()
4380 if (stv090x_write_reg(state, STV090x_P1_TSSPEED, 0x14) < 0) in stv0900_set_tspath()
4382 if (stv090x_write_reg(state, STV090x_P2_TSSPEED, 0x28) < 0) in stv0900_set_tspath()
4391 switch (state->config->ts2_mode) { in stv0900_set_tspath()
4395 stv090x_write_reg(state, STV090x_TSGENERAL1X, 0x14); in stv0900_set_tspath()
4400 stv090x_write_reg(state, STV090x_TSGENERAL1X, 0x12); in stv0900_set_tspath()
4407 switch (state->config->ts1_mode) { in stv0900_set_tspath()
4409 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH); in stv0900_set_tspath()
4410 STV090x_SETFIELD_Px(reg, TSFIFO_TEIUPDATE_FIELD, state->config->ts1_tei); in stv0900_set_tspath()
4413 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0) in stv0900_set_tspath()
4418 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH); in stv0900_set_tspath()
4419 STV090x_SETFIELD_Px(reg, TSFIFO_TEIUPDATE_FIELD, state->config->ts1_tei); in stv0900_set_tspath()
4422 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0) in stv0900_set_tspath()
4427 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH); in stv0900_set_tspath()
4428 STV090x_SETFIELD_Px(reg, TSFIFO_TEIUPDATE_FIELD, state->config->ts1_tei); in stv0900_set_tspath()
4431 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0) in stv0900_set_tspath()
4436 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH); in stv0900_set_tspath()
4437 STV090x_SETFIELD_Px(reg, TSFIFO_TEIUPDATE_FIELD, state->config->ts1_tei); in stv0900_set_tspath()
4440 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0) in stv0900_set_tspath()
4448 switch (state->config->ts2_mode) { in stv0900_set_tspath()
4450 reg = stv090x_read_reg(state, STV090x_P2_TSCFGH); in stv0900_set_tspath()
4451 STV090x_SETFIELD_Px(reg, TSFIFO_TEIUPDATE_FIELD, state->config->ts2_tei); in stv0900_set_tspath()
4454 if (stv090x_write_reg(state, STV090x_P2_TSCFGH, reg) < 0) in stv0900_set_tspath()
4459 reg = stv090x_read_reg(state, STV090x_P2_TSCFGH); in stv0900_set_tspath()
4460 STV090x_SETFIELD_Px(reg, TSFIFO_TEIUPDATE_FIELD, state->config->ts2_tei); in stv0900_set_tspath()
4463 if (stv090x_write_reg(state, STV090x_P2_TSCFGH, reg) < 0) in stv0900_set_tspath()
4468 reg = stv090x_read_reg(state, STV090x_P2_TSCFGH); in stv0900_set_tspath()
4469 STV090x_SETFIELD_Px(reg, TSFIFO_TEIUPDATE_FIELD, state->config->ts2_tei); in stv0900_set_tspath()
4472 if (stv090x_write_reg(state, STV090x_P2_TSCFGH, reg) < 0) in stv0900_set_tspath()
4477 reg = stv090x_read_reg(state, STV090x_P2_TSCFGH); in stv0900_set_tspath()
4478 STV090x_SETFIELD_Px(reg, TSFIFO_TEIUPDATE_FIELD, state->config->ts2_tei); in stv0900_set_tspath()
4481 if (stv090x_write_reg(state, STV090x_P2_TSCFGH, reg) < 0) in stv0900_set_tspath()
4489 if (state->config->ts1_clk > 0) { in stv0900_set_tspath()
4492 switch (state->config->ts1_mode) { in stv0900_set_tspath()
4496 speed = state->internal->mclk / in stv0900_set_tspath()
4497 (state->config->ts1_clk / 4); in stv0900_set_tspath()
4505 speed = state->internal->mclk / in stv0900_set_tspath()
4506 (state->config->ts1_clk / 32); in stv0900_set_tspath()
4513 reg = stv090x_read_reg(state, STV090x_P1_TSCFGM); in stv0900_set_tspath()
4515 if (stv090x_write_reg(state, STV090x_P1_TSCFGM, reg) < 0) in stv0900_set_tspath()
4517 if (stv090x_write_reg(state, STV090x_P1_TSSPEED, speed) < 0) in stv0900_set_tspath()
4521 if (state->config->ts2_clk > 0) { in stv0900_set_tspath()
4524 switch (state->config->ts2_mode) { in stv0900_set_tspath()
4528 speed = state->internal->mclk / in stv0900_set_tspath()
4529 (state->config->ts2_clk / 4); in stv0900_set_tspath()
4537 speed = state->internal->mclk / in stv0900_set_tspath()
4538 (state->config->ts2_clk / 32); in stv0900_set_tspath()
4545 reg = stv090x_read_reg(state, STV090x_P2_TSCFGM); in stv0900_set_tspath()
4547 if (stv090x_write_reg(state, STV090x_P2_TSCFGM, reg) < 0) in stv0900_set_tspath()
4549 if (stv090x_write_reg(state, STV090x_P2_TSSPEED, speed) < 0) in stv0900_set_tspath()
4553 reg = stv090x_read_reg(state, STV090x_P2_TSCFGH); in stv0900_set_tspath()
4555 if (stv090x_write_reg(state, STV090x_P2_TSCFGH, reg) < 0) in stv0900_set_tspath()
4558 if (stv090x_write_reg(state, STV090x_P2_TSCFGH, reg) < 0) in stv0900_set_tspath()
4561 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH); in stv0900_set_tspath()
4563 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0) in stv0900_set_tspath()
4566 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0) in stv0900_set_tspath()
4575 static int stv0903_set_tspath(struct stv090x_state *state) in stv0903_set_tspath() argument
4579 if (state->internal->dev_ver >= 0x20) { in stv0903_set_tspath()
4580 switch (state->config->ts1_mode) { in stv0903_set_tspath()
4583 stv090x_write_reg(state, STV090x_TSGENERAL, 0x00); in stv0903_set_tspath()
4589 stv090x_write_reg(state, STV090x_TSGENERAL, 0x0c); in stv0903_set_tspath()
4593 switch (state->config->ts1_mode) { in stv0903_set_tspath()
4596 stv090x_write_reg(state, STV090x_TSGENERAL1X, 0x10); in stv0903_set_tspath()
4602 stv090x_write_reg(state, STV090x_TSGENERAL1X, 0x14); in stv0903_set_tspath()
4607 switch (state->config->ts1_mode) { in stv0903_set_tspath()
4609 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH); in stv0903_set_tspath()
4612 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0) in stv0903_set_tspath()
4617 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH); in stv0903_set_tspath()
4620 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0) in stv0903_set_tspath()
4625 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH); in stv0903_set_tspath()
4628 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0) in stv0903_set_tspath()
4633 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH); in stv0903_set_tspath()
4636 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0) in stv0903_set_tspath()
4644 if (state->config->ts1_clk > 0) { in stv0903_set_tspath()
4647 switch (state->config->ts1_mode) { in stv0903_set_tspath()
4651 speed = state->internal->mclk / in stv0903_set_tspath()
4652 (state->config->ts1_clk / 4); in stv0903_set_tspath()
4660 speed = state->internal->mclk / in stv0903_set_tspath()
4661 (state->config->ts1_clk / 32); in stv0903_set_tspath()
4668 reg = stv090x_read_reg(state, STV090x_P1_TSCFGM); in stv0903_set_tspath()
4670 if (stv090x_write_reg(state, STV090x_P1_TSCFGM, reg) < 0) in stv0903_set_tspath()
4672 if (stv090x_write_reg(state, STV090x_P1_TSSPEED, speed) < 0) in stv0903_set_tspath()
4676 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH); in stv0903_set_tspath()
4678 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0) in stv0903_set_tspath()
4681 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0) in stv0903_set_tspath()
4692 struct stv090x_state *state = fe->demodulator_priv; in stv090x_init() local
4693 const struct stv090x_config *config = state->config; in stv090x_init()
4696 if (state->internal->mclk == 0) { in stv090x_init()
4700 if (stv090x_i2c_gate_ctrl(state, 1) < 0) in stv090x_init()
4708 if (stv090x_i2c_gate_ctrl(state, 0) < 0) in stv090x_init()
4711 stv090x_set_mclk(state, 135000000, config->xtal); /* 135 Mhz */ in stv090x_init()
4713 if (stv090x_write_reg(state, STV090x_SYNTCTRL, in stv090x_init()
4716 stv090x_get_mclk(state); in stv090x_init()
4724 if (stv090x_ldpc_mode(state, state->demod_mode) < 0) in stv090x_init()
4727 reg = STV090x_READ_DEMOD(state, TNRCFG2); in stv090x_init()
4728 STV090x_SETFIELD_Px(reg, TUN_IQSWAP_FIELD, state->inversion); in stv090x_init()
4729 if (STV090x_WRITE_DEMOD(state, TNRCFG2, reg) < 0) in stv090x_init()
4731 reg = STV090x_READ_DEMOD(state, DEMOD); in stv090x_init()
4732 STV090x_SETFIELD_Px(reg, ROLLOFF_CONTROL_FIELD, state->rolloff); in stv090x_init()
4733 if (STV090x_WRITE_DEMOD(state, DEMOD, reg) < 0) in stv090x_init()
4736 if (stv090x_i2c_gate_ctrl(state, 1) < 0) in stv090x_init()
4749 if (stv090x_i2c_gate_ctrl(state, 0) < 0) in stv090x_init()
4752 if (state->device == STV0900) { in stv090x_init()
4753 if (stv0900_set_tspath(state) < 0) in stv090x_init()
4756 if (stv0903_set_tspath(state) < 0) in stv090x_init()
4763 stv090x_i2c_gate_ctrl(state, 0); in stv090x_init()
4771 struct stv090x_state *state = fe->demodulator_priv; in stv090x_setup() local
4772 const struct stv090x_config *config = state->config; in stv090x_setup()
4780 if (state->device == STV0900) { in stv090x_setup()
4786 } else if (state->device == STV0903) { in stv090x_setup()
4797 if (stv090x_write_reg(state, STV090x_P1_DMDISTATE, 0x5c) < 0) in stv090x_setup()
4799 if (state->device == STV0900) in stv090x_setup()
4800 if (stv090x_write_reg(state, STV090x_P2_DMDISTATE, 0x5c) < 0) in stv090x_setup()
4806 if (stv090x_write_reg(state, STV090x_P1_TNRCFG, 0x6c) < 0) in stv090x_setup()
4808 if (state->device == STV0900) in stv090x_setup()
4809 if (stv090x_write_reg(state, STV090x_P2_TNRCFG, 0x6c) < 0) in stv090x_setup()
4814 if (stv090x_write_reg(state, STV090x_P1_I2CRPT, reg) < 0) in stv090x_setup()
4816 if (state->device == STV0900) in stv090x_setup()
4817 if (stv090x_write_reg(state, STV090x_P2_I2CRPT, reg) < 0) in stv090x_setup()
4820 if (stv090x_write_reg(state, STV090x_NCOARSE, 0x13) < 0) /* set PLL divider */ in stv090x_setup()
4823 if (stv090x_write_reg(state, STV090x_I2CCFG, 0x08) < 0) /* 1/41 oversampling */ in stv090x_setup()
4825 if (stv090x_write_reg(state, STV090x_SYNTCTRL, 0x20 | config->clk_mode) < 0) /* enable PLL */ in stv090x_setup()
4832 if (stv090x_write_reg(state, stv090x_initval[i].addr, stv090x_initval[i].data) < 0) in stv090x_setup()
4836 state->internal->dev_ver = stv090x_read_reg(state, STV090x_MID); in stv090x_setup()
4837 if (state->internal->dev_ver >= 0x20) { in stv090x_setup()
4838 if (stv090x_write_reg(state, STV090x_TSGENERAL, 0x0c) < 0) in stv090x_setup()
4844 if (stv090x_write_reg(state, stv090x_cut20_val[i].addr, stv090x_cut20_val[i].data) < 0) in stv090x_setup()
4848 } else if (state->internal->dev_ver < 0x20) { in stv090x_setup()
4850 state->internal->dev_ver); in stv090x_setup()
4853 } else if (state->internal->dev_ver > 0x30) { in stv090x_setup()
4856 state->internal->dev_ver); in stv090x_setup()
4860 reg = stv090x_read_reg(state, STV090x_TSTTNR1); in stv090x_setup()
4863 if (stv090x_write_reg(state, STV090x_TSTTNR1, reg) < 0) in stv090x_setup()
4867 reg = stv090x_read_reg(state, STV090x_TSTTNR3); in stv090x_setup()
4870 if (stv090x_write_reg(state, STV090x_TSTTNR3, reg) < 0) in stv090x_setup()
4873 if (stv090x_write_reg(state, STV090x_TSTRES0, 0x80) < 0) in stv090x_setup()
4875 if (stv090x_write_reg(state, STV090x_TSTRES0, 0x00) < 0) in stv090x_setup()
4887 struct stv090x_state *state = fe->demodulator_priv; in stv090x_set_gpio() local
4894 return stv090x_write_reg(state, STV090x_GPIOxCFG(gpio), reg); in stv090x_set_gpio()
4897 static int stv090x_setup_compound(struct stv090x_state *state) in stv090x_setup_compound() argument
4901 temp_int = find_dev(state->i2c, in stv090x_setup_compound()
4902 state->config->address); in stv090x_setup_compound()
4904 if (temp_int && state->demod_mode == STV090x_DUAL) { in stv090x_setup_compound()
4905 state->internal = temp_int->internal; in stv090x_setup_compound()
4906 state->internal->num_used++; in stv090x_setup_compound()
4909 state->internal = kmalloc(sizeof(*state->internal), GFP_KERNEL); in stv090x_setup_compound()
4910 if (!state->internal) in stv090x_setup_compound()
4912 temp_int = append_internal(state->internal); in stv090x_setup_compound()
4914 kfree(state->internal); in stv090x_setup_compound()
4917 state->internal->num_used = 1; in stv090x_setup_compound()
4918 state->internal->mclk = 0; in stv090x_setup_compound()
4919 state->internal->dev_ver = 0; in stv090x_setup_compound()
4920 state->internal->i2c_adap = state->i2c; in stv090x_setup_compound()
4921 state->internal->i2c_addr = state->config->address; in stv090x_setup_compound()
4924 mutex_init(&state->internal->demod_lock); in stv090x_setup_compound()
4925 mutex_init(&state->internal->tuner_lock); in stv090x_setup_compound()
4927 if (stv090x_setup(&state->frontend) < 0) { in stv090x_setup_compound()
4933 if (state->internal->dev_ver >= 0x30) in stv090x_setup_compound()
4934 state->frontend.ops.info.caps |= FE_CAN_MULTISTREAM; in stv090x_setup_compound()
4937 if (state->config->diseqc_envelope_mode) in stv090x_setup_compound()
4938 stv090x_send_diseqc_burst(&state->frontend, SEC_MINI_A); in stv090x_setup_compound()
4940 state->config->set_gpio = stv090x_set_gpio; in stv090x_setup_compound()
4943 state->device == STV0900 ? "STV0900" : "STV0903", in stv090x_setup_compound()
4944 state->config->demod, in stv090x_setup_compound()
4945 state->internal->dev_ver); in stv090x_setup_compound()
4952 remove_dev(state->internal); in stv090x_setup_compound()
4953 kfree(state->internal); in stv090x_setup_compound()
4991 struct stv090x_state *state = i2c_get_clientdata(client); in stv090x_get_dvb_frontend() local
4995 return &state->frontend; in stv090x_get_dvb_frontend()
5003 struct stv090x_state *state = NULL; in stv090x_probe() local
5005 state = kzalloc(sizeof(*state), GFP_KERNEL); in stv090x_probe()
5006 if (!state) { in stv090x_probe()
5011 state->verbose = &verbose; in stv090x_probe()
5012 state->config = config; in stv090x_probe()
5013 state->i2c = client->adapter; in stv090x_probe()
5014 state->frontend.ops = stv090x_ops; in stv090x_probe()
5015 state->frontend.demodulator_priv = state; in stv090x_probe()
5016 state->demod = config->demod; in stv090x_probe()
5018 state->demod_mode = config->demod_mode; in stv090x_probe()
5019 state->device = config->device; in stv090x_probe()
5021 state->rolloff = STV090x_RO_35; in stv090x_probe()
5023 ret = stv090x_setup_compound(state); in stv090x_probe()
5027 i2c_set_clientdata(client, state); in stv090x_probe()
5035 kfree(state); in stv090x_probe()
5041 struct stv090x_state *state = i2c_get_clientdata(client); in stv090x_remove() local
5043 stv090x_release(&state->frontend); in stv090x_remove()
5051 struct stv090x_state *state = NULL; in stv090x_attach() local
5053 state = kzalloc(sizeof(*state), GFP_KERNEL); in stv090x_attach()
5054 if (!state) in stv090x_attach()
5057 state->verbose = &verbose; in stv090x_attach()
5058 state->config = config; in stv090x_attach()
5059 state->i2c = i2c; in stv090x_attach()
5060 state->frontend.ops = stv090x_ops; in stv090x_attach()
5061 state->frontend.demodulator_priv = state; in stv090x_attach()
5062 state->demod = demod; in stv090x_attach()
5064 state->demod_mode = config->demod_mode; in stv090x_attach()
5065 state->device = config->device; in stv090x_attach()
5067 state->rolloff = STV090x_RO_35; in stv090x_attach()
5069 ret = stv090x_setup_compound(state); in stv090x_attach()
5073 return &state->frontend; in stv090x_attach()
5076 kfree(state); in stv090x_attach()