22 #include <linux/videodev2.h>
28 "(info=1, map=2, reg=4, adv=8, cal=16 (or-able))");
30 static int tda18271_cal_on_startup = -1;
35 static LIST_HEAD(hybrid_tuner_instance_list);
50 tda_dbg(
"%s mode: xtal oscillator %s, slave tuner loop thru %s\n",
51 standby ?
"standby" :
"active",
69 static inline void tda18271_set_if_notch(
struct dvb_frontend *fe)
84 static int tda18271_channel_configuration(
struct dvb_frontend *fe,
101 regs[
R_EP3] &= ~0x04;
105 regs[
R_EP4] &= ~0x03;
108 regs[
R_EP4] &= ~0x1c;
112 regs[
R_EP4] &= ~0x80;
144 switch (priv->
role) {
149 regs[
R_EB1] &= ~0x04;
154 regs[
R_EB1] &= ~0x02;
157 regs[
R_EB1] &= ~0x01;
167 switch (priv->
role) {
170 tda18271_set_if_notch(fe);
178 tda18271_set_if_notch(fe);
188 charge_pump_source(fe, 1);
193 charge_pump_source(fe, 0);
200 regs[
R_EP3] &= ~0x04;
209 static int tda18271_read_thermometer(
struct dvb_frontend *fe)
222 if ((((regs[
R_TM] & 0x0f) == 0x00) && ((regs[
R_TM] & 0x20) == 0x20)) ||
223 (((regs[
R_TM] & 0x0f) == 0x08) && ((regs[
R_TM] & 0x20) == 0x00))) {
225 if ((regs[
R_TM] & 0x20) == 0x20)
245 regs[
R_EP4] &= ~0x03;
253 static int tda18271c2_rf_tracking_filters_correction(
struct dvb_frontend *fe,
260 u8 tm_current, dc_over_dt, rf_tab;
261 s32 rfcal_comp, approx;
269 tm_current = tda18271_read_thermometer(fe);
280 if ((0 == map[i].
rf3) || (freq / 1000 < map[i].
rf2)) {
281 approx = map[
i].
rf_a1 * (
s32)(freq / 1000 - map[i].
rf1) +
284 approx = map[
i].
rf_a2 * (
s32)(freq / 1000 - map[i].rf2) +
296 rfcal_comp = dc_over_dt * (
s32)(tm_current - priv->
tm_rfcal) / 1000;
298 regs[
R_EB14] = (
unsigned char)(approx + rfcal_comp);
344 regs[
R_EP4] &= ~0x03;
421 regs[
R_EP4] &= ~0x03;
424 regs[
R_EP3] &= ~0x40;
441 u32 *freq_in,
u32 *freq_out)
469 regs[
R_EP4] &= ~0x03;
483 *freq_out = *freq_in;
488 while ((regs[
R_EB10] & 0x3f) < cid_target) {
490 freq = *freq_in + (sgn *
count) + 1000000;
511 if (count <= count_limit)
522 if ((regs[
R_EB10] & 0x3f) >= cid_target) {
524 *freq_out = freq - 1000000;
528 tda_cal(
"bcal = %d, freq_in = %d, freq_out = %d (freq = %d)\n",
529 bcal, *freq_in, *freq_out, freq);
534 static int tda18271_powerscan_init(
struct dvb_frontend *fe)
541 regs[
R_EP3] &= ~0x1f;
545 regs[
R_EP4] &= ~0x03;
548 regs[
R_EP4] &= ~0x1c;
570 static int tda18271_rf_tracking_filters_init(
struct dvb_frontend *fe,
u32 freq)
594 for (rf = RF1; rf <=
RF3; rf++) {
595 if (0 == rf_default[rf])
597 tda_cal(
"freq = %d, rf = %d\n", freq, rf);
600 bcal = tda18271_powerscan(fe, &rf_default[rf], &rf_freq[rf]);
609 (
s32)tda18271_calibrate_rf(fe, rf_freq[rf]);
611 prog_cal[rf] = prog_tab[rf];
617 map[
i].
rf1 = rf_freq[
RF1] / 1000;
620 dividend = (prog_cal[
RF2] - prog_tab[
RF2] -
621 prog_cal[
RF1] + prog_tab[
RF1]);
622 divisor = (
s32)(rf_freq[RF2] - rf_freq[RF1]) / 1000;
624 map[
i].
rf2 = rf_freq[
RF2] / 1000;
627 dividend = (prog_cal[
RF3] - prog_tab[
RF3] -
628 prog_cal[
RF2] + prog_tab[
RF2]);
629 divisor = (
s32)(rf_freq[RF3] - rf_freq[RF2]) / 1000;
631 map[
i].
rf_b2 = (prog_cal[RF2] - prog_tab[RF2]);
632 map[
i].
rf3 = rf_freq[
RF3] / 1000;
642 static int tda18271_calc_rf_filter_curve(
struct dvb_frontend *fe)
648 tda_info(
"tda18271: performing RF tracking filter calibration\n");
653 ret = tda18271_powerscan_init(fe);
660 tda18271_rf_tracking_filters_init(fe, 1000 *
666 priv->
tm_rfcal = tda18271_read_thermometer(fe);
673 static int tda18271c2_rf_cal_init(
struct dvb_frontend *fe)
680 if ((regs[
R_EP1] & 0x10) == 0)
686 ret = tda18271_calc_rf_filter_curve(fe);
690 ret = tda18271_por(fe);
694 tda_info(
"tda18271: RF tracking filter calibration complete\n");
699 tda_info(
"tda18271: RF tracking filter calibration failed!\n");
704 static int tda18271c1_rf_tracking_filter_calibration(
struct dvb_frontend *fe,
734 switch (priv->
mode) {
747 switch (priv->
mode) {
752 N = freq + bw / 2 + 1000000;
791 regs[
R_EP4] &= ~0x03;
805 static int tda18271_ir_cal_init(
struct dvb_frontend *fe)
816 if ((regs[
R_EP1] & 0x08) == 0)
835 ret = tda18271_ir_cal_init(fe);
840 tda18271c2_rf_cal_init(fe);
855 ret = tda18271_toggle_output(fe, 1);
873 tda_dbg(
"no agc configuration provided\n");
877 tda_dbg(
"invoking callback\n");
901 tda_dbg(
"freq = %d, ifc = %d, bw = %d, agc_mode = %d, std = %d\n",
904 ret = tda18271_agc(fe);
906 tda_warn(
"failed to configure agc\n");
908 ret = tda18271_init(fe);
916 tda18271c1_rf_tracking_filter_calibration(fe, freq, bw);
919 tda18271c2_rf_tracking_filters_correction(fe, freq);
922 ret = tda18271_channel_configuration(fe, map, freq, bw);
954 }
else if (bw <= 7000000) {
966 map = &std_map->
qam_6;
967 }
else if (bw <= 7000000) {
968 map = &std_map->
qam_7;
970 map = &std_map->
qam_8;
974 tda_warn(
"modulation type not supported!\n");
979 if (fe->
ops.analog_ops.standby)
980 fe->
ops.analog_ops.standby(fe);
982 ret = tda18271_tune(fe, map, freq, bw);
994 static int tda18271_set_analog_params(
struct dvb_frontend *fe,
1014 map = &std_map->
atv_b;
1020 map = &std_map->
atv_i;
1026 map = &std_map->
atv_l;
1032 map = &std_map->
atv_i;
1036 tda_dbg(
"setting tda18271 to system %s\n", mode);
1038 ret = tda18271_tune(fe, map, freq, 0);
1089 #define tda18271_update_std(std_cfg, name) do { \
1090 if (map->std_cfg.if_freq + \
1091 map->std_cfg.agc_mode + map->std_cfg.std + \
1092 map->std_cfg.if_lvl + map->std_cfg.rfagc_top > 0) { \
1093 tda_dbg("Using custom std config for %s\n", name); \
1094 memcpy(&std->std_cfg, &map->std_cfg, \
1095 sizeof(struct tda18271_std_map_item)); \
1098 #define tda18271_dump_std_item(std_cfg, name) do { \
1099 tda_dbg("(%s) if_freq = %d, agc_mode = %d, std = %d, " \
1100 "if_lvl = %d, rfagc_top = 0x%02x\n", \
1101 name, std->std_cfg.if_freq, \
1102 std->std_cfg.agc_mode, std->std_cfg.std, \
1103 std->std_cfg.if_lvl, std->std_cfg.rfagc_top); \
1106 static int tda18271_dump_std_map(
struct dvb_frontend *fe)
1111 tda_dbg(
"========== STANDARD MAP SETTINGS ==========\n");
1130 static int tda18271_update_std_map(
struct dvb_frontend *fe,
1169 tda_info(
"Error reading device ID @ %d-%04x, bailing out.\n",
1175 switch (regs[
R_ID] & 0x7f) {
1177 name =
"TDA18271HD/C1";
1181 name =
"TDA18271HD/C2";
1185 tda_info(
"Unknown device (%i) detected @ %d-%04x, device not supported.\n",
1191 tda_info(
"%s detected @ %d-%04x\n", name,
1197 static int tda18271_setup_configuration(
struct dvb_frontend *fe,
1216 return ((tda18271_cal_on_startup == -1) ?
1220 (tda18271_cal_on_startup)) ? 1 : 0;
1223 static int tda18271_set_config(
struct dvb_frontend *fe,
void *priv_cfg)
1227 tda18271_setup_configuration(fe, cfg);
1229 if (tda18271_need_cal_on_startup(cfg))
1234 tda18271_update_std_map(fe, cfg->
std_map);
1241 .name =
"NXP TDA18271HD",
1242 .frequency_min = 45000000,
1243 .frequency_max = 864000000,
1244 .frequency_step = 62500
1246 .init = tda18271_init,
1247 .sleep = tda18271_sleep,
1248 .set_params = tda18271_set_params,
1249 .set_analog_params = tda18271_set_analog_params,
1250 .release = tda18271_release,
1251 .set_config = tda18271_set_config,
1252 .get_frequency = tda18271_get_frequency,
1253 .get_bandwidth = tda18271_get_bandwidth,
1254 .get_if_frequency = tda18271_get_if_frequency,
1268 i2c, addr,
"tda18271");
1276 tda18271_setup_configuration(fe, cfg);
1281 ret = tda18271_get_id(fe);
1291 if ((cfg->
delay_cal) && (!tda18271_need_cal_on_startup(cfg)))
1297 if ((tda18271_need_cal_on_startup(cfg)) &&
1299 tda18271c2_rf_cal_init(fe);
1302 ret = tda18271_toggle_output(fe, 1);
1324 tda18271_update_std_map(fe, cfg->
std_map);
1326 if (tda18271_need_cal_on_startup(cfg))
1333 tda18271_update_std_map(fe, cfg->
std_map);
1337 memcpy(&fe->
ops.tuner_ops, &tda18271_tuner_ops,
1341 tda18271_dump_std_map(fe);
1347 tda18271_release(fe);