Lines Matching refs: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 int stv090x_i2c_gate_ctrl(struct stv090x_state *state, int enable) in stv090x_i2c_gate_ctrl() argument
765 if (state->config->tuner_i2c_lock) in stv090x_i2c_gate_ctrl()
766 state->config->tuner_i2c_lock(&state->frontend, 1); in stv090x_i2c_gate_ctrl()
768 mutex_lock(&state->internal->tuner_lock); in stv090x_i2c_gate_ctrl()
771 reg = STV090x_READ_DEMOD(state, I2CRPT); in stv090x_i2c_gate_ctrl()
775 if (STV090x_WRITE_DEMOD(state, I2CRPT, reg) < 0) in stv090x_i2c_gate_ctrl()
781 if ((STV090x_WRITE_DEMOD(state, I2CRPT, reg)) < 0) in stv090x_i2c_gate_ctrl()
786 if (state->config->tuner_i2c_lock) in stv090x_i2c_gate_ctrl()
787 state->config->tuner_i2c_lock(&state->frontend, 0); in stv090x_i2c_gate_ctrl()
789 mutex_unlock(&state->internal->tuner_lock); in stv090x_i2c_gate_ctrl()
795 if (state->config->tuner_i2c_lock) in stv090x_i2c_gate_ctrl()
796 state->config->tuner_i2c_lock(&state->frontend, 0); in stv090x_i2c_gate_ctrl()
798 mutex_unlock(&state->internal->tuner_lock); in stv090x_i2c_gate_ctrl()
802 static void stv090x_get_lock_tmg(struct stv090x_state *state) in stv090x_get_lock_tmg() argument
804 switch (state->algo) { in stv090x_get_lock_tmg()
807 if (state->srate <= 1500000) { /*10Msps< SR <=15Msps*/ in stv090x_get_lock_tmg()
808 state->DemodTimeout = 1500; in stv090x_get_lock_tmg()
809 state->FecTimeout = 400; in stv090x_get_lock_tmg()
810 } else if (state->srate <= 5000000) { /*10Msps< SR <=15Msps*/ in stv090x_get_lock_tmg()
811 state->DemodTimeout = 1000; in stv090x_get_lock_tmg()
812 state->FecTimeout = 300; in stv090x_get_lock_tmg()
814 state->DemodTimeout = 700; in stv090x_get_lock_tmg()
815 state->FecTimeout = 100; in stv090x_get_lock_tmg()
823 if (state->srate <= 1000000) { /*SR <=1Msps*/ in stv090x_get_lock_tmg()
824 state->DemodTimeout = 4500; in stv090x_get_lock_tmg()
825 state->FecTimeout = 1700; in stv090x_get_lock_tmg()
826 } else if (state->srate <= 2000000) { /*1Msps < SR <= 2Msps */ in stv090x_get_lock_tmg()
827 state->DemodTimeout = 2500; in stv090x_get_lock_tmg()
828 state->FecTimeout = 1100; in stv090x_get_lock_tmg()
829 } else if (state->srate <= 5000000) { /*2Msps < SR <= 5Msps */ in stv090x_get_lock_tmg()
830 state->DemodTimeout = 1000; in stv090x_get_lock_tmg()
831 state->FecTimeout = 550; in stv090x_get_lock_tmg()
832 } else if (state->srate <= 10000000) { /*5Msps < SR <= 10Msps */ in stv090x_get_lock_tmg()
833 state->DemodTimeout = 700; in stv090x_get_lock_tmg()
834 state->FecTimeout = 250; in stv090x_get_lock_tmg()
835 } else if (state->srate <= 20000000) { /*10Msps < SR <= 20Msps */ in stv090x_get_lock_tmg()
836 state->DemodTimeout = 400; in stv090x_get_lock_tmg()
837 state->FecTimeout = 130; in stv090x_get_lock_tmg()
839 state->DemodTimeout = 300; in stv090x_get_lock_tmg()
840 state->FecTimeout = 100; in stv090x_get_lock_tmg()
845 if (state->algo == STV090x_WARM_SEARCH) in stv090x_get_lock_tmg()
846 state->DemodTimeout /= 2; in stv090x_get_lock_tmg()
849 static int stv090x_set_srate(struct stv090x_state *state, u32 srate) in stv090x_set_srate() argument
855 sym /= (state->internal->mclk >> 12); in stv090x_set_srate()
858 sym /= (state->internal->mclk >> 10); in stv090x_set_srate()
861 sym /= (state->internal->mclk >> 7); in stv090x_set_srate()
864 if (STV090x_WRITE_DEMOD(state, SFRINIT1, (sym >> 8) & 0x7f) < 0) /* MSB */ in stv090x_set_srate()
866 if (STV090x_WRITE_DEMOD(state, SFRINIT0, (sym & 0xff)) < 0) /* LSB */ in stv090x_set_srate()
875 static int stv090x_set_max_srate(struct stv090x_state *state, u32 clk, u32 srate) in stv090x_set_max_srate() argument
882 sym /= (state->internal->mclk >> 12); in stv090x_set_max_srate()
885 sym /= (state->internal->mclk >> 10); in stv090x_set_max_srate()
888 sym /= (state->internal->mclk >> 7); in stv090x_set_max_srate()
892 if (STV090x_WRITE_DEMOD(state, SFRUP1, (sym >> 8) & 0x7f) < 0) /* MSB */ in stv090x_set_max_srate()
894 if (STV090x_WRITE_DEMOD(state, SFRUP0, sym & 0xff) < 0) /* LSB */ in stv090x_set_max_srate()
897 if (STV090x_WRITE_DEMOD(state, SFRUP1, 0x7f) < 0) /* MSB */ in stv090x_set_max_srate()
899 if (STV090x_WRITE_DEMOD(state, SFRUP0, 0xff) < 0) /* LSB */ in stv090x_set_max_srate()
909 static int stv090x_set_min_srate(struct stv090x_state *state, u32 clk, u32 srate) in stv090x_set_min_srate() argument
916 sym /= (state->internal->mclk >> 12); in stv090x_set_min_srate()
919 sym /= (state->internal->mclk >> 10); in stv090x_set_min_srate()
922 sym /= (state->internal->mclk >> 7); in stv090x_set_min_srate()
925 if (STV090x_WRITE_DEMOD(state, SFRLOW1, ((sym >> 8) & 0x7f)) < 0) /* MSB */ in stv090x_set_min_srate()
927 if (STV090x_WRITE_DEMOD(state, SFRLOW0, (sym & 0xff)) < 0) /* LSB */ in stv090x_set_min_srate()
955 static int stv090x_set_vit_thacq(struct stv090x_state *state) in stv090x_set_vit_thacq() argument
957 if (STV090x_WRITE_DEMOD(state, VTH12, 0x96) < 0) in stv090x_set_vit_thacq()
959 if (STV090x_WRITE_DEMOD(state, VTH23, 0x64) < 0) in stv090x_set_vit_thacq()
961 if (STV090x_WRITE_DEMOD(state, VTH34, 0x36) < 0) in stv090x_set_vit_thacq()
963 if (STV090x_WRITE_DEMOD(state, VTH56, 0x23) < 0) in stv090x_set_vit_thacq()
965 if (STV090x_WRITE_DEMOD(state, VTH67, 0x1e) < 0) in stv090x_set_vit_thacq()
967 if (STV090x_WRITE_DEMOD(state, VTH78, 0x19) < 0) in stv090x_set_vit_thacq()
975 static int stv090x_set_vit_thtracq(struct stv090x_state *state) in stv090x_set_vit_thtracq() argument
977 if (STV090x_WRITE_DEMOD(state, VTH12, 0xd0) < 0) in stv090x_set_vit_thtracq()
979 if (STV090x_WRITE_DEMOD(state, VTH23, 0x7d) < 0) in stv090x_set_vit_thtracq()
981 if (STV090x_WRITE_DEMOD(state, VTH34, 0x53) < 0) in stv090x_set_vit_thtracq()
983 if (STV090x_WRITE_DEMOD(state, VTH56, 0x2f) < 0) in stv090x_set_vit_thtracq()
985 if (STV090x_WRITE_DEMOD(state, VTH67, 0x24) < 0) in stv090x_set_vit_thtracq()
987 if (STV090x_WRITE_DEMOD(state, VTH78, 0x1f) < 0) in stv090x_set_vit_thtracq()
995 static int stv090x_set_viterbi(struct stv090x_state *state) in stv090x_set_viterbi() argument
997 switch (state->search_mode) { in stv090x_set_viterbi()
999 if (STV090x_WRITE_DEMOD(state, FECM, 0x10) < 0) /* DVB-S and DVB-S2 */ in stv090x_set_viterbi()
1001 if (STV090x_WRITE_DEMOD(state, PRVIT, 0x3f) < 0) /* all puncture rate */ in stv090x_set_viterbi()
1005 if (STV090x_WRITE_DEMOD(state, FECM, 0x00) < 0) /* disable DSS */ in stv090x_set_viterbi()
1007 switch (state->fec) { in stv090x_set_viterbi()
1009 if (STV090x_WRITE_DEMOD(state, PRVIT, 0x01) < 0) in stv090x_set_viterbi()
1014 if (STV090x_WRITE_DEMOD(state, PRVIT, 0x02) < 0) in stv090x_set_viterbi()
1019 if (STV090x_WRITE_DEMOD(state, PRVIT, 0x04) < 0) in stv090x_set_viterbi()
1024 if (STV090x_WRITE_DEMOD(state, PRVIT, 0x08) < 0) in stv090x_set_viterbi()
1029 if (STV090x_WRITE_DEMOD(state, PRVIT, 0x20) < 0) in stv090x_set_viterbi()
1034 if (STV090x_WRITE_DEMOD(state, PRVIT, 0x2f) < 0) /* all */ in stv090x_set_viterbi()
1040 if (STV090x_WRITE_DEMOD(state, FECM, 0x80) < 0) in stv090x_set_viterbi()
1042 switch (state->fec) { in stv090x_set_viterbi()
1044 if (STV090x_WRITE_DEMOD(state, PRVIT, 0x01) < 0) in stv090x_set_viterbi()
1049 if (STV090x_WRITE_DEMOD(state, PRVIT, 0x02) < 0) in stv090x_set_viterbi()
1054 if (STV090x_WRITE_DEMOD(state, PRVIT, 0x10) < 0) in stv090x_set_viterbi()
1059 if (STV090x_WRITE_DEMOD(state, PRVIT, 0x13) < 0) /* 1/2, 2/3, 6/7 */ in stv090x_set_viterbi()
1073 static int stv090x_stop_modcod(struct stv090x_state *state) in stv090x_stop_modcod() argument
1075 if (STV090x_WRITE_DEMOD(state, MODCODLST0, 0xff) < 0) in stv090x_stop_modcod()
1077 if (STV090x_WRITE_DEMOD(state, MODCODLST1, 0xff) < 0) in stv090x_stop_modcod()
1079 if (STV090x_WRITE_DEMOD(state, MODCODLST2, 0xff) < 0) in stv090x_stop_modcod()
1081 if (STV090x_WRITE_DEMOD(state, MODCODLST3, 0xff) < 0) in stv090x_stop_modcod()
1083 if (STV090x_WRITE_DEMOD(state, MODCODLST4, 0xff) < 0) in stv090x_stop_modcod()
1085 if (STV090x_WRITE_DEMOD(state, MODCODLST5, 0xff) < 0) in stv090x_stop_modcod()
1087 if (STV090x_WRITE_DEMOD(state, MODCODLST6, 0xff) < 0) in stv090x_stop_modcod()
1089 if (STV090x_WRITE_DEMOD(state, MODCODLST7, 0xff) < 0) in stv090x_stop_modcod()
1091 if (STV090x_WRITE_DEMOD(state, MODCODLST8, 0xff) < 0) in stv090x_stop_modcod()
1093 if (STV090x_WRITE_DEMOD(state, MODCODLST9, 0xff) < 0) in stv090x_stop_modcod()
1095 if (STV090x_WRITE_DEMOD(state, MODCODLSTA, 0xff) < 0) in stv090x_stop_modcod()
1097 if (STV090x_WRITE_DEMOD(state, MODCODLSTB, 0xff) < 0) in stv090x_stop_modcod()
1099 if (STV090x_WRITE_DEMOD(state, MODCODLSTC, 0xff) < 0) in stv090x_stop_modcod()
1101 if (STV090x_WRITE_DEMOD(state, MODCODLSTD, 0xff) < 0) in stv090x_stop_modcod()
1103 if (STV090x_WRITE_DEMOD(state, MODCODLSTE, 0xff) < 0) in stv090x_stop_modcod()
1105 if (STV090x_WRITE_DEMOD(state, MODCODLSTF, 0xff) < 0) in stv090x_stop_modcod()
1113 static int stv090x_activate_modcod(struct stv090x_state *state) in stv090x_activate_modcod() argument
1115 if (STV090x_WRITE_DEMOD(state, MODCODLST0, 0xff) < 0) in stv090x_activate_modcod()
1117 if (STV090x_WRITE_DEMOD(state, MODCODLST1, 0xfc) < 0) in stv090x_activate_modcod()
1119 if (STV090x_WRITE_DEMOD(state, MODCODLST2, 0xcc) < 0) in stv090x_activate_modcod()
1121 if (STV090x_WRITE_DEMOD(state, MODCODLST3, 0xcc) < 0) in stv090x_activate_modcod()
1123 if (STV090x_WRITE_DEMOD(state, MODCODLST4, 0xcc) < 0) in stv090x_activate_modcod()
1125 if (STV090x_WRITE_DEMOD(state, MODCODLST5, 0xcc) < 0) in stv090x_activate_modcod()
1127 if (STV090x_WRITE_DEMOD(state, MODCODLST6, 0xcc) < 0) in stv090x_activate_modcod()
1129 if (STV090x_WRITE_DEMOD(state, MODCODLST7, 0xcc) < 0) in stv090x_activate_modcod()
1131 if (STV090x_WRITE_DEMOD(state, MODCODLST8, 0xcc) < 0) in stv090x_activate_modcod()
1133 if (STV090x_WRITE_DEMOD(state, MODCODLST9, 0xcc) < 0) in stv090x_activate_modcod()
1135 if (STV090x_WRITE_DEMOD(state, MODCODLSTA, 0xcc) < 0) in stv090x_activate_modcod()
1137 if (STV090x_WRITE_DEMOD(state, MODCODLSTB, 0xcc) < 0) in stv090x_activate_modcod()
1139 if (STV090x_WRITE_DEMOD(state, MODCODLSTC, 0xcc) < 0) in stv090x_activate_modcod()
1141 if (STV090x_WRITE_DEMOD(state, MODCODLSTD, 0xcc) < 0) in stv090x_activate_modcod()
1143 if (STV090x_WRITE_DEMOD(state, MODCODLSTE, 0xcc) < 0) in stv090x_activate_modcod()
1145 if (STV090x_WRITE_DEMOD(state, MODCODLSTF, 0xcf) < 0) in stv090x_activate_modcod()
1154 static int stv090x_activate_modcod_single(struct stv090x_state *state) in stv090x_activate_modcod_single() argument
1157 if (STV090x_WRITE_DEMOD(state, MODCODLST0, 0xff) < 0) in stv090x_activate_modcod_single()
1159 if (STV090x_WRITE_DEMOD(state, MODCODLST1, 0xf0) < 0) in stv090x_activate_modcod_single()
1161 if (STV090x_WRITE_DEMOD(state, MODCODLST2, 0x00) < 0) in stv090x_activate_modcod_single()
1163 if (STV090x_WRITE_DEMOD(state, MODCODLST3, 0x00) < 0) in stv090x_activate_modcod_single()
1165 if (STV090x_WRITE_DEMOD(state, MODCODLST4, 0x00) < 0) in stv090x_activate_modcod_single()
1167 if (STV090x_WRITE_DEMOD(state, MODCODLST5, 0x00) < 0) in stv090x_activate_modcod_single()
1169 if (STV090x_WRITE_DEMOD(state, MODCODLST6, 0x00) < 0) in stv090x_activate_modcod_single()
1171 if (STV090x_WRITE_DEMOD(state, MODCODLST7, 0x00) < 0) in stv090x_activate_modcod_single()
1173 if (STV090x_WRITE_DEMOD(state, MODCODLST8, 0x00) < 0) in stv090x_activate_modcod_single()
1175 if (STV090x_WRITE_DEMOD(state, MODCODLST9, 0x00) < 0) in stv090x_activate_modcod_single()
1177 if (STV090x_WRITE_DEMOD(state, MODCODLSTA, 0x00) < 0) in stv090x_activate_modcod_single()
1179 if (STV090x_WRITE_DEMOD(state, MODCODLSTB, 0x00) < 0) in stv090x_activate_modcod_single()
1181 if (STV090x_WRITE_DEMOD(state, MODCODLSTC, 0x00) < 0) in stv090x_activate_modcod_single()
1183 if (STV090x_WRITE_DEMOD(state, MODCODLSTD, 0x00) < 0) in stv090x_activate_modcod_single()
1185 if (STV090x_WRITE_DEMOD(state, MODCODLSTE, 0x00) < 0) in stv090x_activate_modcod_single()
1187 if (STV090x_WRITE_DEMOD(state, MODCODLSTF, 0x0f) < 0) in stv090x_activate_modcod_single()
1197 static int stv090x_vitclk_ctl(struct stv090x_state *state, int enable) in stv090x_vitclk_ctl() argument
1201 switch (state->demod) { in stv090x_vitclk_ctl()
1203 mutex_lock(&state->internal->demod_lock); in stv090x_vitclk_ctl()
1204 reg = stv090x_read_reg(state, STV090x_STOPCLK2); in stv090x_vitclk_ctl()
1206 if (stv090x_write_reg(state, STV090x_STOPCLK2, reg) < 0) in stv090x_vitclk_ctl()
1208 mutex_unlock(&state->internal->demod_lock); in stv090x_vitclk_ctl()
1212 mutex_lock(&state->internal->demod_lock); in stv090x_vitclk_ctl()
1213 reg = stv090x_read_reg(state, STV090x_STOPCLK2); in stv090x_vitclk_ctl()
1215 if (stv090x_write_reg(state, STV090x_STOPCLK2, reg) < 0) in stv090x_vitclk_ctl()
1217 mutex_unlock(&state->internal->demod_lock); in stv090x_vitclk_ctl()
1226 mutex_unlock(&state->internal->demod_lock); in stv090x_vitclk_ctl()
1231 static int stv090x_dvbs_track_crl(struct stv090x_state *state) in stv090x_dvbs_track_crl() argument
1233 if (state->internal->dev_ver >= 0x30) { in stv090x_dvbs_track_crl()
1235 if (state->srate >= 15000000) { in stv090x_dvbs_track_crl()
1236 if (STV090x_WRITE_DEMOD(state, ACLC, 0x2b) < 0) in stv090x_dvbs_track_crl()
1238 if (STV090x_WRITE_DEMOD(state, BCLC, 0x1a) < 0) in stv090x_dvbs_track_crl()
1240 } else if ((state->srate >= 7000000) && (15000000 > state->srate)) { in stv090x_dvbs_track_crl()
1241 if (STV090x_WRITE_DEMOD(state, ACLC, 0x0c) < 0) in stv090x_dvbs_track_crl()
1243 if (STV090x_WRITE_DEMOD(state, BCLC, 0x1b) < 0) in stv090x_dvbs_track_crl()
1245 } else if (state->srate < 7000000) { in stv090x_dvbs_track_crl()
1246 if (STV090x_WRITE_DEMOD(state, ACLC, 0x2c) < 0) in stv090x_dvbs_track_crl()
1248 if (STV090x_WRITE_DEMOD(state, BCLC, 0x1c) < 0) in stv090x_dvbs_track_crl()
1254 if (STV090x_WRITE_DEMOD(state, ACLC, 0x1a) < 0) in stv090x_dvbs_track_crl()
1256 if (STV090x_WRITE_DEMOD(state, BCLC, 0x09) < 0) in stv090x_dvbs_track_crl()
1265 static int stv090x_delivery_search(struct stv090x_state *state) in stv090x_delivery_search() argument
1269 switch (state->search_mode) { in stv090x_delivery_search()
1272 reg = STV090x_READ_DEMOD(state, DMDCFGMD); in stv090x_delivery_search()
1275 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) in stv090x_delivery_search()
1281 if (stv090x_vitclk_ctl(state, 0) < 0) in stv090x_delivery_search()
1284 if (stv090x_dvbs_track_crl(state) < 0) in stv090x_delivery_search()
1287 if (STV090x_WRITE_DEMOD(state, CAR2CFG, 0x22) < 0) /* disable DVB-S2 */ in stv090x_delivery_search()
1290 if (stv090x_set_vit_thacq(state) < 0) in stv090x_delivery_search()
1292 if (stv090x_set_viterbi(state) < 0) in stv090x_delivery_search()
1297 reg = STV090x_READ_DEMOD(state, DMDCFGMD); in stv090x_delivery_search()
1300 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) in stv090x_delivery_search()
1304 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) in stv090x_delivery_search()
1307 if (stv090x_vitclk_ctl(state, 1) < 0) in stv090x_delivery_search()
1310 if (STV090x_WRITE_DEMOD(state, ACLC, 0x1a) < 0) /* stop DVB-S CR loop */ in stv090x_delivery_search()
1312 if (STV090x_WRITE_DEMOD(state, BCLC, 0x09) < 0) in stv090x_delivery_search()
1315 if (state->internal->dev_ver <= 0x20) { in stv090x_delivery_search()
1317 if (STV090x_WRITE_DEMOD(state, CAR2CFG, 0x26) < 0) in stv090x_delivery_search()
1321 if (STV090x_WRITE_DEMOD(state, CAR2CFG, 0x66) < 0) in stv090x_delivery_search()
1325 if (state->demod_mode != STV090x_SINGLE) { in stv090x_delivery_search()
1327 if (stv090x_activate_modcod(state) < 0) in stv090x_delivery_search()
1334 if (stv090x_activate_modcod_single(state) < 0) in stv090x_delivery_search()
1338 if (stv090x_set_vit_thtracq(state) < 0) in stv090x_delivery_search()
1345 reg = STV090x_READ_DEMOD(state, DMDCFGMD); in stv090x_delivery_search()
1348 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) in stv090x_delivery_search()
1352 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) in stv090x_delivery_search()
1355 if (stv090x_vitclk_ctl(state, 0) < 0) in stv090x_delivery_search()
1358 if (stv090x_dvbs_track_crl(state) < 0) in stv090x_delivery_search()
1361 if (state->internal->dev_ver <= 0x20) { in stv090x_delivery_search()
1363 if (STV090x_WRITE_DEMOD(state, CAR2CFG, 0x26) < 0) in stv090x_delivery_search()
1367 if (STV090x_WRITE_DEMOD(state, CAR2CFG, 0x66) < 0) in stv090x_delivery_search()
1371 if (state->demod_mode != STV090x_SINGLE) { in stv090x_delivery_search()
1373 if (stv090x_activate_modcod(state) < 0) in stv090x_delivery_search()
1380 if (stv090x_activate_modcod_single(state) < 0) in stv090x_delivery_search()
1384 if (stv090x_set_vit_thacq(state) < 0) in stv090x_delivery_search()
1387 if (stv090x_set_viterbi(state) < 0) in stv090x_delivery_search()
1397 static int stv090x_start_search(struct stv090x_state *state) in stv090x_start_search() argument
1403 reg = STV090x_READ_DEMOD(state, DMDISTATE); in stv090x_start_search()
1405 if (STV090x_WRITE_DEMOD(state, DMDISTATE, reg) < 0) in stv090x_start_search()
1408 if (state->internal->dev_ver <= 0x20) { in stv090x_start_search()
1409 if (state->srate <= 5000000) { in stv090x_start_search()
1410 if (STV090x_WRITE_DEMOD(state, CARCFG, 0x44) < 0) in stv090x_start_search()
1412 if (STV090x_WRITE_DEMOD(state, CFRUP1, 0x0f) < 0) in stv090x_start_search()
1414 if (STV090x_WRITE_DEMOD(state, CFRUP0, 0xff) < 0) in stv090x_start_search()
1416 if (STV090x_WRITE_DEMOD(state, CFRLOW1, 0xf0) < 0) in stv090x_start_search()
1418 if (STV090x_WRITE_DEMOD(state, CFRLOW0, 0x00) < 0) in stv090x_start_search()
1422 if (STV090x_WRITE_DEMOD(state, RTCS2, 0x68) < 0) in stv090x_start_search()
1427 if (STV090x_WRITE_DEMOD(state, CARCFG, 0xc4) < 0) in stv090x_start_search()
1430 if (STV090x_WRITE_DEMOD(state, RTCS2, 0x44) < 0) in stv090x_start_search()
1435 if (state->srate <= 5000000) { in stv090x_start_search()
1437 STV090x_WRITE_DEMOD(state, RTCS2, 0x68); in stv090x_start_search()
1440 STV090x_WRITE_DEMOD(state, RTCS2, 0x44); in stv090x_start_search()
1444 STV090x_WRITE_DEMOD(state, CARCFG, 0x46); in stv090x_start_search()
1446 if (state->algo == STV090x_WARM_SEARCH) { in stv090x_start_search()
1452 freq_abs /= (state->internal->mclk / 1000); in stv090x_start_search()
1460 freq_abs = (state->search_range / 2000) + 600; in stv090x_start_search()
1462 freq_abs /= (state->internal->mclk / 1000); in stv090x_start_search()
1466 if (STV090x_WRITE_DEMOD(state, CFRUP1, MSB(freq)) < 0) in stv090x_start_search()
1468 if (STV090x_WRITE_DEMOD(state, CFRUP0, LSB(freq)) < 0) in stv090x_start_search()
1473 if (STV090x_WRITE_DEMOD(state, CFRLOW1, MSB(freq)) < 0) in stv090x_start_search()
1475 if (STV090x_WRITE_DEMOD(state, CFRLOW0, LSB(freq)) < 0) in stv090x_start_search()
1480 if (STV090x_WRITE_DEMOD(state, CFRINIT1, 0) < 0) in stv090x_start_search()
1482 if (STV090x_WRITE_DEMOD(state, CFRINIT0, 0) < 0) in stv090x_start_search()
1485 if (state->internal->dev_ver >= 0x20) { in stv090x_start_search()
1486 if (STV090x_WRITE_DEMOD(state, EQUALCFG, 0x41) < 0) in stv090x_start_search()
1488 if (STV090x_WRITE_DEMOD(state, FFECFG, 0x41) < 0) in stv090x_start_search()
1491 if ((state->search_mode == STV090x_SEARCH_DVBS1) || in stv090x_start_search()
1492 (state->search_mode == STV090x_SEARCH_DSS) || in stv090x_start_search()
1493 (state->search_mode == STV090x_SEARCH_AUTO)) { in stv090x_start_search()
1495 if (STV090x_WRITE_DEMOD(state, VITSCALE, 0x82) < 0) in stv090x_start_search()
1497 if (STV090x_WRITE_DEMOD(state, VAVSRVIT, 0x00) < 0) in stv090x_start_search()
1502 if (STV090x_WRITE_DEMOD(state, SFRSTEP, 0x00) < 0) in stv090x_start_search()
1504 if (STV090x_WRITE_DEMOD(state, TMGTHRISE, 0xe0) < 0) in stv090x_start_search()
1506 if (STV090x_WRITE_DEMOD(state, TMGTHFALL, 0xc0) < 0) in stv090x_start_search()
1509 reg = STV090x_READ_DEMOD(state, DMDCFGMD); in stv090x_start_search()
1512 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) in stv090x_start_search()
1514 reg = STV090x_READ_DEMOD(state, DMDCFG2); in stv090x_start_search()
1516 if (STV090x_WRITE_DEMOD(state, DMDCFG2, reg) < 0) in stv090x_start_search()
1519 if (STV090x_WRITE_DEMOD(state, RTC, 0x88) < 0) in stv090x_start_search()
1522 if (state->internal->dev_ver >= 0x20) { in stv090x_start_search()
1524 if (state->srate < 2000000) { in stv090x_start_search()
1525 if (state->internal->dev_ver <= 0x20) { in stv090x_start_search()
1527 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x39) < 0) in stv090x_start_search()
1531 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x89) < 0) in stv090x_start_search()
1534 if (STV090x_WRITE_DEMOD(state, CARHDR, 0x40) < 0) in stv090x_start_search()
1536 } else if (state->srate < 10000000) { in stv090x_start_search()
1537 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x4c) < 0) in stv090x_start_search()
1539 if (STV090x_WRITE_DEMOD(state, CARHDR, 0x20) < 0) in stv090x_start_search()
1542 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x4b) < 0) in stv090x_start_search()
1544 if (STV090x_WRITE_DEMOD(state, CARHDR, 0x20) < 0) in stv090x_start_search()
1548 if (state->srate < 10000000) { in stv090x_start_search()
1549 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0xef) < 0) in stv090x_start_search()
1552 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0xed) < 0) in stv090x_start_search()
1557 switch (state->algo) { in stv090x_start_search()
1562 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x1f) < 0) in stv090x_start_search()
1564 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x18) < 0) in stv090x_start_search()
1570 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x1f) < 0) in stv090x_start_search()
1572 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x15) < 0) in stv090x_start_search()
1585 static int stv090x_get_agc2_min_level(struct stv090x_state *state) in stv090x_get_agc2_min_level() argument
1590 if (STV090x_WRITE_DEMOD(state, AGC2REF, 0x38) < 0) in stv090x_get_agc2_min_level()
1592 reg = STV090x_READ_DEMOD(state, DMDCFGMD); in stv090x_get_agc2_min_level()
1595 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) in stv090x_get_agc2_min_level()
1598 if (STV090x_WRITE_DEMOD(state, SFRUP1, 0x83) < 0) /* SR = 65 Msps Max */ in stv090x_get_agc2_min_level()
1600 if (STV090x_WRITE_DEMOD(state, SFRUP0, 0xc0) < 0) in stv090x_get_agc2_min_level()
1602 if (STV090x_WRITE_DEMOD(state, SFRLOW1, 0x82) < 0) /* SR= 400 ksps Min */ in stv090x_get_agc2_min_level()
1604 if (STV090x_WRITE_DEMOD(state, SFRLOW0, 0xa0) < 0) in stv090x_get_agc2_min_level()
1606 if (STV090x_WRITE_DEMOD(state, DMDTOM, 0x00) < 0) /* stop acq @ coarse carrier state */ in stv090x_get_agc2_min_level()
1608 if (stv090x_set_srate(state, 1000000) < 0) in stv090x_get_agc2_min_level()
1611 steps = state->search_range / 1000000; in stv090x_get_agc2_min_level()
1616 freq_step = (1000000 * 256) / (state->internal->mclk / 256); in stv090x_get_agc2_min_level()
1627 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x5c) < 0) /* Demod RESET */ in stv090x_get_agc2_min_level()
1629 if (STV090x_WRITE_DEMOD(state, CFRINIT1, (freq_init >> 8) & 0xff) < 0) in stv090x_get_agc2_min_level()
1631 if (STV090x_WRITE_DEMOD(state, CFRINIT0, freq_init & 0xff) < 0) in stv090x_get_agc2_min_level()
1633 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x58) < 0) /* Demod RESET */ in stv090x_get_agc2_min_level()
1639 agc2 += (STV090x_READ_DEMOD(state, AGC2I1) << 8) | in stv090x_get_agc2_min_level()
1640 STV090x_READ_DEMOD(state, AGC2I0); in stv090x_get_agc2_min_level()
1653 static u32 stv090x_get_srate(struct stv090x_state *state, u32 clk) in stv090x_get_srate() argument
1658 r3 = STV090x_READ_DEMOD(state, SFR3); in stv090x_get_srate()
1659 r2 = STV090x_READ_DEMOD(state, SFR2); in stv090x_get_srate()
1660 r1 = STV090x_READ_DEMOD(state, SFR1); in stv090x_get_srate()
1661 r0 = STV090x_READ_DEMOD(state, SFR0); in stv090x_get_srate()
1678 static u32 stv090x_srate_srch_coarse(struct stv090x_state *state) in stv090x_srate_srch_coarse() argument
1680 struct dvb_frontend *fe = &state->frontend; in stv090x_srate_srch_coarse()
1687 if (state->internal->dev_ver >= 0x30) in stv090x_srate_srch_coarse()
1692 reg = STV090x_READ_DEMOD(state, DMDISTATE); in stv090x_srate_srch_coarse()
1694 if (STV090x_WRITE_DEMOD(state, DMDISTATE, reg) < 0) in stv090x_srate_srch_coarse()
1696 if (STV090x_WRITE_DEMOD(state, TMGCFG, 0x12) < 0) in stv090x_srate_srch_coarse()
1698 if (STV090x_WRITE_DEMOD(state, TMGCFG2, 0xc0) < 0) in stv090x_srate_srch_coarse()
1700 if (STV090x_WRITE_DEMOD(state, TMGTHRISE, 0xf0) < 0) in stv090x_srate_srch_coarse()
1702 if (STV090x_WRITE_DEMOD(state, TMGTHFALL, 0xe0) < 0) in stv090x_srate_srch_coarse()
1704 reg = STV090x_READ_DEMOD(state, DMDCFGMD); in stv090x_srate_srch_coarse()
1707 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) in stv090x_srate_srch_coarse()
1710 if (STV090x_WRITE_DEMOD(state, SFRUP1, 0x83) < 0) in stv090x_srate_srch_coarse()
1712 if (STV090x_WRITE_DEMOD(state, SFRUP0, 0xc0) < 0) in stv090x_srate_srch_coarse()
1714 if (STV090x_WRITE_DEMOD(state, SFRLOW1, 0x82) < 0) in stv090x_srate_srch_coarse()
1716 if (STV090x_WRITE_DEMOD(state, SFRLOW0, 0xa0) < 0) in stv090x_srate_srch_coarse()
1718 if (STV090x_WRITE_DEMOD(state, DMDTOM, 0x00) < 0) in stv090x_srate_srch_coarse()
1720 if (STV090x_WRITE_DEMOD(state, AGC2REF, 0x50) < 0) in stv090x_srate_srch_coarse()
1723 if (state->internal->dev_ver >= 0x30) { in stv090x_srate_srch_coarse()
1724 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x99) < 0) in stv090x_srate_srch_coarse()
1726 if (STV090x_WRITE_DEMOD(state, SFRSTEP, 0x98) < 0) in stv090x_srate_srch_coarse()
1729 } else if (state->internal->dev_ver >= 0x20) { in stv090x_srate_srch_coarse()
1730 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x6a) < 0) in stv090x_srate_srch_coarse()
1732 if (STV090x_WRITE_DEMOD(state, SFRSTEP, 0x95) < 0) in stv090x_srate_srch_coarse()
1736 if (state->srate <= 2000000) in stv090x_srate_srch_coarse()
1738 else if (state->srate <= 5000000) in stv090x_srate_srch_coarse()
1740 else if (state->srate <= 12000000) in stv090x_srate_srch_coarse()
1745 steps = -1 + ((state->search_range / 1000) / car_step); in stv090x_srate_srch_coarse()
1752 car_step = (state->search_range / 1000) / 10; in stv090x_srate_srch_coarse()
1756 freq = state->frequency; in stv090x_srate_srch_coarse()
1759 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x5f) < 0) /* Demod RESET */ in stv090x_srate_srch_coarse()
1761 if (STV090x_WRITE_DEMOD(state, CFRINIT1, 0x00) < 0) in stv090x_srate_srch_coarse()
1763 if (STV090x_WRITE_DEMOD(state, CFRINIT0, 0x00) < 0) in stv090x_srate_srch_coarse()
1765 if (STV090x_WRITE_DEMOD(state, SFRINIT1, 0x00) < 0) in stv090x_srate_srch_coarse()
1767 if (STV090x_WRITE_DEMOD(state, SFRINIT0, 0x00) < 0) in stv090x_srate_srch_coarse()
1770 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x40) < 0) in stv090x_srate_srch_coarse()
1774 reg = STV090x_READ_DEMOD(state, DSTATUS); in stv090x_srate_srch_coarse()
1777 agc2 += (STV090x_READ_DEMOD(state, AGC2I1) << 8) | in stv090x_srate_srch_coarse()
1778 STV090x_READ_DEMOD(state, AGC2I0); in stv090x_srate_srch_coarse()
1781 srate_coarse = stv090x_get_srate(state, state->internal->mclk); in stv090x_srate_srch_coarse()
1794 if (stv090x_i2c_gate_ctrl(state, 1) < 0) in stv090x_srate_srch_coarse()
1797 if (state->config->tuner_set_frequency) { in stv090x_srate_srch_coarse()
1798 if (state->config->tuner_set_frequency(fe, freq) < 0) in stv090x_srate_srch_coarse()
1802 if (state->config->tuner_set_bandwidth) { in stv090x_srate_srch_coarse()
1803 if (state->config->tuner_set_bandwidth(fe, state->tuner_bw) < 0) in stv090x_srate_srch_coarse()
1807 if (stv090x_i2c_gate_ctrl(state, 0) < 0) in stv090x_srate_srch_coarse()
1812 if (stv090x_i2c_gate_ctrl(state, 1) < 0) in stv090x_srate_srch_coarse()
1815 if (state->config->tuner_get_status) { in stv090x_srate_srch_coarse()
1816 if (state->config->tuner_get_status(fe, &reg) < 0) in stv090x_srate_srch_coarse()
1825 if (stv090x_i2c_gate_ctrl(state, 0) < 0) in stv090x_srate_srch_coarse()
1833 srate_coarse = stv090x_get_srate(state, state->internal->mclk); in stv090x_srate_srch_coarse()
1838 stv090x_i2c_gate_ctrl(state, 0); in stv090x_srate_srch_coarse()
1844 static u32 stv090x_srate_srch_fine(struct stv090x_state *state) in stv090x_srate_srch_fine() argument
1848 srate_coarse = stv090x_get_srate(state, state->internal->mclk); in stv090x_srate_srch_fine()
1849 freq_coarse = STV090x_READ_DEMOD(state, CFR2) << 8; in stv090x_srate_srch_fine()
1850 freq_coarse |= STV090x_READ_DEMOD(state, CFR1); in stv090x_srate_srch_fine()
1853 if (sym < state->srate) in stv090x_srate_srch_fine()
1856 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x1f) < 0) /* Demod RESET */ in stv090x_srate_srch_fine()
1858 if (STV090x_WRITE_DEMOD(state, TMGCFG2, 0xc1) < 0) in stv090x_srate_srch_fine()
1860 if (STV090x_WRITE_DEMOD(state, TMGTHRISE, 0x20) < 0) in stv090x_srate_srch_fine()
1862 if (STV090x_WRITE_DEMOD(state, TMGTHFALL, 0x00) < 0) in stv090x_srate_srch_fine()
1864 if (STV090x_WRITE_DEMOD(state, TMGCFG, 0xd2) < 0) in stv090x_srate_srch_fine()
1866 reg = STV090x_READ_DEMOD(state, DMDCFGMD); in stv090x_srate_srch_fine()
1868 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) in stv090x_srate_srch_fine()
1871 if (STV090x_WRITE_DEMOD(state, AGC2REF, 0x38) < 0) in stv090x_srate_srch_fine()
1874 if (state->internal->dev_ver >= 0x30) { in stv090x_srate_srch_fine()
1875 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x79) < 0) in stv090x_srate_srch_fine()
1877 } else if (state->internal->dev_ver >= 0x20) { in stv090x_srate_srch_fine()
1878 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x49) < 0) in stv090x_srate_srch_fine()
1885 sym /= (state->internal->mclk / 1000); in stv090x_srate_srch_fine()
1886 if (STV090x_WRITE_DEMOD(state, SFRUP1, (sym >> 8) & 0x7f) < 0) in stv090x_srate_srch_fine()
1888 if (STV090x_WRITE_DEMOD(state, SFRUP0, sym & 0xff) < 0) in stv090x_srate_srch_fine()
1892 sym /= (state->internal->mclk / 1000); in stv090x_srate_srch_fine()
1893 if (STV090x_WRITE_DEMOD(state, SFRLOW1, (sym >> 8) & 0x7f) < 0) in stv090x_srate_srch_fine()
1895 if (STV090x_WRITE_DEMOD(state, SFRLOW0, sym & 0xff) < 0) in stv090x_srate_srch_fine()
1898 sym /= (state->internal->mclk / 1000); in stv090x_srate_srch_fine()
1899 if (STV090x_WRITE_DEMOD(state, SFRINIT1, (sym >> 8) & 0xff) < 0) in stv090x_srate_srch_fine()
1901 if (STV090x_WRITE_DEMOD(state, SFRINIT0, sym & 0xff) < 0) in stv090x_srate_srch_fine()
1906 sym /= (state->internal->mclk / 100); in stv090x_srate_srch_fine()
1907 if (STV090x_WRITE_DEMOD(state, SFRUP1, (sym >> 8) & 0x7f) < 0) in stv090x_srate_srch_fine()
1909 if (STV090x_WRITE_DEMOD(state, SFRUP0, sym & 0xff) < 0) in stv090x_srate_srch_fine()
1913 sym /= (state->internal->mclk / 100); in stv090x_srate_srch_fine()
1914 if (STV090x_WRITE_DEMOD(state, SFRLOW1, (sym >> 8) & 0x7f) < 0) in stv090x_srate_srch_fine()
1916 if (STV090x_WRITE_DEMOD(state, SFRLOW0, sym & 0xff) < 0) in stv090x_srate_srch_fine()
1919 sym /= (state->internal->mclk / 100); in stv090x_srate_srch_fine()
1920 if (STV090x_WRITE_DEMOD(state, SFRINIT1, (sym >> 8) & 0xff) < 0) in stv090x_srate_srch_fine()
1922 if (STV090x_WRITE_DEMOD(state, SFRINIT0, sym & 0xff) < 0) in stv090x_srate_srch_fine()
1925 if (STV090x_WRITE_DEMOD(state, DMDTOM, 0x20) < 0) in stv090x_srate_srch_fine()
1927 if (STV090x_WRITE_DEMOD(state, CFRINIT1, (freq_coarse >> 8) & 0xff) < 0) in stv090x_srate_srch_fine()
1929 if (STV090x_WRITE_DEMOD(state, CFRINIT0, freq_coarse & 0xff) < 0) in stv090x_srate_srch_fine()
1931 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x15) < 0) /* trigger acquisition */ in stv090x_srate_srch_fine()
1942 static int stv090x_get_dmdlock(struct stv090x_state *state, s32 timeout) in stv090x_get_dmdlock() argument
1949 reg = STV090x_READ_DEMOD(state, DMDSTATE); in stv090x_get_dmdlock()
1961 reg = STV090x_READ_DEMOD(state, DSTATUS); in stv090x_get_dmdlock()
1976 static int stv090x_blind_search(struct stv090x_state *state) in stv090x_blind_search() argument
1987 agc2 = stv090x_get_agc2_min_level(state); in stv090x_blind_search()
1989 if (agc2 > STV090x_SEARCH_AGC2_TH(state->internal->dev_ver)) { in stv090x_blind_search()
1993 if (state->internal->dev_ver <= 0x20) { in stv090x_blind_search()
1994 if (STV090x_WRITE_DEMOD(state, CARCFG, 0xc4) < 0) in stv090x_blind_search()
1998 if (STV090x_WRITE_DEMOD(state, CARCFG, 0x06) < 0) in stv090x_blind_search()
2002 if (STV090x_WRITE_DEMOD(state, RTCS2, 0x44) < 0) in stv090x_blind_search()
2005 if (state->internal->dev_ver >= 0x20) { in stv090x_blind_search()
2006 if (STV090x_WRITE_DEMOD(state, EQUALCFG, 0x41) < 0) in stv090x_blind_search()
2008 if (STV090x_WRITE_DEMOD(state, FFECFG, 0x41) < 0) in stv090x_blind_search()
2010 if (STV090x_WRITE_DEMOD(state, VITSCALE, 0x82) < 0) in stv090x_blind_search()
2012 if (STV090x_WRITE_DEMOD(state, VAVSRVIT, 0x00) < 0) /* set viterbi hysteresis */ in stv090x_blind_search()
2018 if (STV090x_WRITE_DEMOD(state, KREFTMG, k_ref) < 0) in stv090x_blind_search()
2020 if (stv090x_srate_srch_coarse(state) != 0) { in stv090x_blind_search()
2021 srate_coarse = stv090x_srate_srch_fine(state); in stv090x_blind_search()
2023 stv090x_get_lock_tmg(state); in stv090x_blind_search()
2024 lock = stv090x_get_dmdlock(state, in stv090x_blind_search()
2025 state->DemodTimeout); in stv090x_blind_search()
2033 agc2 += (STV090x_READ_DEMOD(state, AGC2I1) << 8) | in stv090x_blind_search()
2034 STV090x_READ_DEMOD(state, AGC2I0); in stv090x_blind_search()
2037 reg = STV090x_READ_DEMOD(state, DSTATUS2); in stv090x_blind_search()
2059 static int stv090x_chk_tmg(struct stv090x_state *state) in stv090x_chk_tmg() argument
2066 freq = STV090x_READ_DEMOD(state, CARFREQ); in stv090x_chk_tmg()
2067 tmg_thh = STV090x_READ_DEMOD(state, TMGTHRISE); in stv090x_chk_tmg()
2068 tmg_thl = STV090x_READ_DEMOD(state, TMGTHFALL); in stv090x_chk_tmg()
2069 if (STV090x_WRITE_DEMOD(state, TMGTHRISE, 0x20) < 0) in stv090x_chk_tmg()
2071 if (STV090x_WRITE_DEMOD(state, TMGTHFALL, 0x00) < 0) in stv090x_chk_tmg()
2074 reg = STV090x_READ_DEMOD(state, DMDCFGMD); in stv090x_chk_tmg()
2076 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) in stv090x_chk_tmg()
2078 if (STV090x_WRITE_DEMOD(state, RTC, 0x80) < 0) in stv090x_chk_tmg()
2081 if (STV090x_WRITE_DEMOD(state, RTCS2, 0x40) < 0) in stv090x_chk_tmg()
2083 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x00) < 0) in stv090x_chk_tmg()
2086 if (STV090x_WRITE_DEMOD(state, CFRINIT1, 0x00) < 0) /* set car ofset to 0 */ in stv090x_chk_tmg()
2088 if (STV090x_WRITE_DEMOD(state, CFRINIT0, 0x00) < 0) in stv090x_chk_tmg()
2090 if (STV090x_WRITE_DEMOD(state, AGC2REF, 0x65) < 0) in stv090x_chk_tmg()
2093 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x18) < 0) /* trigger acquisition */ in stv090x_chk_tmg()
2098 reg = STV090x_READ_DEMOD(state, DSTATUS); in stv090x_chk_tmg()
2106 if (STV090x_WRITE_DEMOD(state, AGC2REF, 0x38) < 0) in stv090x_chk_tmg()
2108 if (STV090x_WRITE_DEMOD(state, RTC, 0x88) < 0) /* DVB-S1 timing */ in stv090x_chk_tmg()
2110 if (STV090x_WRITE_DEMOD(state, RTCS2, 0x68) < 0) /* DVB-S2 timing */ in stv090x_chk_tmg()
2113 if (STV090x_WRITE_DEMOD(state, CARFREQ, freq) < 0) in stv090x_chk_tmg()
2115 if (STV090x_WRITE_DEMOD(state, TMGTHRISE, tmg_thh) < 0) in stv090x_chk_tmg()
2117 if (STV090x_WRITE_DEMOD(state, TMGTHFALL, tmg_thl) < 0) in stv090x_chk_tmg()
2127 static int stv090x_get_coldlock(struct stv090x_state *state, s32 timeout_dmd) in stv090x_get_coldlock() argument
2129 struct dvb_frontend *fe = &state->frontend; in stv090x_get_coldlock()
2135 if (state->srate >= 10000000) in stv090x_get_coldlock()
2140 lock = stv090x_get_dmdlock(state, timeout_lock); /* cold start wait */ in stv090x_get_coldlock()
2144 if (state->srate >= 10000000) { in stv090x_get_coldlock()
2145 if (stv090x_chk_tmg(state)) { in stv090x_get_coldlock()
2146 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x1f) < 0) in stv090x_get_coldlock()
2148 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x15) < 0) in stv090x_get_coldlock()
2150 return stv090x_get_dmdlock(state, timeout_dmd); in stv090x_get_coldlock()
2155 if (state->srate <= 4000000) in stv090x_get_coldlock()
2157 else if (state->srate <= 7000000) in stv090x_get_coldlock()
2159 else if (state->srate <= 10000000) in stv090x_get_coldlock()
2164 steps = (state->search_range / 1000) / car_step; in stv090x_get_coldlock()
2175 freq = state->frequency; in stv090x_get_coldlock()
2176 state->tuner_bw = stv090x_car_width(state->srate, state->rolloff) + state->srate; in stv090x_get_coldlock()
2184 if (stv090x_i2c_gate_ctrl(state, 1) < 0) in stv090x_get_coldlock()
2187 if (state->config->tuner_set_frequency) { in stv090x_get_coldlock()
2188 if (state->config->tuner_set_frequency(fe, freq) < 0) in stv090x_get_coldlock()
2192 if (state->config->tuner_set_bandwidth) { in stv090x_get_coldlock()
2193 if (state->config->tuner_set_bandwidth(fe, state->tuner_bw) < 0) in stv090x_get_coldlock()
2197 if (stv090x_i2c_gate_ctrl(state, 0) < 0) in stv090x_get_coldlock()
2202 if (stv090x_i2c_gate_ctrl(state, 1) < 0) in stv090x_get_coldlock()
2205 if (state->config->tuner_get_status) { in stv090x_get_coldlock()
2206 if (state->config->tuner_get_status(fe, &reg) < 0) in stv090x_get_coldlock()
2214 if (stv090x_i2c_gate_ctrl(state, 0) < 0) in stv090x_get_coldlock()
2217 STV090x_WRITE_DEMOD(state, DMDISTATE, 0x1c); in stv090x_get_coldlock()
2218 if (STV090x_WRITE_DEMOD(state, CFRINIT1, 0x00) < 0) in stv090x_get_coldlock()
2220 if (STV090x_WRITE_DEMOD(state, CFRINIT0, 0x00) < 0) in stv090x_get_coldlock()
2222 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x1f) < 0) in stv090x_get_coldlock()
2224 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x15) < 0) in stv090x_get_coldlock()
2226 lock = stv090x_get_dmdlock(state, (timeout_dmd / 3)); in stv090x_get_coldlock()
2235 stv090x_i2c_gate_ctrl(state, 0); in stv090x_get_coldlock()
2241 static int stv090x_get_loop_params(struct stv090x_state *state, s32 *freq_inc, s32 *timeout_sw, s32… in stv090x_get_loop_params() argument
2245 srate = state->srate; in stv090x_get_loop_params()
2246 car_max = state->search_range / 1000; in stv090x_get_loop_params()
2249 car_max /= (state->internal->mclk / 1000); in stv090x_get_loop_params()
2255 inc /= state->internal->mclk / 1000; in stv090x_get_loop_params()
2260 switch (state->search_mode) { in stv090x_get_loop_params()
2301 static int stv090x_chk_signal(struct stv090x_state *state) in stv090x_chk_signal() argument
2306 offst_car = STV090x_READ_DEMOD(state, CFR2) << 8; in stv090x_chk_signal()
2307 offst_car |= STV090x_READ_DEMOD(state, CFR1); in stv090x_chk_signal()
2310 agc2 = STV090x_READ_DEMOD(state, AGC2I1) << 8; in stv090x_chk_signal()
2311 agc2 |= STV090x_READ_DEMOD(state, AGC2I0); in stv090x_chk_signal()
2312 car_max = state->search_range / 1000; in stv090x_chk_signal()
2316 car_max /= state->internal->mclk / 1000; in stv090x_chk_signal()
2332 static int stv090x_search_car_loop(struct stv090x_state *state, s32 inc, s32 timeout, int zigzag, s… in stv090x_search_car_loop() argument
2338 car_max = state->search_range / 1000; in stv090x_search_car_loop()
2341 car_max /= (state->internal->mclk / 1000); in stv090x_search_car_loop()
2351 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x1c) < 0) in stv090x_search_car_loop()
2353 if (STV090x_WRITE_DEMOD(state, CFRINIT1, ((offst_freq / 256) & 0xff)) < 0) in stv090x_search_car_loop()
2355 if (STV090x_WRITE_DEMOD(state, CFRINIT0, offst_freq & 0xff) < 0) in stv090x_search_car_loop()
2357 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x18) < 0) in stv090x_search_car_loop()
2360 reg = STV090x_READ_DEMOD(state, PDELCTRL1); in stv090x_search_car_loop()
2362 if (STV090x_WRITE_DEMOD(state, PDELCTRL1, reg) < 0) in stv090x_search_car_loop()
2376 lock = stv090x_get_dmdlock(state, timeout); in stv090x_search_car_loop()
2377 no_signal = stv090x_chk_signal(state); in stv090x_search_car_loop()
2385 reg = STV090x_READ_DEMOD(state, PDELCTRL1); in stv090x_search_car_loop()
2387 if (STV090x_WRITE_DEMOD(state, PDELCTRL1, reg) < 0) in stv090x_search_car_loop()
2396 static int stv090x_sw_algo(struct stv090x_state *state) in stv090x_sw_algo() argument
2405 stv090x_get_loop_params(state, &inc, &timeout_step, &steps_max); in stv090x_sw_algo()
2407 switch (state->search_mode) { in stv090x_sw_algo()
2411 if (state->internal->dev_ver >= 0x20) { in stv090x_sw_algo()
2412 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x3B) < 0) in stv090x_sw_algo()
2416 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, 0x49) < 0) in stv090x_sw_algo()
2422 if (state->internal->dev_ver >= 0x20) { in stv090x_sw_algo()
2423 if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x79) < 0) in stv090x_sw_algo()
2427 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, 0x89) < 0) in stv090x_sw_algo()
2435 if (state->internal->dev_ver >= 0x20) { in stv090x_sw_algo()
2436 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x3b) < 0) in stv090x_sw_algo()
2438 if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x79) < 0) in stv090x_sw_algo()
2442 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, 0xc9) < 0) in stv090x_sw_algo()
2450 lock = stv090x_search_car_loop(state, inc, timeout_step, zigzag, steps_max); in stv090x_sw_algo()
2451 no_signal = stv090x_chk_signal(state); in stv090x_sw_algo()
2457 if (state->internal->dev_ver >= 0x20) { in stv090x_sw_algo()
2458 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x49) < 0) in stv090x_sw_algo()
2460 if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x9e) < 0) in stv090x_sw_algo()
2464 reg = STV090x_READ_DEMOD(state, DMDSTATE); in stv090x_sw_algo()
2468 reg = STV090x_READ_DEMOD(state, DMDFLYW); in stv090x_sw_algo()
2472 reg = STV090x_READ_DEMOD(state, DMDFLYW); in stv090x_sw_algo()
2479 if (state->internal->dev_ver >= 0x20) { in stv090x_sw_algo()
2480 if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x79) < 0) in stv090x_sw_algo()
2484 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, 0x89) < 0) in stv090x_sw_algo()
2498 static enum stv090x_delsys stv090x_get_std(struct stv090x_state *state) in stv090x_get_std() argument
2503 reg = STV090x_READ_DEMOD(state, DMDSTATE); in stv090x_get_std()
2507 reg = STV090x_READ_DEMOD(state, FECM); in stv090x_get_std()
2520 static s32 stv090x_get_car_freq(struct stv090x_state *state, u32 mclk) in stv090x_get_car_freq() argument
2524 derot = STV090x_READ_DEMOD(state, CFR2) << 16; in stv090x_get_car_freq()
2525 derot |= STV090x_READ_DEMOD(state, CFR1) << 8; in stv090x_get_car_freq()
2526 derot |= STV090x_READ_DEMOD(state, CFR0); in stv090x_get_car_freq()
2543 static int stv090x_get_viterbi(struct stv090x_state *state) in stv090x_get_viterbi() argument
2547 reg = STV090x_READ_DEMOD(state, VITCURPUN); in stv090x_get_viterbi()
2552 state->fec = STV090x_PR12; in stv090x_get_viterbi()
2556 state->fec = STV090x_PR23; in stv090x_get_viterbi()
2560 state->fec = STV090x_PR34; in stv090x_get_viterbi()
2564 state->fec = STV090x_PR56; in stv090x_get_viterbi()
2568 state->fec = STV090x_PR67; in stv090x_get_viterbi()
2572 state->fec = STV090x_PR78; in stv090x_get_viterbi()
2576 state->fec = STV090x_PRERR; in stv090x_get_viterbi()
2583 static enum stv090x_signal_state stv090x_get_sig_params(struct stv090x_state *state) in stv090x_get_sig_params() argument
2585 struct dvb_frontend *fe = &state->frontend; in stv090x_get_sig_params()
2593 if (state->algo == STV090x_BLIND_SEARCH) { in stv090x_get_sig_params()
2594 tmg = STV090x_READ_DEMOD(state, TMGREG2); in stv090x_get_sig_params()
2595 STV090x_WRITE_DEMOD(state, SFRSTEP, 0x5c); in stv090x_get_sig_params()
2597 tmg = STV090x_READ_DEMOD(state, TMGREG2); in stv090x_get_sig_params()
2602 state->delsys = stv090x_get_std(state); in stv090x_get_sig_params()
2604 if (stv090x_i2c_gate_ctrl(state, 1) < 0) in stv090x_get_sig_params()
2607 if (state->config->tuner_get_frequency) { in stv090x_get_sig_params()
2608 if (state->config->tuner_get_frequency(fe, &state->frequency) < 0) in stv090x_get_sig_params()
2612 if (stv090x_i2c_gate_ctrl(state, 0) < 0) in stv090x_get_sig_params()
2615 offst_freq = stv090x_get_car_freq(state, state->internal->mclk) / 1000; in stv090x_get_sig_params()
2616 state->frequency += offst_freq; in stv090x_get_sig_params()
2618 if (stv090x_get_viterbi(state) < 0) in stv090x_get_sig_params()
2621 reg = STV090x_READ_DEMOD(state, DMDMODCOD); in stv090x_get_sig_params()
2622 state->modcod = STV090x_GETFIELD_Px(reg, DEMOD_MODCOD_FIELD); in stv090x_get_sig_params()
2623 state->pilots = STV090x_GETFIELD_Px(reg, DEMOD_TYPE_FIELD) & 0x01; in stv090x_get_sig_params()
2624 state->frame_len = STV090x_GETFIELD_Px(reg, DEMOD_TYPE_FIELD) >> 1; in stv090x_get_sig_params()
2625 reg = STV090x_READ_DEMOD(state, TMGOBS); in stv090x_get_sig_params()
2626 state->rolloff = STV090x_GETFIELD_Px(reg, ROLLOFF_STATUS_FIELD); in stv090x_get_sig_params()
2627 reg = STV090x_READ_DEMOD(state, FECM); in stv090x_get_sig_params()
2628 state->inversion = STV090x_GETFIELD_Px(reg, IQINV_FIELD); in stv090x_get_sig_params()
2630 if ((state->algo == STV090x_BLIND_SEARCH) || (state->srate < 10000000)) { in stv090x_get_sig_params()
2632 if (stv090x_i2c_gate_ctrl(state, 1) < 0) in stv090x_get_sig_params()
2635 if (state->config->tuner_get_frequency) { in stv090x_get_sig_params()
2636 if (state->config->tuner_get_frequency(fe, &state->frequency) < 0) in stv090x_get_sig_params()
2640 if (stv090x_i2c_gate_ctrl(state, 0) < 0) in stv090x_get_sig_params()
2643 if (abs(offst_freq) <= ((state->search_range / 2000) + 500)) in stv090x_get_sig_params()
2645 else if (abs(offst_freq) <= (stv090x_car_width(state->srate, state->rolloff) / 2000)) in stv090x_get_sig_params()
2648 if (abs(offst_freq) <= ((state->search_range / 2000) + 500)) in stv090x_get_sig_params()
2655 stv090x_i2c_gate_ctrl(state, 0); in stv090x_get_sig_params()
2661 static u32 stv090x_get_tmgoffst(struct stv090x_state *state, u32 srate) in stv090x_get_tmgoffst() argument
2665 offst_tmg = STV090x_READ_DEMOD(state, TMGREG2) << 16; in stv090x_get_tmgoffst()
2666 offst_tmg |= STV090x_READ_DEMOD(state, TMGREG1) << 8; in stv090x_get_tmgoffst()
2667 offst_tmg |= STV090x_READ_DEMOD(state, TMGREG0); in stv090x_get_tmgoffst()
2679 static u8 stv090x_optimize_carloop(struct stv090x_state *state, enum stv090x_modcod modcod, s32 pil… in stv090x_optimize_carloop() argument
2685 if (state->internal->dev_ver == 0x20) { in stv090x_optimize_carloop()
2721 if (state->srate <= 3000000) in stv090x_optimize_carloop()
2723 else if (state->srate <= 7000000) in stv090x_optimize_carloop()
2725 else if (state->srate <= 15000000) in stv090x_optimize_carloop()
2727 else if (state->srate <= 25000000) in stv090x_optimize_carloop()
2732 if (state->srate <= 3000000) in stv090x_optimize_carloop()
2734 else if (state->srate <= 7000000) in stv090x_optimize_carloop()
2736 else if (state->srate <= 15000000) in stv090x_optimize_carloop()
2738 else if (state->srate <= 25000000) in stv090x_optimize_carloop()
2746 if (state->srate <= 3000000) in stv090x_optimize_carloop()
2748 else if (state->srate <= 7000000) in stv090x_optimize_carloop()
2750 else if (state->srate <= 15000000) in stv090x_optimize_carloop()
2752 else if (state->srate <= 25000000) in stv090x_optimize_carloop()
2757 if (state->srate <= 3000000) in stv090x_optimize_carloop()
2759 else if (state->srate <= 7000000) in stv090x_optimize_carloop()
2761 else if (state->srate <= 15000000) in stv090x_optimize_carloop()
2763 else if (state->srate <= 25000000) in stv090x_optimize_carloop()
2775 if (state->srate <= 3000000) in stv090x_optimize_carloop()
2777 else if (state->srate <= 7000000) in stv090x_optimize_carloop()
2779 else if (state->srate <= 15000000) in stv090x_optimize_carloop()
2781 else if (state->srate <= 25000000) in stv090x_optimize_carloop()
2790 static u8 stv090x_optimize_carloop_short(struct stv090x_state *state) in stv090x_optimize_carloop_short() argument
2796 switch (state->modulation) { in stv090x_optimize_carloop_short()
2812 if (state->internal->dev_ver >= 0x30) { in stv090x_optimize_carloop_short()
2820 if (state->srate <= 3000000) in stv090x_optimize_carloop_short()
2822 else if (state->srate <= 7000000) in stv090x_optimize_carloop_short()
2824 else if (state->srate <= 15000000) in stv090x_optimize_carloop_short()
2826 else if (state->srate <= 25000000) in stv090x_optimize_carloop_short()
2834 static int stv090x_optimize_track(struct stv090x_state *state) in stv090x_optimize_track() argument
2836 struct dvb_frontend *fe = &state->frontend; in stv090x_optimize_track()
2843 srate = stv090x_get_srate(state, state->internal->mclk); in stv090x_optimize_track()
2844 srate += stv090x_get_tmgoffst(state, srate); in stv090x_optimize_track()
2846 switch (state->delsys) { in stv090x_optimize_track()
2849 if (state->search_mode == STV090x_SEARCH_AUTO) { in stv090x_optimize_track()
2850 reg = STV090x_READ_DEMOD(state, DMDCFGMD); in stv090x_optimize_track()
2853 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) in stv090x_optimize_track()
2856 reg = STV090x_READ_DEMOD(state, DEMOD); in stv090x_optimize_track()
2857 STV090x_SETFIELD_Px(reg, ROLLOFF_CONTROL_FIELD, state->rolloff); in stv090x_optimize_track()
2859 if (STV090x_WRITE_DEMOD(state, DEMOD, reg) < 0) in stv090x_optimize_track()
2862 if (state->internal->dev_ver >= 0x30) { in stv090x_optimize_track()
2863 if (stv090x_get_viterbi(state) < 0) in stv090x_optimize_track()
2866 if (state->fec == STV090x_PR12) { in stv090x_optimize_track()
2867 if (STV090x_WRITE_DEMOD(state, GAUSSR0, 0x98) < 0) in stv090x_optimize_track()
2869 if (STV090x_WRITE_DEMOD(state, CCIR0, 0x18) < 0) in stv090x_optimize_track()
2872 if (STV090x_WRITE_DEMOD(state, GAUSSR0, 0x18) < 0) in stv090x_optimize_track()
2874 if (STV090x_WRITE_DEMOD(state, CCIR0, 0x18) < 0) in stv090x_optimize_track()
2879 if (STV090x_WRITE_DEMOD(state, ERRCTRL1, 0x75) < 0) in stv090x_optimize_track()
2884 reg = STV090x_READ_DEMOD(state, DMDCFGMD); in stv090x_optimize_track()
2887 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) in stv090x_optimize_track()
2889 if (state->internal->dev_ver >= 0x30) { in stv090x_optimize_track()
2890 if (STV090x_WRITE_DEMOD(state, ACLC, 0) < 0) in stv090x_optimize_track()
2892 if (STV090x_WRITE_DEMOD(state, BCLC, 0) < 0) in stv090x_optimize_track()
2895 if (state->frame_len == STV090x_LONG_FRAME) { in stv090x_optimize_track()
2896 reg = STV090x_READ_DEMOD(state, DMDMODCOD); in stv090x_optimize_track()
2899 aclc = stv090x_optimize_carloop(state, modcod, pilots); in stv090x_optimize_track()
2901 STV090x_WRITE_DEMOD(state, ACLC2S2Q, aclc); in stv090x_optimize_track()
2903 if (STV090x_WRITE_DEMOD(state, ACLC2S2Q, 0x2a) < 0) in stv090x_optimize_track()
2905 if (STV090x_WRITE_DEMOD(state, ACLC2S28, aclc) < 0) in stv090x_optimize_track()
2908 if ((state->demod_mode == STV090x_SINGLE) && (modcod > STV090x_8PSK_910)) { in stv090x_optimize_track()
2910 if (STV090x_WRITE_DEMOD(state, ACLC2S2Q, 0x2a) < 0) in stv090x_optimize_track()
2912 if (STV090x_WRITE_DEMOD(state, ACLC2S216A, aclc) < 0) in stv090x_optimize_track()
2915 if (STV090x_WRITE_DEMOD(state, ACLC2S2Q, 0x2a) < 0) in stv090x_optimize_track()
2917 if (STV090x_WRITE_DEMOD(state, ACLC2S232A, aclc) < 0) in stv090x_optimize_track()
2923 aclc = stv090x_optimize_carloop_short(state); in stv090x_optimize_track()
2924 if (state->modulation == STV090x_QPSK) { in stv090x_optimize_track()
2925 if (STV090x_WRITE_DEMOD(state, ACLC2S2Q, aclc) < 0) in stv090x_optimize_track()
2927 } else if (state->modulation == STV090x_8PSK) { in stv090x_optimize_track()
2928 if (STV090x_WRITE_DEMOD(state, ACLC2S2Q, 0x2a) < 0) in stv090x_optimize_track()
2930 if (STV090x_WRITE_DEMOD(state, ACLC2S28, aclc) < 0) in stv090x_optimize_track()
2932 } else if (state->modulation == STV090x_16APSK) { in stv090x_optimize_track()
2933 if (STV090x_WRITE_DEMOD(state, ACLC2S2Q, 0x2a) < 0) in stv090x_optimize_track()
2935 if (STV090x_WRITE_DEMOD(state, ACLC2S216A, aclc) < 0) in stv090x_optimize_track()
2937 } else if (state->modulation == STV090x_32APSK) { in stv090x_optimize_track()
2938 if (STV090x_WRITE_DEMOD(state, ACLC2S2Q, 0x2a) < 0) in stv090x_optimize_track()
2940 if (STV090x_WRITE_DEMOD(state, ACLC2S232A, aclc) < 0) in stv090x_optimize_track()
2945 STV090x_WRITE_DEMOD(state, ERRCTRL1, 0x67); /* PER */ in stv090x_optimize_track()
2950 reg = STV090x_READ_DEMOD(state, DMDCFGMD); in stv090x_optimize_track()
2953 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) in stv090x_optimize_track()
2958 f_1 = STV090x_READ_DEMOD(state, CFR2); in stv090x_optimize_track()
2959 f_0 = STV090x_READ_DEMOD(state, CFR1); in stv090x_optimize_track()
2960 reg = STV090x_READ_DEMOD(state, TMGOBS); in stv090x_optimize_track()
2962 if (state->algo == STV090x_BLIND_SEARCH) { in stv090x_optimize_track()
2963 STV090x_WRITE_DEMOD(state, SFRSTEP, 0x00); in stv090x_optimize_track()
2964 reg = STV090x_READ_DEMOD(state, DMDCFGMD); in stv090x_optimize_track()
2967 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) in stv090x_optimize_track()
2969 if (STV090x_WRITE_DEMOD(state, TMGCFG2, 0xc1) < 0) in stv090x_optimize_track()
2972 if (stv090x_set_srate(state, srate) < 0) in stv090x_optimize_track()
2976 if (stv090x_dvbs_track_crl(state) < 0) in stv090x_optimize_track()
2980 if (state->internal->dev_ver >= 0x20) { in stv090x_optimize_track()
2981 if ((state->search_mode == STV090x_SEARCH_DVBS1) || in stv090x_optimize_track()
2982 (state->search_mode == STV090x_SEARCH_DSS) || in stv090x_optimize_track()
2983 (state->search_mode == STV090x_SEARCH_AUTO)) { in stv090x_optimize_track()
2985 if (STV090x_WRITE_DEMOD(state, VAVSRVIT, 0x0a) < 0) in stv090x_optimize_track()
2987 if (STV090x_WRITE_DEMOD(state, VITSCALE, 0x00) < 0) in stv090x_optimize_track()
2992 if (STV090x_WRITE_DEMOD(state, AGC2REF, 0x38) < 0) in stv090x_optimize_track()
2996 if (STV090x_WRITE_DEMOD(state, SFRUP1, 0x80) < 0) in stv090x_optimize_track()
2999 if (STV090x_WRITE_DEMOD(state, SFRLOW1, 0x80) < 0) in stv090x_optimize_track()
3002 if ((state->internal->dev_ver >= 0x20) || (blind_tune == 1) || in stv090x_optimize_track()
3003 (state->srate < 10000000)) { in stv090x_optimize_track()
3005 if (STV090x_WRITE_DEMOD(state, CFRINIT1, f_1) < 0) in stv090x_optimize_track()
3007 if (STV090x_WRITE_DEMOD(state, CFRINIT0, f_0) < 0) in stv090x_optimize_track()
3009 state->tuner_bw = stv090x_car_width(srate, state->rolloff) + 10000000; in stv090x_optimize_track()
3011 if ((state->internal->dev_ver >= 0x20) || (blind_tune == 1)) { in stv090x_optimize_track()
3013 if (state->algo != STV090x_WARM_SEARCH) { in stv090x_optimize_track()
3015 if (stv090x_i2c_gate_ctrl(state, 1) < 0) in stv090x_optimize_track()
3018 if (state->config->tuner_set_bandwidth) { in stv090x_optimize_track()
3019 if (state->config->tuner_set_bandwidth(fe, state->tuner_bw) < 0) in stv090x_optimize_track()
3023 if (stv090x_i2c_gate_ctrl(state, 0) < 0) in stv090x_optimize_track()
3028 if ((state->algo == STV090x_BLIND_SEARCH) || (state->srate < 10000000)) in stv090x_optimize_track()
3033 stv090x_get_lock_tmg(state); in stv090x_optimize_track()
3035 if (!(stv090x_get_dmdlock(state, (state->DemodTimeout / 2)))) { in stv090x_optimize_track()
3036 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x1f) < 0) in stv090x_optimize_track()
3038 if (STV090x_WRITE_DEMOD(state, CFRINIT1, f_1) < 0) in stv090x_optimize_track()
3040 if (STV090x_WRITE_DEMOD(state, CFRINIT0, f_0) < 0) in stv090x_optimize_track()
3042 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x18) < 0) in stv090x_optimize_track()
3047 while ((!(stv090x_get_dmdlock(state, (state->DemodTimeout / 2)))) && (i <= 2)) { in stv090x_optimize_track()
3049 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x1f) < 0) in stv090x_optimize_track()
3051 if (STV090x_WRITE_DEMOD(state, CFRINIT1, f_1) < 0) in stv090x_optimize_track()
3053 if (STV090x_WRITE_DEMOD(state, CFRINIT0, f_0) < 0) in stv090x_optimize_track()
3055 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x18) < 0) in stv090x_optimize_track()
3063 if (state->internal->dev_ver >= 0x20) { in stv090x_optimize_track()
3064 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x49) < 0) in stv090x_optimize_track()
3068 if ((state->delsys == STV090x_DVBS1) || (state->delsys == STV090x_DSS)) in stv090x_optimize_track()
3069 stv090x_set_vit_thtracq(state); in stv090x_optimize_track()
3074 stv090x_i2c_gate_ctrl(state, 0); in stv090x_optimize_track()
3080 static int stv090x_get_feclock(struct stv090x_state *state, s32 timeout) in stv090x_get_feclock() argument
3086 reg = STV090x_READ_DEMOD(state, DMDSTATE); in stv090x_get_feclock()
3097 reg = STV090x_READ_DEMOD(state, PDELSTATUS1); in stv090x_get_feclock()
3102 reg = STV090x_READ_DEMOD(state, VSTATUSVIT); in stv090x_get_feclock()
3114 static int stv090x_get_lock(struct stv090x_state *state, s32 timeout_dmd, s32 timeout_fec) in stv090x_get_lock() argument
3120 lock = stv090x_get_dmdlock(state, timeout_dmd); in stv090x_get_lock()
3122 lock = stv090x_get_feclock(state, timeout_fec); in stv090x_get_lock()
3128 reg = STV090x_READ_DEMOD(state, TSSTATUS); in stv090x_get_lock()
3138 static int stv090x_set_s2rolloff(struct stv090x_state *state) in stv090x_set_s2rolloff() argument
3142 if (state->internal->dev_ver <= 0x20) { in stv090x_set_s2rolloff()
3144 reg = STV090x_READ_DEMOD(state, DEMOD); in stv090x_set_s2rolloff()
3146 if (STV090x_WRITE_DEMOD(state, DEMOD, reg) < 0) in stv090x_set_s2rolloff()
3150 reg = STV090x_READ_DEMOD(state, DEMOD); in stv090x_set_s2rolloff()
3152 if (STV090x_WRITE_DEMOD(state, DEMOD, reg) < 0) in stv090x_set_s2rolloff()
3162 static enum stv090x_signal_state stv090x_algo(struct stv090x_state *state) in stv090x_algo() argument
3164 struct dvb_frontend *fe = &state->frontend; in stv090x_algo()
3170 reg = STV090x_READ_DEMOD(state, TSCFGH); in stv090x_algo()
3172 if (STV090x_WRITE_DEMOD(state, TSCFGH, reg) < 0) in stv090x_algo()
3175 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x5c) < 0) /* Demod stop */ in stv090x_algo()
3178 if (state->internal->dev_ver >= 0x20) { in stv090x_algo()
3179 if (state->srate > 5000000) { in stv090x_algo()
3180 if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x9e) < 0) in stv090x_algo()
3183 if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x82) < 0) in stv090x_algo()
3188 stv090x_get_lock_tmg(state); in stv090x_algo()
3190 if (state->algo == STV090x_BLIND_SEARCH) { in stv090x_algo()
3191 state->tuner_bw = 2 * 36000000; /* wide bw for unknown srate */ in stv090x_algo()
3192 if (STV090x_WRITE_DEMOD(state, TMGCFG2, 0xc0) < 0) /* wider srate scan */ in stv090x_algo()
3194 if (STV090x_WRITE_DEMOD(state, CORRELMANT, 0x70) < 0) in stv090x_algo()
3196 if (stv090x_set_srate(state, 1000000) < 0) /* initial srate = 1Msps */ in stv090x_algo()
3200 if (STV090x_WRITE_DEMOD(state, DMDTOM, 0x20) < 0) in stv090x_algo()
3202 if (STV090x_WRITE_DEMOD(state, TMGCFG, 0xd2) < 0) in stv090x_algo()
3205 if (state->srate < 2000000) { in stv090x_algo()
3207 if (STV090x_WRITE_DEMOD(state, CORRELMANT, 0x63) < 0) in stv090x_algo()
3211 if (STV090x_WRITE_DEMOD(state, CORRELMANT, 0x70) < 0) in stv090x_algo()
3215 if (STV090x_WRITE_DEMOD(state, AGC2REF, 0x38) < 0) in stv090x_algo()
3218 if (state->internal->dev_ver >= 0x20) { in stv090x_algo()
3219 if (STV090x_WRITE_DEMOD(state, KREFTMG, 0x5a) < 0) in stv090x_algo()
3221 if (state->algo == STV090x_COLD_SEARCH) in stv090x_algo()
3222 state->tuner_bw = (15 * (stv090x_car_width(state->srate, state->rolloff) + 10000000)) / 10; in stv090x_algo()
3223 else if (state->algo == STV090x_WARM_SEARCH) in stv090x_algo()
3224 state->tuner_bw = stv090x_car_width(state->srate, state->rolloff) + 10000000; in stv090x_algo()
3230 if (STV090x_WRITE_DEMOD(state, TMGCFG2, 0xc1) < 0) /* narrow srate scan */ in stv090x_algo()
3233 if (stv090x_set_srate(state, state->srate) < 0) in stv090x_algo()
3236 if (stv090x_set_max_srate(state, state->internal->mclk, in stv090x_algo()
3237 state->srate) < 0) in stv090x_algo()
3239 if (stv090x_set_min_srate(state, state->internal->mclk, in stv090x_algo()
3240 state->srate) < 0) in stv090x_algo()
3243 if (state->srate >= 10000000) in stv090x_algo()
3250 if (stv090x_i2c_gate_ctrl(state, 1) < 0) in stv090x_algo()
3253 if (state->config->tuner_set_bbgain) { in stv090x_algo()
3254 reg = state->config->tuner_bbgain; in stv090x_algo()
3257 if (state->config->tuner_set_bbgain(fe, reg) < 0) in stv090x_algo()
3261 if (state->config->tuner_set_frequency) { in stv090x_algo()
3262 if (state->config->tuner_set_frequency(fe, state->frequency) < 0) in stv090x_algo()
3266 if (state->config->tuner_set_bandwidth) { in stv090x_algo()
3267 if (state->config->tuner_set_bandwidth(fe, state->tuner_bw) < 0) in stv090x_algo()
3271 if (stv090x_i2c_gate_ctrl(state, 0) < 0) in stv090x_algo()
3276 if (state->config->tuner_get_status) { in stv090x_algo()
3277 if (stv090x_i2c_gate_ctrl(state, 1) < 0) in stv090x_algo()
3279 if (state->config->tuner_get_status(fe, &reg) < 0) in stv090x_algo()
3281 if (stv090x_i2c_gate_ctrl(state, 0) < 0) in stv090x_algo()
3293 agc1_power = MAKEWORD16(STV090x_READ_DEMOD(state, AGCIQIN1), in stv090x_algo()
3294 STV090x_READ_DEMOD(state, AGCIQIN0)); in stv090x_algo()
3301 power_iq += (STV090x_READ_DEMOD(state, POWERI) + in stv090x_algo()
3302 STV090x_READ_DEMOD(state, POWERQ)) >> 1; in stv090x_algo()
3312 reg = STV090x_READ_DEMOD(state, DEMOD); in stv090x_algo()
3313 STV090x_SETFIELD_Px(reg, SPECINV_CONTROL_FIELD, state->inversion); in stv090x_algo()
3315 if (state->internal->dev_ver <= 0x20) { in stv090x_algo()
3322 if (STV090x_WRITE_DEMOD(state, DEMOD, reg) < 0) in stv090x_algo()
3325 if (stv090x_delivery_search(state) < 0) in stv090x_algo()
3328 if (state->algo != STV090x_BLIND_SEARCH) { in stv090x_algo()
3329 if (stv090x_start_search(state) < 0) in stv090x_algo()
3337 if (state->algo == STV090x_BLIND_SEARCH) in stv090x_algo()
3338 lock = stv090x_blind_search(state); in stv090x_algo()
3340 else if (state->algo == STV090x_COLD_SEARCH) in stv090x_algo()
3341 lock = stv090x_get_coldlock(state, state->DemodTimeout); in stv090x_algo()
3343 else if (state->algo == STV090x_WARM_SEARCH) in stv090x_algo()
3344 lock = stv090x_get_dmdlock(state, state->DemodTimeout); in stv090x_algo()
3346 if ((!lock) && (state->algo == STV090x_COLD_SEARCH)) { in stv090x_algo()
3348 if (stv090x_chk_tmg(state)) in stv090x_algo()
3349 lock = stv090x_sw_algo(state); in stv090x_algo()
3354 signal_state = stv090x_get_sig_params(state); in stv090x_algo()
3357 stv090x_optimize_track(state); in stv090x_algo()
3359 if (state->internal->dev_ver >= 0x20) { in stv090x_algo()
3363 reg = STV090x_READ_DEMOD(state, TSCFGH); in stv090x_algo()
3365 if (STV090x_WRITE_DEMOD(state, TSCFGH, reg) < 0) in stv090x_algo()
3371 if (STV090x_WRITE_DEMOD(state, TSCFGH, reg) < 0) in stv090x_algo()
3375 if (STV090x_WRITE_DEMOD(state, TSCFGH, reg) < 0) in stv090x_algo()
3379 lock = stv090x_get_lock(state, state->FecTimeout, in stv090x_algo()
3380 state->FecTimeout); in stv090x_algo()
3382 if (state->delsys == STV090x_DVBS2) { in stv090x_algo()
3383 stv090x_set_s2rolloff(state); in stv090x_algo()
3385 reg = STV090x_READ_DEMOD(state, PDELCTRL2); in stv090x_algo()
3387 if (STV090x_WRITE_DEMOD(state, PDELCTRL2, reg) < 0) 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 if (STV090x_WRITE_DEMOD(state, ERRCTRL1, 0x67) < 0) /* PER */ in stv090x_algo()
3398 if (STV090x_WRITE_DEMOD(state, ERRCTRL1, 0x75) < 0) in stv090x_algo()
3402 if (STV090x_WRITE_DEMOD(state, FBERCPT4, 0x00) < 0) in stv090x_algo()
3405 if (STV090x_WRITE_DEMOD(state, ERRCTRL2, 0xc1) < 0) in stv090x_algo()
3409 stv090x_chk_signal(state); in stv090x_algo()
3415 stv090x_i2c_gate_ctrl(state, 0); in stv090x_algo()
3421 static int stv090x_set_pls(struct stv090x_state *state, u32 pls_code) in stv090x_set_pls() argument
3424 if (STV090x_WRITE_DEMOD(state, PLROOT0, pls_code & 0xff) < 0) in stv090x_set_pls()
3426 if (STV090x_WRITE_DEMOD(state, PLROOT1, (pls_code >> 8) & 0xff) < 0) in stv090x_set_pls()
3428 if (STV090x_WRITE_DEMOD(state, PLROOT2, 0x04 | (pls_code >> 16)) < 0) in stv090x_set_pls()
3436 static int stv090x_set_mis(struct stv090x_state *state, int mis) in stv090x_set_mis() argument
3442 reg = STV090x_READ_DEMOD(state, PDELCTRL1); in stv090x_set_mis()
3444 if (STV090x_WRITE_DEMOD(state, PDELCTRL1, reg) < 0) in stv090x_set_mis()
3448 reg = STV090x_READ_DEMOD(state, PDELCTRL1); in stv090x_set_mis()
3450 if (STV090x_WRITE_DEMOD(state, PDELCTRL1, reg) < 0) in stv090x_set_mis()
3452 if (STV090x_WRITE_DEMOD(state, ISIENTRY, mis) < 0) in stv090x_set_mis()
3454 if (STV090x_WRITE_DEMOD(state, ISIBITENA, 0xff) < 0) in stv090x_set_mis()
3465 struct stv090x_state *state = fe->demodulator_priv; in stv090x_search() local
3473 state->delsys = STV090x_DSS; in stv090x_search()
3476 state->delsys = STV090x_DVBS1; in stv090x_search()
3479 state->delsys = STV090x_DVBS2; in stv090x_search()
3485 state->frequency = props->frequency; in stv090x_search()
3486 state->srate = props->symbol_rate; in stv090x_search()
3487 state->search_mode = STV090x_SEARCH_AUTO; in stv090x_search()
3488 state->algo = STV090x_COLD_SEARCH; in stv090x_search()
3489 state->fec = STV090x_PRERR; in stv090x_search()
3490 if (state->srate > 10000000) { in stv090x_search()
3492 state->search_range = 10000000; in stv090x_search()
3495 state->search_range = 5000000; in stv090x_search()
3498 stv090x_set_pls(state, props->scrambling_sequence_index); in stv090x_search()
3499 stv090x_set_mis(state, props->stream_id); in stv090x_search()
3501 if (stv090x_algo(state) == STV090x_RANGEOK) { in stv090x_search()
3514 struct stv090x_state *state = fe->demodulator_priv; in stv090x_read_status() local
3520 dstatus = STV090x_READ_DEMOD(state, DSTATUS); in stv090x_read_status()
3524 reg = STV090x_READ_DEMOD(state, DMDSTATE); in stv090x_read_status()
3537 reg = STV090x_READ_DEMOD(state, PDELSTATUS1); in stv090x_read_status()
3540 reg = STV090x_READ_DEMOD(state, TSSTATUS); in stv090x_read_status()
3550 reg = STV090x_READ_DEMOD(state, VSTATUSVIT); in stv090x_read_status()
3553 reg = STV090x_READ_DEMOD(state, TSSTATUS); in stv090x_read_status()
3566 struct stv090x_state *state = fe->demodulator_priv; in stv090x_read_per() local
3577 reg = STV090x_READ_DEMOD(state, ERRCNT22); in stv090x_read_per()
3580 reg = STV090x_READ_DEMOD(state, ERRCNT21); in stv090x_read_per()
3583 reg = STV090x_READ_DEMOD(state, ERRCNT20); in stv090x_read_per()
3588 count_4 = STV090x_READ_DEMOD(state, FBERCPT4); in stv090x_read_per()
3589 count_3 = STV090x_READ_DEMOD(state, FBERCPT3); in stv090x_read_per()
3590 count_2 = STV090x_READ_DEMOD(state, FBERCPT2); in stv090x_read_per()
3591 count_1 = STV090x_READ_DEMOD(state, FBERCPT1); in stv090x_read_per()
3592 count_0 = STV090x_READ_DEMOD(state, FBERCPT0); in stv090x_read_per()
3604 if (STV090x_WRITE_DEMOD(state, FBERCPT4, 0) < 0) in stv090x_read_per()
3606 if (STV090x_WRITE_DEMOD(state, ERRCTRL2, 0xc1) < 0) in stv090x_read_per()
3653 struct stv090x_state *state = fe->demodulator_priv; in stv090x_read_signal_strength() local
3658 reg = STV090x_READ_DEMOD(state, AGCIQIN1); in stv090x_read_signal_strength()
3660 reg = STV090x_READ_DEMOD(state, AGCIQIN0); in stv090x_read_signal_strength()
3677 struct stv090x_state *state = fe->demodulator_priv; in stv090x_read_cnr() local
3684 switch (state->delsys) { in stv090x_read_cnr()
3686 reg = STV090x_READ_DEMOD(state, DSTATUS); in stv090x_read_cnr()
3691 reg_1 = STV090x_READ_DEMOD(state, NNOSPLHT1); in stv090x_read_cnr()
3693 reg_0 = STV090x_READ_DEMOD(state, NNOSPLHT0); in stv090x_read_cnr()
3711 reg = STV090x_READ_DEMOD(state, DSTATUS); in stv090x_read_cnr()
3716 reg_1 = STV090x_READ_DEMOD(state, NOSDATAT1); in stv090x_read_cnr()
3718 reg_0 = STV090x_READ_DEMOD(state, NOSDATAT0); in stv090x_read_cnr()
3740 struct stv090x_state *state = fe->demodulator_priv; in stv090x_set_tone() local
3743 reg = STV090x_READ_DEMOD(state, DISTXCTL); in stv090x_set_tone()
3748 if (STV090x_WRITE_DEMOD(state, DISTXCTL, reg) < 0) in stv090x_set_tone()
3751 if (STV090x_WRITE_DEMOD(state, DISTXCTL, reg) < 0) in stv090x_set_tone()
3758 if (STV090x_WRITE_DEMOD(state, DISTXCTL, reg) < 0) in stv090x_set_tone()
3779 struct stv090x_state *state = fe->demodulator_priv; in stv090x_send_diseqc_msg() local
3783 reg = STV090x_READ_DEMOD(state, DISTXCTL); in stv090x_send_diseqc_msg()
3786 (state->config->diseqc_envelope_mode) ? 4 : 2); in stv090x_send_diseqc_msg()
3788 if (STV090x_WRITE_DEMOD(state, DISTXCTL, reg) < 0) in stv090x_send_diseqc_msg()
3791 if (STV090x_WRITE_DEMOD(state, DISTXCTL, reg) < 0) in stv090x_send_diseqc_msg()
3795 if (STV090x_WRITE_DEMOD(state, DISTXCTL, reg) < 0) in stv090x_send_diseqc_msg()
3801 reg = STV090x_READ_DEMOD(state, DISTXSTATUS); in stv090x_send_diseqc_msg()
3805 if (STV090x_WRITE_DEMOD(state, DISTXDATA, cmd->msg[i]) < 0) in stv090x_send_diseqc_msg()
3808 reg = STV090x_READ_DEMOD(state, DISTXCTL); in stv090x_send_diseqc_msg()
3810 if (STV090x_WRITE_DEMOD(state, DISTXCTL, reg) < 0) in stv090x_send_diseqc_msg()
3816 reg = STV090x_READ_DEMOD(state, DISTXSTATUS); in stv090x_send_diseqc_msg()
3831 struct stv090x_state *state = fe->demodulator_priv; in stv090x_send_diseqc_burst() local
3836 reg = STV090x_READ_DEMOD(state, DISTXCTL); in stv090x_send_diseqc_burst()
3839 mode = (state->config->diseqc_envelope_mode) ? 5 : 3; in stv090x_send_diseqc_burst()
3842 mode = (state->config->diseqc_envelope_mode) ? 4 : 2; in stv090x_send_diseqc_burst()
3848 if (STV090x_WRITE_DEMOD(state, DISTXCTL, reg) < 0) in stv090x_send_diseqc_burst()
3851 if (STV090x_WRITE_DEMOD(state, DISTXCTL, reg) < 0) in stv090x_send_diseqc_burst()
3855 if (STV090x_WRITE_DEMOD(state, DISTXCTL, reg) < 0) in stv090x_send_diseqc_burst()
3859 reg = STV090x_READ_DEMOD(state, DISTXSTATUS); in stv090x_send_diseqc_burst()
3863 if (STV090x_WRITE_DEMOD(state, DISTXDATA, value) < 0) in stv090x_send_diseqc_burst()
3866 reg = STV090x_READ_DEMOD(state, DISTXCTL); in stv090x_send_diseqc_burst()
3868 if (STV090x_WRITE_DEMOD(state, DISTXCTL, reg) < 0) in stv090x_send_diseqc_burst()
3874 reg = STV090x_READ_DEMOD(state, DISTXSTATUS); in stv090x_send_diseqc_burst()
3888 struct stv090x_state *state = fe->demodulator_priv; in stv090x_recv_slave_reply() local
3894 reg = STV090x_READ_DEMOD(state, DISRX_ST0); in stv090x_recv_slave_reply()
3901 reply->msg[i] = STV090x_READ_DEMOD(state, DISRXDATA); in stv090x_recv_slave_reply()
3909 struct stv090x_state *state = fe->demodulator_priv; in stv090x_sleep() local
3913 if (stv090x_i2c_gate_ctrl(state, 1) < 0) in stv090x_sleep()
3916 if (state->config->tuner_sleep) { in stv090x_sleep()
3917 if (state->config->tuner_sleep(fe) < 0) in stv090x_sleep()
3921 if (stv090x_i2c_gate_ctrl(state, 0) < 0) in stv090x_sleep()
3925 state->device == STV0900 ? "STV0900" : "STV0903", in stv090x_sleep()
3926 state->demod); in stv090x_sleep()
3928 mutex_lock(&state->internal->demod_lock); in stv090x_sleep()
3930 switch (state->demod) { in stv090x_sleep()
3933 reg = stv090x_read_reg(state, STV090x_TSTTNR1); in stv090x_sleep()
3935 if (stv090x_write_reg(state, STV090x_TSTTNR1, reg) < 0) in stv090x_sleep()
3938 reg = stv090x_read_reg(state, STV090x_TSTTNR2); in stv090x_sleep()
3940 if (stv090x_write_reg(state, STV090x_TSTTNR2, reg) < 0) in stv090x_sleep()
3945 reg = stv090x_read_reg(state, STV090x_TSTTNR3); in stv090x_sleep()
3950 reg = stv090x_read_reg(state, STV090x_STOPCLK1); in stv090x_sleep()
3959 if (stv090x_write_reg(state, STV090x_STOPCLK1, reg) < 0) in stv090x_sleep()
3961 reg = stv090x_read_reg(state, STV090x_STOPCLK2); in stv090x_sleep()
3970 if (stv090x_write_reg(state, STV090x_STOPCLK2, reg) < 0) in stv090x_sleep()
3976 reg = stv090x_read_reg(state, STV090x_TSTTNR3); in stv090x_sleep()
3978 if (stv090x_write_reg(state, STV090x_TSTTNR3, reg) < 0) in stv090x_sleep()
3981 reg = stv090x_read_reg(state, STV090x_TSTTNR4); in stv090x_sleep()
3983 if (stv090x_write_reg(state, STV090x_TSTTNR4, reg) < 0) in stv090x_sleep()
3988 reg = stv090x_read_reg(state, STV090x_TSTTNR1); in stv090x_sleep()
3993 reg = stv090x_read_reg(state, STV090x_STOPCLK1); in stv090x_sleep()
4002 if (stv090x_write_reg(state, STV090x_STOPCLK1, reg) < 0) in stv090x_sleep()
4004 reg = stv090x_read_reg(state, STV090x_STOPCLK2); in stv090x_sleep()
4013 if (stv090x_write_reg(state, STV090x_STOPCLK2, reg) < 0) in stv090x_sleep()
4024 reg = stv090x_read_reg(state, STV090x_SYNTCTRL); in stv090x_sleep()
4026 if (stv090x_write_reg(state, STV090x_SYNTCTRL, reg) < 0) in stv090x_sleep()
4030 mutex_unlock(&state->internal->demod_lock); in stv090x_sleep()
4034 stv090x_i2c_gate_ctrl(state, 0); in stv090x_sleep()
4037 mutex_unlock(&state->internal->demod_lock); in stv090x_sleep()
4045 struct stv090x_state *state = fe->demodulator_priv; in stv090x_wakeup() local
4049 state->device == STV0900 ? "STV0900" : "STV0903", in stv090x_wakeup()
4050 state->demod); in stv090x_wakeup()
4052 mutex_lock(&state->internal->demod_lock); in stv090x_wakeup()
4055 reg = stv090x_read_reg(state, STV090x_SYNTCTRL); in stv090x_wakeup()
4057 if (stv090x_write_reg(state, STV090x_SYNTCTRL, reg) < 0) in stv090x_wakeup()
4060 switch (state->demod) { in stv090x_wakeup()
4063 reg = stv090x_read_reg(state, STV090x_TSTTNR1); in stv090x_wakeup()
4065 if (stv090x_write_reg(state, STV090x_TSTTNR1, reg) < 0) in stv090x_wakeup()
4068 reg = stv090x_read_reg(state, STV090x_TSTTNR2); in stv090x_wakeup()
4070 if (stv090x_write_reg(state, STV090x_TSTTNR2, reg) < 0) in stv090x_wakeup()
4074 reg = stv090x_read_reg(state, STV090x_STOPCLK1); in stv090x_wakeup()
4081 if (stv090x_write_reg(state, STV090x_STOPCLK1, reg) < 0) in stv090x_wakeup()
4083 reg = stv090x_read_reg(state, STV090x_STOPCLK2); in stv090x_wakeup()
4090 if (stv090x_write_reg(state, STV090x_STOPCLK2, reg) < 0) in stv090x_wakeup()
4096 reg = stv090x_read_reg(state, STV090x_TSTTNR3); in stv090x_wakeup()
4098 if (stv090x_write_reg(state, STV090x_TSTTNR3, reg) < 0) in stv090x_wakeup()
4101 reg = stv090x_read_reg(state, STV090x_TSTTNR4); in stv090x_wakeup()
4103 if (stv090x_write_reg(state, STV090x_TSTTNR4, reg) < 0) in stv090x_wakeup()
4107 reg = stv090x_read_reg(state, STV090x_STOPCLK1); in stv090x_wakeup()
4114 if (stv090x_write_reg(state, STV090x_STOPCLK1, reg) < 0) in stv090x_wakeup()
4116 reg = stv090x_read_reg(state, STV090x_STOPCLK2); in stv090x_wakeup()
4123 if (stv090x_write_reg(state, STV090x_STOPCLK2, reg) < 0) in stv090x_wakeup()
4132 mutex_unlock(&state->internal->demod_lock); in stv090x_wakeup()
4135 mutex_unlock(&state->internal->demod_lock); in stv090x_wakeup()
4142 struct stv090x_state *state = fe->demodulator_priv; in stv090x_release() local
4144 state->internal->num_used--; in stv090x_release()
4145 if (state->internal->num_used <= 0) { in stv090x_release()
4149 remove_dev(state->internal); in stv090x_release()
4150 kfree(state->internal); in stv090x_release()
4153 kfree(state); in stv090x_release()
4156 static int stv090x_ldpc_mode(struct stv090x_state *state, enum stv090x_mode ldpc_mode) in stv090x_ldpc_mode() argument
4160 reg = stv090x_read_reg(state, STV090x_GENCFG); in stv090x_ldpc_mode()
4165 if ((state->demod_mode != STV090x_DUAL) || (STV090x_GETFIELD(reg, DDEMOD_FIELD) != 1)) { in stv090x_ldpc_mode()
4167 if (stv090x_write_reg(state, STV090x_GENCFG, 0x1d) < 0) in stv090x_ldpc_mode()
4170 state->demod_mode = STV090x_DUAL; in stv090x_ldpc_mode()
4172 reg = stv090x_read_reg(state, STV090x_TSTRES0); in stv090x_ldpc_mode()
4174 if (stv090x_write_reg(state, STV090x_TSTRES0, reg) < 0) in stv090x_ldpc_mode()
4177 if (stv090x_write_reg(state, STV090x_TSTRES0, reg) < 0) in stv090x_ldpc_mode()
4180 if (STV090x_WRITE_DEMOD(state, MODCODLST0, 0xff) < 0) in stv090x_ldpc_mode()
4182 if (STV090x_WRITE_DEMOD(state, MODCODLST1, 0xff) < 0) in stv090x_ldpc_mode()
4184 if (STV090x_WRITE_DEMOD(state, MODCODLST2, 0xff) < 0) in stv090x_ldpc_mode()
4186 if (STV090x_WRITE_DEMOD(state, MODCODLST3, 0xff) < 0) in stv090x_ldpc_mode()
4188 if (STV090x_WRITE_DEMOD(state, MODCODLST4, 0xff) < 0) in stv090x_ldpc_mode()
4190 if (STV090x_WRITE_DEMOD(state, MODCODLST5, 0xff) < 0) in stv090x_ldpc_mode()
4192 if (STV090x_WRITE_DEMOD(state, MODCODLST6, 0xff) < 0) in stv090x_ldpc_mode()
4195 if (STV090x_WRITE_DEMOD(state, MODCODLST7, 0xcc) < 0) in stv090x_ldpc_mode()
4197 if (STV090x_WRITE_DEMOD(state, MODCODLST8, 0xcc) < 0) in stv090x_ldpc_mode()
4199 if (STV090x_WRITE_DEMOD(state, MODCODLST9, 0xcc) < 0) in stv090x_ldpc_mode()
4201 if (STV090x_WRITE_DEMOD(state, MODCODLSTA, 0xcc) < 0) in stv090x_ldpc_mode()
4203 if (STV090x_WRITE_DEMOD(state, MODCODLSTB, 0xcc) < 0) in stv090x_ldpc_mode()
4205 if (STV090x_WRITE_DEMOD(state, MODCODLSTC, 0xcc) < 0) in stv090x_ldpc_mode()
4207 if (STV090x_WRITE_DEMOD(state, MODCODLSTD, 0xcc) < 0) in stv090x_ldpc_mode()
4210 if (STV090x_WRITE_DEMOD(state, MODCODLSTE, 0xff) < 0) in stv090x_ldpc_mode()
4212 if (STV090x_WRITE_DEMOD(state, MODCODLSTF, 0xcf) < 0) in stv090x_ldpc_mode()
4218 if (stv090x_stop_modcod(state) < 0) in stv090x_ldpc_mode()
4220 if (stv090x_activate_modcod_single(state) < 0) in stv090x_ldpc_mode()
4223 if (state->demod == STV090x_DEMODULATOR_1) { in stv090x_ldpc_mode()
4224 if (stv090x_write_reg(state, STV090x_GENCFG, 0x06) < 0) /* path 2 */ in stv090x_ldpc_mode()
4227 if (stv090x_write_reg(state, STV090x_GENCFG, 0x04) < 0) /* path 1 */ in stv090x_ldpc_mode()
4231 reg = stv090x_read_reg(state, STV090x_TSTRES0); in stv090x_ldpc_mode()
4233 if (stv090x_write_reg(state, STV090x_TSTRES0, reg) < 0) in stv090x_ldpc_mode()
4236 if (stv090x_write_reg(state, STV090x_TSTRES0, reg) < 0) in stv090x_ldpc_mode()
4239 reg = STV090x_READ_DEMOD(state, PDELCTRL1); in stv090x_ldpc_mode()
4241 if (STV090x_WRITE_DEMOD(state, PDELCTRL1, reg) < 0) in stv090x_ldpc_mode()
4244 if (STV090x_WRITE_DEMOD(state, PDELCTRL1, reg) < 0) in stv090x_ldpc_mode()
4256 static u32 stv090x_get_mclk(struct stv090x_state *state) in stv090x_get_mclk() argument
4258 const struct stv090x_config *config = state->config; in stv090x_get_mclk()
4262 div = stv090x_read_reg(state, STV090x_NCOARSE); in stv090x_get_mclk()
4263 reg = stv090x_read_reg(state, STV090x_SYNTCTRL); in stv090x_get_mclk()
4269 static int stv090x_set_mclk(struct stv090x_state *state, u32 mclk, u32 clk) in stv090x_set_mclk() argument
4271 const struct stv090x_config *config = state->config; in stv090x_set_mclk()
4274 reg = stv090x_read_reg(state, STV090x_SYNTCTRL); in stv090x_set_mclk()
4279 reg = stv090x_read_reg(state, STV090x_NCOARSE); in stv090x_set_mclk()
4281 if (stv090x_write_reg(state, STV090x_NCOARSE, reg) < 0) in stv090x_set_mclk()
4284 state->internal->mclk = stv090x_get_mclk(state); in stv090x_set_mclk()
4287 div = state->internal->mclk / 704000; in stv090x_set_mclk()
4288 if (STV090x_WRITE_DEMOD(state, F22TX, div) < 0) in stv090x_set_mclk()
4290 if (STV090x_WRITE_DEMOD(state, F22RX, div) < 0) in stv090x_set_mclk()
4299 static int stv0900_set_tspath(struct stv090x_state *state) in stv0900_set_tspath() argument
4303 if (state->internal->dev_ver >= 0x20) { in stv0900_set_tspath()
4304 switch (state->config->ts1_mode) { in stv0900_set_tspath()
4307 switch (state->config->ts2_mode) { in stv0900_set_tspath()
4311 stv090x_write_reg(state, STV090x_TSGENERAL, 0x00); in stv0900_set_tspath()
4316 if (stv090x_write_reg(state, STV090x_TSGENERAL, 0x06) < 0) /* Mux'd stream mode */ in stv0900_set_tspath()
4318 reg = stv090x_read_reg(state, STV090x_P1_TSCFGM); in stv0900_set_tspath()
4320 if (stv090x_write_reg(state, STV090x_P1_TSCFGM, reg) < 0) in stv0900_set_tspath()
4322 reg = stv090x_read_reg(state, STV090x_P2_TSCFGM); in stv0900_set_tspath()
4324 if (stv090x_write_reg(state, STV090x_P2_TSCFGM, reg) < 0) in stv0900_set_tspath()
4326 if (stv090x_write_reg(state, STV090x_P1_TSSPEED, 0x14) < 0) in stv0900_set_tspath()
4328 if (stv090x_write_reg(state, STV090x_P2_TSSPEED, 0x28) < 0) in stv0900_set_tspath()
4337 switch (state->config->ts2_mode) { in stv0900_set_tspath()
4341 if (stv090x_write_reg(state, STV090x_TSGENERAL, 0x0c) < 0) in stv0900_set_tspath()
4347 if (stv090x_write_reg(state, STV090x_TSGENERAL, 0x0a) < 0) in stv0900_set_tspath()
4354 switch (state->config->ts1_mode) { in stv0900_set_tspath()
4357 switch (state->config->ts2_mode) { in stv0900_set_tspath()
4361 stv090x_write_reg(state, STV090x_TSGENERAL1X, 0x10); in stv0900_set_tspath()
4366 stv090x_write_reg(state, STV090x_TSGENERAL1X, 0x16); in stv0900_set_tspath()
4367 reg = stv090x_read_reg(state, STV090x_P1_TSCFGM); in stv0900_set_tspath()
4369 if (stv090x_write_reg(state, STV090x_P1_TSCFGM, reg) < 0) in stv0900_set_tspath()
4371 reg = stv090x_read_reg(state, STV090x_P1_TSCFGM); in stv0900_set_tspath()
4373 if (stv090x_write_reg(state, STV090x_P1_TSCFGM, reg) < 0) in stv0900_set_tspath()
4375 if (stv090x_write_reg(state, STV090x_P1_TSSPEED, 0x14) < 0) in stv0900_set_tspath()
4377 if (stv090x_write_reg(state, STV090x_P2_TSSPEED, 0x28) < 0) in stv0900_set_tspath()
4386 switch (state->config->ts2_mode) { in stv0900_set_tspath()
4390 stv090x_write_reg(state, STV090x_TSGENERAL1X, 0x14); in stv0900_set_tspath()
4395 stv090x_write_reg(state, STV090x_TSGENERAL1X, 0x12); in stv0900_set_tspath()
4402 switch (state->config->ts1_mode) { in stv0900_set_tspath()
4404 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH); in stv0900_set_tspath()
4405 STV090x_SETFIELD_Px(reg, TSFIFO_TEIUPDATE_FIELD, state->config->ts1_tei); in stv0900_set_tspath()
4408 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0) in stv0900_set_tspath()
4413 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH); in stv0900_set_tspath()
4414 STV090x_SETFIELD_Px(reg, TSFIFO_TEIUPDATE_FIELD, state->config->ts1_tei); in stv0900_set_tspath()
4417 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0) in stv0900_set_tspath()
4422 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH); in stv0900_set_tspath()
4423 STV090x_SETFIELD_Px(reg, TSFIFO_TEIUPDATE_FIELD, state->config->ts1_tei); in stv0900_set_tspath()
4426 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0) in stv0900_set_tspath()
4431 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH); in stv0900_set_tspath()
4432 STV090x_SETFIELD_Px(reg, TSFIFO_TEIUPDATE_FIELD, state->config->ts1_tei); in stv0900_set_tspath()
4435 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0) in stv0900_set_tspath()
4443 switch (state->config->ts2_mode) { in stv0900_set_tspath()
4445 reg = stv090x_read_reg(state, STV090x_P2_TSCFGH); in stv0900_set_tspath()
4446 STV090x_SETFIELD_Px(reg, TSFIFO_TEIUPDATE_FIELD, state->config->ts2_tei); in stv0900_set_tspath()
4449 if (stv090x_write_reg(state, STV090x_P2_TSCFGH, reg) < 0) in stv0900_set_tspath()
4454 reg = stv090x_read_reg(state, STV090x_P2_TSCFGH); in stv0900_set_tspath()
4455 STV090x_SETFIELD_Px(reg, TSFIFO_TEIUPDATE_FIELD, state->config->ts2_tei); in stv0900_set_tspath()
4458 if (stv090x_write_reg(state, STV090x_P2_TSCFGH, reg) < 0) in stv0900_set_tspath()
4463 reg = stv090x_read_reg(state, STV090x_P2_TSCFGH); in stv0900_set_tspath()
4464 STV090x_SETFIELD_Px(reg, TSFIFO_TEIUPDATE_FIELD, state->config->ts2_tei); in stv0900_set_tspath()
4467 if (stv090x_write_reg(state, STV090x_P2_TSCFGH, reg) < 0) in stv0900_set_tspath()
4472 reg = stv090x_read_reg(state, STV090x_P2_TSCFGH); in stv0900_set_tspath()
4473 STV090x_SETFIELD_Px(reg, TSFIFO_TEIUPDATE_FIELD, state->config->ts2_tei); in stv0900_set_tspath()
4476 if (stv090x_write_reg(state, STV090x_P2_TSCFGH, reg) < 0) in stv0900_set_tspath()
4484 if (state->config->ts1_clk > 0) { in stv0900_set_tspath()
4487 switch (state->config->ts1_mode) { in stv0900_set_tspath()
4491 speed = state->internal->mclk / in stv0900_set_tspath()
4492 (state->config->ts1_clk / 4); in stv0900_set_tspath()
4500 speed = state->internal->mclk / in stv0900_set_tspath()
4501 (state->config->ts1_clk / 32); in stv0900_set_tspath()
4508 reg = stv090x_read_reg(state, STV090x_P1_TSCFGM); in stv0900_set_tspath()
4510 if (stv090x_write_reg(state, STV090x_P1_TSCFGM, reg) < 0) in stv0900_set_tspath()
4512 if (stv090x_write_reg(state, STV090x_P1_TSSPEED, speed) < 0) in stv0900_set_tspath()
4516 if (state->config->ts2_clk > 0) { in stv0900_set_tspath()
4519 switch (state->config->ts2_mode) { in stv0900_set_tspath()
4523 speed = state->internal->mclk / in stv0900_set_tspath()
4524 (state->config->ts2_clk / 4); in stv0900_set_tspath()
4532 speed = state->internal->mclk / in stv0900_set_tspath()
4533 (state->config->ts2_clk / 32); in stv0900_set_tspath()
4540 reg = stv090x_read_reg(state, STV090x_P2_TSCFGM); in stv0900_set_tspath()
4542 if (stv090x_write_reg(state, STV090x_P2_TSCFGM, reg) < 0) in stv0900_set_tspath()
4544 if (stv090x_write_reg(state, STV090x_P2_TSSPEED, speed) < 0) in stv0900_set_tspath()
4548 reg = stv090x_read_reg(state, STV090x_P2_TSCFGH); in stv0900_set_tspath()
4550 if (stv090x_write_reg(state, STV090x_P2_TSCFGH, reg) < 0) in stv0900_set_tspath()
4553 if (stv090x_write_reg(state, STV090x_P2_TSCFGH, reg) < 0) in stv0900_set_tspath()
4556 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH); in stv0900_set_tspath()
4558 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0) in stv0900_set_tspath()
4561 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0) in stv0900_set_tspath()
4570 static int stv0903_set_tspath(struct stv090x_state *state) in stv0903_set_tspath() argument
4574 if (state->internal->dev_ver >= 0x20) { in stv0903_set_tspath()
4575 switch (state->config->ts1_mode) { in stv0903_set_tspath()
4578 stv090x_write_reg(state, STV090x_TSGENERAL, 0x00); in stv0903_set_tspath()
4584 stv090x_write_reg(state, STV090x_TSGENERAL, 0x0c); in stv0903_set_tspath()
4588 switch (state->config->ts1_mode) { in stv0903_set_tspath()
4591 stv090x_write_reg(state, STV090x_TSGENERAL1X, 0x10); in stv0903_set_tspath()
4597 stv090x_write_reg(state, STV090x_TSGENERAL1X, 0x14); in stv0903_set_tspath()
4602 switch (state->config->ts1_mode) { in stv0903_set_tspath()
4604 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH); in stv0903_set_tspath()
4607 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0) in stv0903_set_tspath()
4612 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH); in stv0903_set_tspath()
4615 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0) in stv0903_set_tspath()
4620 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH); in stv0903_set_tspath()
4623 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0) in stv0903_set_tspath()
4628 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH); in stv0903_set_tspath()
4631 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0) in stv0903_set_tspath()
4639 if (state->config->ts1_clk > 0) { in stv0903_set_tspath()
4642 switch (state->config->ts1_mode) { in stv0903_set_tspath()
4646 speed = state->internal->mclk / in stv0903_set_tspath()
4647 (state->config->ts1_clk / 4); in stv0903_set_tspath()
4655 speed = state->internal->mclk / in stv0903_set_tspath()
4656 (state->config->ts1_clk / 32); in stv0903_set_tspath()
4663 reg = stv090x_read_reg(state, STV090x_P1_TSCFGM); in stv0903_set_tspath()
4665 if (stv090x_write_reg(state, STV090x_P1_TSCFGM, reg) < 0) in stv0903_set_tspath()
4667 if (stv090x_write_reg(state, STV090x_P1_TSSPEED, speed) < 0) in stv0903_set_tspath()
4671 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH); in stv0903_set_tspath()
4673 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0) in stv0903_set_tspath()
4676 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0) in stv0903_set_tspath()
4687 struct stv090x_state *state = fe->demodulator_priv; in stv090x_init() local
4688 const struct stv090x_config *config = state->config; in stv090x_init()
4691 if (state->internal->mclk == 0) { in stv090x_init()
4695 if (stv090x_i2c_gate_ctrl(state, 1) < 0) in stv090x_init()
4703 if (stv090x_i2c_gate_ctrl(state, 0) < 0) in stv090x_init()
4706 stv090x_set_mclk(state, 135000000, config->xtal); /* 135 Mhz */ in stv090x_init()
4708 if (stv090x_write_reg(state, STV090x_SYNTCTRL, in stv090x_init()
4711 stv090x_get_mclk(state); in stv090x_init()
4719 if (stv090x_ldpc_mode(state, state->demod_mode) < 0) in stv090x_init()
4722 reg = STV090x_READ_DEMOD(state, TNRCFG2); in stv090x_init()
4723 STV090x_SETFIELD_Px(reg, TUN_IQSWAP_FIELD, state->inversion); in stv090x_init()
4724 if (STV090x_WRITE_DEMOD(state, TNRCFG2, reg) < 0) in stv090x_init()
4726 reg = STV090x_READ_DEMOD(state, DEMOD); in stv090x_init()
4727 STV090x_SETFIELD_Px(reg, ROLLOFF_CONTROL_FIELD, state->rolloff); in stv090x_init()
4728 if (STV090x_WRITE_DEMOD(state, DEMOD, reg) < 0) in stv090x_init()
4731 if (stv090x_i2c_gate_ctrl(state, 1) < 0) in stv090x_init()
4744 if (stv090x_i2c_gate_ctrl(state, 0) < 0) in stv090x_init()
4747 if (state->device == STV0900) { in stv090x_init()
4748 if (stv0900_set_tspath(state) < 0) in stv090x_init()
4751 if (stv0903_set_tspath(state) < 0) in stv090x_init()
4758 stv090x_i2c_gate_ctrl(state, 0); in stv090x_init()
4766 struct stv090x_state *state = fe->demodulator_priv; in stv090x_setup() local
4767 const struct stv090x_config *config = state->config; in stv090x_setup()
4775 if (state->device == STV0900) { in stv090x_setup()
4781 } else if (state->device == STV0903) { in stv090x_setup()
4792 if (stv090x_write_reg(state, STV090x_P1_DMDISTATE, 0x5c) < 0) in stv090x_setup()
4794 if (state->device == STV0900) in stv090x_setup()
4795 if (stv090x_write_reg(state, STV090x_P2_DMDISTATE, 0x5c) < 0) in stv090x_setup()
4801 if (stv090x_write_reg(state, STV090x_P1_TNRCFG, 0x6c) < 0) in stv090x_setup()
4803 if (state->device == STV0900) in stv090x_setup()
4804 if (stv090x_write_reg(state, STV090x_P2_TNRCFG, 0x6c) < 0) in stv090x_setup()
4809 if (stv090x_write_reg(state, STV090x_P1_I2CRPT, reg) < 0) in stv090x_setup()
4811 if (state->device == STV0900) in stv090x_setup()
4812 if (stv090x_write_reg(state, STV090x_P2_I2CRPT, reg) < 0) in stv090x_setup()
4815 if (stv090x_write_reg(state, STV090x_NCOARSE, 0x13) < 0) /* set PLL divider */ in stv090x_setup()
4818 if (stv090x_write_reg(state, STV090x_I2CCFG, 0x08) < 0) /* 1/41 oversampling */ in stv090x_setup()
4820 if (stv090x_write_reg(state, STV090x_SYNTCTRL, 0x20 | config->clk_mode) < 0) /* enable PLL */ in stv090x_setup()
4827 if (stv090x_write_reg(state, stv090x_initval[i].addr, stv090x_initval[i].data) < 0) in stv090x_setup()
4831 state->internal->dev_ver = stv090x_read_reg(state, STV090x_MID); in stv090x_setup()
4832 if (state->internal->dev_ver >= 0x20) { in stv090x_setup()
4833 if (stv090x_write_reg(state, STV090x_TSGENERAL, 0x0c) < 0) in stv090x_setup()
4839 if (stv090x_write_reg(state, stv090x_cut20_val[i].addr, stv090x_cut20_val[i].data) < 0) in stv090x_setup()
4843 } else if (state->internal->dev_ver < 0x20) { in stv090x_setup()
4845 state->internal->dev_ver); in stv090x_setup()
4848 } else if (state->internal->dev_ver > 0x30) { in stv090x_setup()
4851 state->internal->dev_ver); in stv090x_setup()
4855 reg = stv090x_read_reg(state, STV090x_TSTTNR1); in stv090x_setup()
4858 if (stv090x_write_reg(state, STV090x_TSTTNR1, reg) < 0) in stv090x_setup()
4862 reg = stv090x_read_reg(state, STV090x_TSTTNR3); in stv090x_setup()
4865 if (stv090x_write_reg(state, STV090x_TSTTNR3, reg) < 0) in stv090x_setup()
4868 if (stv090x_write_reg(state, STV090x_TSTRES0, 0x80) < 0) in stv090x_setup()
4870 if (stv090x_write_reg(state, STV090x_TSTRES0, 0x00) < 0) in stv090x_setup()
4882 struct stv090x_state *state = fe->demodulator_priv; in stv090x_set_gpio() local
4889 return stv090x_write_reg(state, STV090x_GPIOxCFG(gpio), reg); in stv090x_set_gpio()
4892 static int stv090x_setup_compound(struct stv090x_state *state) in stv090x_setup_compound() argument
4896 temp_int = find_dev(state->i2c, in stv090x_setup_compound()
4897 state->config->address); in stv090x_setup_compound()
4899 if (temp_int && state->demod_mode == STV090x_DUAL) { in stv090x_setup_compound()
4900 state->internal = temp_int->internal; in stv090x_setup_compound()
4901 state->internal->num_used++; in stv090x_setup_compound()
4904 state->internal = kmalloc(sizeof(*state->internal), GFP_KERNEL); in stv090x_setup_compound()
4905 if (!state->internal) in stv090x_setup_compound()
4907 temp_int = append_internal(state->internal); in stv090x_setup_compound()
4909 kfree(state->internal); in stv090x_setup_compound()
4912 state->internal->num_used = 1; in stv090x_setup_compound()
4913 state->internal->mclk = 0; in stv090x_setup_compound()
4914 state->internal->dev_ver = 0; in stv090x_setup_compound()
4915 state->internal->i2c_adap = state->i2c; in stv090x_setup_compound()
4916 state->internal->i2c_addr = state->config->address; in stv090x_setup_compound()
4919 mutex_init(&state->internal->demod_lock); in stv090x_setup_compound()
4920 mutex_init(&state->internal->tuner_lock); in stv090x_setup_compound()
4922 if (stv090x_setup(&state->frontend) < 0) { in stv090x_setup_compound()
4928 if (state->internal->dev_ver >= 0x30) in stv090x_setup_compound()
4929 state->frontend.ops.info.caps |= FE_CAN_MULTISTREAM; in stv090x_setup_compound()
4932 if (state->config->diseqc_envelope_mode) in stv090x_setup_compound()
4933 stv090x_send_diseqc_burst(&state->frontend, SEC_MINI_A); in stv090x_setup_compound()
4935 state->config->set_gpio = stv090x_set_gpio; in stv090x_setup_compound()
4938 state->device == STV0900 ? "STV0900" : "STV0903", in stv090x_setup_compound()
4939 state->config->demod, in stv090x_setup_compound()
4940 state->internal->dev_ver); in stv090x_setup_compound()
4947 remove_dev(state->internal); in stv090x_setup_compound()
4948 kfree(state->internal); in stv090x_setup_compound()
4986 struct stv090x_state *state = i2c_get_clientdata(client); in stv090x_get_dvb_frontend() local
4990 return &state->frontend; in stv090x_get_dvb_frontend()
4999 struct stv090x_state *state = NULL; in stv090x_probe() local
5001 state = kzalloc(sizeof(*state), GFP_KERNEL); in stv090x_probe()
5002 if (!state) { in stv090x_probe()
5007 state->verbose = &verbose; in stv090x_probe()
5008 state->config = config; in stv090x_probe()
5009 state->i2c = client->adapter; in stv090x_probe()
5010 state->frontend.ops = stv090x_ops; in stv090x_probe()
5011 state->frontend.demodulator_priv = state; in stv090x_probe()
5012 state->demod = config->demod; in stv090x_probe()
5014 state->demod_mode = config->demod_mode; in stv090x_probe()
5015 state->device = config->device; in stv090x_probe()
5017 state->rolloff = STV090x_RO_35; in stv090x_probe()
5019 ret = stv090x_setup_compound(state); in stv090x_probe()
5023 i2c_set_clientdata(client, state); in stv090x_probe()
5031 kfree(state); in stv090x_probe()
5037 struct stv090x_state *state = i2c_get_clientdata(client); in stv090x_remove() local
5039 stv090x_release(&state->frontend); in stv090x_remove()
5048 struct stv090x_state *state = NULL; in stv090x_attach() local
5050 state = kzalloc(sizeof(*state), GFP_KERNEL); in stv090x_attach()
5051 if (!state) in stv090x_attach()
5054 state->verbose = &verbose; in stv090x_attach()
5055 state->config = config; in stv090x_attach()
5056 state->i2c = i2c; in stv090x_attach()
5057 state->frontend.ops = stv090x_ops; in stv090x_attach()
5058 state->frontend.demodulator_priv = state; in stv090x_attach()
5059 state->demod = demod; in stv090x_attach()
5061 state->demod_mode = config->demod_mode; in stv090x_attach()
5062 state->device = config->device; in stv090x_attach()
5064 state->rolloff = STV090x_RO_35; in stv090x_attach()
5066 ret = stv090x_setup_compound(state); in stv090x_attach()
5070 return &state->frontend; in stv090x_attach()
5073 kfree(state); in stv090x_attach()