27 #include <linux/kernel.h>
28 #include <linux/slab.h>
29 #include <linux/i2c.h>
41 #define dprintk(args...) do { \
43 printk(KERN_DEBUG "DiB0090: "); \
49 #define CONFIG_SYS_DVBT
50 #define CONFIG_SYS_ISDBT
51 #define CONFIG_BAND_CBAND
52 #define CONFIG_BAND_VHF
53 #define CONFIG_BAND_UHF
54 #define CONFIG_DIB0090_USE_PWM_AGC
56 #define EN_LNA0 0x8000
57 #define EN_LNA1 0x4000
58 #define EN_LNA2 0x2000
59 #define EN_LNA3 0x1000
60 #define EN_MIX0 0x0800
61 #define EN_MIX1 0x0400
62 #define EN_MIX2 0x0200
63 #define EN_MIX3 0x0100
64 #define EN_IQADC 0x0040
69 #define EN_BIAS 0x0001
71 #define EN_IQANA 0x0002
72 #define EN_DIGCLK 0x0080
73 #define EN_CRYSTAL 0x0002
85 #define CAPTRIM_CAL 0x8
87 #define KROSUS_PLL_LOCKED 0x800
92 #define SOC_7090_P1G_11R1 0x82
93 #define SOC_7090_P1G_21R1 0x8a
94 #define SOC_8090_P1G_11R1 0x86
95 #define SOC_8090_P1G_21R1 0x8e
109 #define pgm_read_word(w) (*w)
221 dprintk(
"could not acquire lock");
228 state->
msg[0].addr = state->
config->i2c_address;
229 state->
msg[0].flags = 0;
231 state->
msg[0].len = 1;
232 state->
msg[1].addr = state->
config->i2c_address;
235 state->
msg[1].len = 2;
253 dprintk(
"could not acquire lock");
262 state->
msg[0].addr = state->
config->i2c_address;
263 state->
msg[0].flags = 0;
265 state->
msg[0].len = 3;
282 dprintk(
"could not acquire lock");
309 dprintk(
"could not acquire lock");
318 state->
msg.flags = 0;
331 #define HARD_RESET(state) do { if (cfg->reset) { if (cfg->sleep) cfg->sleep(fe, 0); msleep(10); cfg->reset(fe, 1); msleep(10); cfg->reset(fe, 0); msleep(10); } } while (0)
332 #define ADC_TARGET -220
339 dib0090_write_reg(state, r++, *b++);
349 v = dib0090_read_reg(state, 0x1a);
354 dprintk(
"Tuner identification (Version = 0x%04x)", v);
360 identity->
product = (v >> 8) & 0xf;
363 goto identification_error;
369 dprintk(
"SOC 8090 P1-G11R1 Has been detected");
373 dprintk(
"SOC 8090 P1-G21R1 Has been detected");
377 dprintk(
"SOC 7090 P1-G11R1 Has been detected");
381 dprintk(
"SOC 7090 P1-G21R1 Has been detected");
385 goto identification_error;
388 switch ((identity->
version >> 5) & 0x7) {
393 dprintk(
"MP005 : Single Sband");
396 dprintk(
"MP008 : diversity VHF-UHF-LBAND");
399 dprintk(
"MP009 : diversity 29098 CBAND-UHF-LBAND-SBAND");
402 goto identification_error;
405 switch (identity->
version & 0x1f) {
421 dprintk(
"P1-A/B detected: driver is deactivated - not available");
422 goto identification_error;
425 goto identification_error;
431 identification_error:
440 u16 v = dib0090_fw_read_reg(state, 0x1a);
444 dprintk(
"FE: Tuner identification (Version = 0x%04x)", v);
450 identity->
product = (v >> 8) & 0xf;
453 goto identification_error;
459 dprintk(
"SOC 8090 P1-G11R1 Has been detected");
463 dprintk(
"SOC 8090 P1-G21R1 Has been detected");
467 dprintk(
"SOC 7090 P1-G11R1 Has been detected");
471 dprintk(
"SOC 7090 P1-G21R1 Has been detected");
475 goto identification_error;
478 switch ((identity->
version >> 5) & 0x7) {
483 dprintk(
"MP005 : Single Sband");
486 dprintk(
"MP008 : diversity VHF-UHF-LBAND");
489 dprintk(
"MP009 : diversity 29098 CBAND-UHF-LBAND-SBAND");
492 goto identification_error;
495 switch (identity->
version & 0x1f) {
511 dprintk(
"P1-A/B detected: driver is deactivated - not available");
512 goto identification_error;
515 goto identification_error;
521 identification_error:
537 dib0090_write_reg(state, 0x20, ((cfg->
io.adc_clock_ratio - 1) << 11) | (0 << 10) | (1 << 9) | (1 << 8) | (0 << 4) | 0);
539 dib0090_write_reg(state, 0x23, (0 << 15) | ((!cfg->
analog_output) << 14) | (2 << 10) | (1 << 9) | (0 << 8)
542 dib0090_write_reg(state, 0x23, (0 << 15) | ((!cfg->
analog_output) << 14) | (2 << 10) | (1 << 9) | (0 << 8)
547 PllCfg = dib0090_read_reg(state, 0x21);
550 if ((PllCfg & 0x1FFF) != ((cfg->
io.pll_range << 12) | (cfg->
io.pll_loopdiv << 6) | (cfg->
io.pll_prediv)) && (!cfg->
in_soc)
551 && !cfg->
io.pll_bypass) {
555 dib0090_write_reg(state, 0x21, PllCfg);
558 PllCfg &= ~(1 << 13);
559 dib0090_write_reg(state, 0x21, PllCfg);
562 PllCfg = (1 << 15) | (0 << 13) | (cfg->
io.pll_range << 12) | (cfg->
io.pll_loopdiv << 6) | (cfg->
io.pll_prediv);
563 dib0090_write_reg(state, 0x21, PllCfg);
567 dib0090_write_reg(state, 0x21, PllCfg);
572 v = !!(dib0090_read_reg(state, 0x1a) & 0x800);
578 dprintk(
"Pll: Unable to lock Pll");
583 PllCfg &= ~(1 << 15);
584 dib0090_write_reg(state, 0x21, PllCfg);
587 if (cfg->
io.pll_bypass) {
588 PllCfg |= (cfg->
io.pll_bypass << 15);
589 dib0090_write_reg(state, 0x21, PllCfg);
606 dib0090_fw_write_reg(state, 0x20,
616 dib0090_fw_write_reg(state, 0x23, v);
619 PllCfg = dib0090_fw_read_reg(state, 0x21);
622 if ((PllCfg & 0x1FFF) != ((cfg->
io.pll_range << 12) | (cfg->
io.pll_loopdiv << 6) | (cfg->
io.pll_prediv)) && !cfg->
io.pll_bypass) {
626 dib0090_fw_write_reg(state, 0x21, PllCfg);
629 PllCfg &= ~(1 << 13);
630 dib0090_fw_write_reg(state, 0x21, PllCfg);
633 PllCfg = (1 << 15) | (0 << 13) | (cfg->
io.pll_range << 12) | (cfg->
io.pll_loopdiv << 6) | (cfg->
io.pll_prediv);
634 dib0090_fw_write_reg(state, 0x21, PllCfg);
638 dib0090_fw_write_reg(state, 0x21, PllCfg);
643 v = !!(dib0090_fw_read_reg(state, 0x1a) & 0x800);
649 dprintk(
"Pll: Unable to lock Pll");
654 PllCfg &= ~(1 << 15);
655 dib0090_fw_write_reg(state, 0x21, PllCfg);
658 if (cfg->
io.pll_bypass) {
659 PllCfg |= (cfg->
io.pll_bypass << 15);
660 dib0090_fw_write_reg(state, 0x21, PllCfg);
663 return dib0090_fw_identify(fe);
670 state->
config->sleep(fe, 0);
673 dib0090_write_reg(state, 0x23, dib0090_read_reg(state, 0x23) | (1 << 14));
681 state->
config->sleep(fe, 1);
689 dib0090_write_reg(state, 0x04, 0);
691 dib0090_write_reg(state, 0x04, 1);
696 static const u16 bb_ramp_pwm_normal_socs[] = {
706 static const u16 rf_ramp_pwm_cband_7090[] = {
720 static const uint16_t rf_ramp_pwm_cband_7090e_sensitivity[] = {
734 static const uint16_t rf_ramp_pwm_cband_7090e_aci[] = {
748 static const u16 rf_ramp_pwm_cband_8090[] = {
762 static const u16 rf_ramp_pwm_uhf_7090[] = {
776 static const u16 rf_ramp_pwm_uhf_8090[] = {
790 static const u16 rf_ramp_pwm_cband[] = {
804 static const u16 rf_ramp_vhf[] = {
813 static const u16 rf_ramp_uhf[] = {
822 static const u16 rf_ramp_cband_broadmatching[] =
832 static const u16 rf_ramp_cband[] = {
841 static const u16 rf_ramp_pwm_vhf[] = {
855 static const u16 rf_ramp_pwm_uhf[] = {
869 static const u16 bb_ramp_boost[] = {
875 static const u16 bb_ramp_pwm_normal[] = {
889 static u16 slopes_to_scale(
const struct slope *slopes,
u8 num,
s16 val)
894 for (i = 0; i < num; i++) {
895 if (val > slopes[i].
range)
899 ret += (rest * slopes[
i].
slope) / slopes[i].range;
905 static const struct slope dib0090_wbd_slopes[3] = {
914 if (wbd < state->wbd_offset)
919 return -640 + (
s16) slopes_to_scale(dib0090_wbd_slopes,
ARRAY_SIZE(dib0090_wbd_slopes), wbd);
930 #ifndef FIRMWARE_FIREFLY
932 offset = state->
config->wbd_vhf_offset;
934 offset = state->
config->wbd_cband_offset;
941 static const int gain_reg_addr[4] = {
942 0x08, 0x0a, 0x0f, 0x01
951 if (top_delta < -511)
1000 for (i = 0; i < 7; i++) {
1001 if (g[0] == 0 || ref < (g[1] - g[0]))
1003 else if (ref >= g[1])
1006 v = ((ref - (g[1] - g[0])) * g[2]) / g[0];
1011 gain_reg[0] |= v << 7;
1015 gain_reg[1] |= v << 7;
1019 gain_reg[3] = v << 3;
1021 gain_reg[3] |= v << 8;
1032 gain_reg[3] |= ((bb % 10) * 100) / 125;
1035 dprintk(
"GA CALC: DB: %3d(rf) + %3d(bb) = %3d gain_reg[0]=%04x gain_reg[1]=%04x gain_reg[2]=%04x gain_reg[0]=%04x", rf, bb, rf + bb,
1036 gain_reg[0], gain_reg[1], gain_reg[2], gain_reg[3]);
1040 for (i = 0; i < 4; i++) {
1042 if (force || state->
gain_reg[i] != v) {
1044 dib0090_write_reg(state, gain_reg_addr[i], v);
1055 static void dib0090_set_rframp(
struct dib0090_state *state,
const u16 * cfg)
1060 static void dib0090_set_rframp_pwm(
struct dib0090_state *state,
const u16 * cfg)
1064 dib0090_write_reg(state, 0x2a, 0xffff);
1066 dprintk(
"total RF gain: %ddB, step: %d", (
u32) cfg[0], dib0090_read_reg(state, 0x2a));
1068 dib0090_write_regs(state, 0x2c, cfg + 3, 6);
1069 dib0090_write_regs(state, 0x3e, cfg + 9, 2);
1072 static void dib0090_set_bbramp(
struct dib0090_state *state,
const u16 * cfg)
1075 dib0090_set_boost(state, cfg[0] > 500);
1078 static void dib0090_set_bbramp_pwm(
struct dib0090_state *state,
const u16 * cfg)
1082 dib0090_set_boost(state, cfg[0] > 500);
1084 dib0090_write_reg(state, 0x33, 0xffff);
1085 dprintk(
"total BB gain: %ddB, step: %d", (
u32) cfg[0], dib0090_read_reg(state, 0x33));
1086 dib0090_write_regs(state, 0x35, cfg + 3, 4);
1094 if (state->
config->use_pwm_agc) {
1095 #ifdef CONFIG_BAND_SBAND
1097 dib0090_set_rframp_pwm(state, rf_ramp_pwm_sband);
1098 dib0090_set_bbramp_pwm(state, bb_ramp_pwm_boost);
1101 #ifdef CONFIG_BAND_CBAND
1104 dib0090_set_bbramp_pwm(state, bb_ramp_pwm_normal_socs);
1106 dib0090_set_rframp_pwm(state, rf_ramp_pwm_cband_8090);
1109 if (state->
config->is_dib7090e) {
1111 dib0090_set_rframp_pwm(state, rf_ramp_pwm_cband_7090e_sensitivity);
1113 dib0090_set_rframp_pwm(state, state->
rf_ramp);
1115 dib0090_set_rframp_pwm(state, rf_ramp_pwm_cband_7090);
1118 dib0090_set_rframp_pwm(state, rf_ramp_pwm_cband);
1119 dib0090_set_bbramp_pwm(state, bb_ramp_pwm_normal);
1123 #ifdef CONFIG_BAND_VHF
1126 dib0090_set_bbramp_pwm(state, bb_ramp_pwm_normal_socs);
1128 dib0090_set_rframp_pwm(state, rf_ramp_pwm_vhf);
1129 dib0090_set_bbramp_pwm(state, bb_ramp_pwm_normal);
1136 dib0090_set_rframp_pwm(state, rf_ramp_pwm_uhf_8090);
1138 dib0090_set_rframp_pwm(state, rf_ramp_pwm_uhf_7090);
1139 dib0090_set_bbramp_pwm(state, bb_ramp_pwm_normal_socs);
1141 dib0090_set_rframp_pwm(state, rf_ramp_pwm_uhf);
1142 dib0090_set_bbramp_pwm(state, bb_ramp_pwm_normal);
1147 dib0090_write_reg(state, 0x32, (3 << 11));
1149 dib0090_write_reg(state, 0x32, (0 << 11));
1151 dib0090_write_reg(state, 0x04, 0x03);
1152 dib0090_write_reg(state, 0x39, (1 << 10));
1161 if (DC_servo_cutoff < 4)
1162 dib0090_write_reg(state, 0x04, DC_servo_cutoff);
1168 u16 adc_val = dib0090_read_reg(state, 0x1d);
1181 u8 apply_gain_immediatly = 1;
1182 s16 wbd_error = 0, adc_error = 0;
1186 dib0090_write_reg(state, 0x04, 0x0);
1188 #ifdef CONFIG_BAND_SBAND
1190 dib0090_set_rframp(state, rf_ramp_sband);
1191 dib0090_set_bbramp(state, bb_ramp_boost);
1194 #ifdef CONFIG_BAND_VHF
1196 dib0090_set_rframp(state, rf_ramp_vhf);
1197 dib0090_set_bbramp(state, bb_ramp_boost);
1200 #ifdef CONFIG_BAND_CBAND
1202 dib0090_set_rframp(state, rf_ramp_cband);
1203 dib0090_set_bbramp(state, bb_ramp_boost);
1207 dib0090_set_rframp(state, rf_ramp_cband_broadmatching);
1208 dib0090_set_bbramp(state, bb_ramp_boost);
1210 dib0090_set_rframp(state, rf_ramp_uhf);
1211 dib0090_set_bbramp(state, bb_ramp_boost);
1214 dib0090_write_reg(state, 0x32, 0);
1215 dib0090_write_reg(state, 0x39, 0);
1217 dib0090_wbd_target(state, state->
current_rf);
1227 wbd_val = dib0090_get_slow_adc_val(state);
1234 for (i = 0; i <
cnt; i++) {
1235 wbd_val = dib0090_get_slow_adc_val(state);
1236 wbd += dib0090_wbd_to_db(state, wbd_val);
1243 #ifdef CONFIG_BAND_CBAND
1257 adc = state->
config->get_adc_power(fe);
1258 adc = (adc * ((
s32) 355774) + (((
s32) 1) << 20)) >> 21;
1261 #ifdef CONFIG_STANDARD_DAB
1262 if (state->
fe->dtv_property_cache.delivery_system == STANDARD_DAB)
1265 #ifdef CONFIG_STANDARD_DVBT
1266 if (state->
fe->dtv_property_cache.delivery_system == STANDARD_DVBT &&
1267 (state->
fe->dtv_property_cache.modulation ==
QAM_64 || state->
fe->dtv_property_cache.modulation ==
QAM_16))
1270 #ifdef CONFIG_SYS_ISDBT
1271 if ((state->
fe->dtv_property_cache.delivery_system ==
SYS_ISDBT) && (((state->
fe->dtv_property_cache.layer[0].segment_count >
1274 ((state->
fe->dtv_property_cache.layer[0].modulation ==
1276 || (state->
fe->dtv_property_cache.
1277 layer[0].modulation ==
QAM_16)))
1279 ((state->
fe->dtv_property_cache.layer[1].segment_count >
1282 ((state->
fe->dtv_property_cache.layer[1].modulation ==
1284 || (state->
fe->dtv_property_cache.
1285 layer[1].modulation ==
QAM_16)))
1287 ((state->
fe->dtv_property_cache.layer[2].segment_count >
1290 ((state->
fe->dtv_property_cache.layer[2].modulation ==
1292 || (state->
fe->dtv_property_cache.
1293 layer[2].modulation ==
QAM_16)))
1300 if (
ABS(adc_error) < 50 || state->
agc_step++ > 5) {
1302 #ifdef CONFIG_STANDARD_DAB
1303 if (state->
fe->dtv_property_cache.delivery_system == STANDARD_DAB) {
1304 dib0090_write_reg(state, 0x02, (1 << 15) | (15 << 11) | (31 << 6) | (63));
1305 dib0090_write_reg(state, 0x04, 0x0);
1309 dib0090_write_reg(state, 0x02, (1 << 15) | (3 << 11) | (6 << 6) | (32));
1310 dib0090_write_reg(state, 0x04, 0x01);
1318 apply_gain_immediatly = 0;
1323 (
"tune state %d, ADC = %3ddB (ADC err %3d) WBD %3ddB (WBD err %3d, WBD val SADC: %4d), RFGainLimit (TOP): %3d, signal: %3ddBm",
1324 (
u32) *tune_state, (
u32) adc, (
u32) adc_error, (
u32) wbd, (
u32) wbd_error, (
u32) wbd_val,
1331 dib0090_gain_apply(state, adc_error, wbd_error, apply_gain_immediatly);
1341 *rf = state->
gain[0];
1343 *bb = state->
gain[1];
1355 u32 f_MHz = state->
fe->dtv_property_cache.frequency / 1000000;
1357 s32 wbd_thot, wbd_tcold;
1365 if (current_temp < 0)
1367 if (current_temp > 128)
1370 state->
wbdmux &= ~(7 << 13);
1374 state->
wbdmux |= (4 << 13);
1376 dib0090_write_reg(state, 0x10, state->
wbdmux);
1381 wbd_tcold += ((wbd_thot - wbd_tcold) * current_temp) >> 7;
1385 dprintk(
"wbd offset applied is %d", wbd_tcold);
1402 dib0090_write_reg(state, 0x0b, (dib0090_read_reg(state, 0x0b) & 0xfff8)
1403 | ((sw3 & 1) << 2) | ((sw2 & 1) << 1) | (sw1 & 1));
1413 dib0090_write_reg(state, 0x09, (dib0090_read_reg(state, 0x09) & 0x7fff)
1414 | ((onoff & 1) << 15));
1426 dprintk(
"%s() function can only be used for dib7090P", __func__);
1430 if (cfg_sensitivity)
1431 state->
rf_ramp = (
const u16 *)&rf_ramp_pwm_cband_7090e_sensitivity;
1433 state->
rf_ramp = (
const u16 *)&rf_ramp_pwm_cband_7090e_aci;
1440 static const u16 dib0090_defaults[] = {
1488 static const u16 dib0090_p1g_additionnal_defaults[] = {
1503 static void dib0090_set_default_config(
struct dib0090_state *state,
const u16 *
n)
1518 #define CAP_VALUE_MIN (u8) 9
1519 #define CAP_VALUE_MAX (u8) 40
1520 #define HR_MIN (u8) 25
1521 #define HR_MAX (u8) 40
1522 #define POLY_MIN (u8) 0
1523 #define POLY_MAX (u8) 8
1531 e2 = dib0090_read_reg(state, 0x26);
1532 e4 = dib0090_read_reg(state, 0x28);
1535 (state->
identity.version ==
P1G) || (e2 == 0xffff)) {
1537 dib0090_write_reg(state, 0x22, 0x10);
1538 cal = (dib0090_read_reg(state, 0x22) >> 6) & 0x3ff;
1540 if ((cal < 670) || (cal == 1023))
1542 n = 165 - ((cal * 10)>>6) ;
1543 e2 = e4 = (3<<12) | (34<<6) | (
n);
1551 n = (e2 >> 12) & 0xf;
1552 h = (e2 >> 6) & 0x3f;
1561 dib0090_write_reg(state, 0x13, (h << 10)) ;
1562 e2 = (n<<11) | ((h>>2)<<6) | (
c);
1563 dib0090_write_reg(state, 0x2, e2) ;
1571 dib0090_reset_digital(fe, state->
config);
1572 if (dib0090_identify(fe) < 0)
1575 #ifdef CONFIG_TUNER_DIB0090_P1B_SUPPORT
1576 if (!(state->
identity.version & 0x1))
1581 if ((dib0090_read_reg(state, 0x1a) >> 5) & 0x2)
1587 dib0090_set_default_config(state, dib0090_defaults);
1590 dib0090_write_reg(state, 0x18, 0x2910);
1593 dib0090_set_default_config(state, dib0090_p1g_additionnal_defaults);
1597 dib0090_set_EFUSE(state);
1600 if (state->
config->force_crystal_mode != 0)
1601 dib0090_write_reg(state, 0x14,
1602 state->
config->force_crystal_mode & 3);
1603 else if (state->
config->io.clock_khz >= 24000)
1604 dib0090_write_reg(state, 0x14, 1);
1606 dib0090_write_reg(state, 0x14, 2);
1607 dprintk(
"Pll lock : %d", (dib0090_read_reg(state, 0x1a) >> 11) & 0x1);
1614 #define steps(u) (((u) > 15) ? ((u)-16) : (u))
1615 #define INTERN_WAIT 10
1620 switch (*tune_state) {
1623 dib0090_write_reg(state, 0x1f, 0x7);
1628 state->
adc_diff = dib0090_read_reg(state, 0x1d);
1631 dib0090_write_reg(state, 0x1f, 0x4);
1636 state->
adc_diff -= dib0090_read_reg(state, 0x1d);
1658 {0x06, 5, 1, (1 << 13) | (0 << 8) | (26 << 3), 1},
1659 {0x07, 11, 1, (1 << 13) | (0 << 8) | (26 << 3), 0},
1661 {0x06, 0, 0, (1 << 13) | (29 << 8) | (26 << 3), 1},
1662 {0x06, 10, 0, (1 << 13) | (29 << 8) | (26 << 3), 0},
1669 {0x06, 5, 1, (1 << 13) | (0 << 8) | (15 << 3), 1},
1670 {0x07, 11, 1, (1 << 13) | (0 << 8) | (15 << 3), 0},
1672 {0x06, 0, 0, (1 << 13) | (29 << 8) | (15 << 3), 1},
1673 {0x06, 10, 0, (1 << 13) | (29 << 8) | (15 << 3), 0},
1681 if (state->
dc->addr == 0x07)
1686 *val &= ~(0x1f << state->
dc->offset);
1687 *val |= state->
step << state->
dc->offset;
1689 dib0090_write_reg(state, state->
dc->addr, *val);
1697 switch (*tune_state) {
1699 dprintk(
"Start DC offset calibration");
1703 state->
bb7 = 0x040d;
1706 reg = dib0090_read_reg(state, 0x24) & 0x0ffb;
1707 dib0090_write_reg(state, 0x24, reg);
1709 state->
wbdmux = dib0090_read_reg(state, 0x10);
1710 dib0090_write_reg(state, 0x10, (state->
wbdmux & ~(0xff << 3)) | (0x7 << 3) | 0x3);
1711 dib0090_write_reg(state, 0x23, dib0090_read_reg(state, 0x23) & ~(1 << 14));
1713 state->
dc = dc_table;
1716 state->
dc = dc_p1g_table;
1722 dprintk(
"Sart/continue DC calibration for %s path", (state->
dc->i == 1) ?
"I" :
"Q");
1723 dib0090_write_reg(state, 0x01, state->
dc->bb1);
1724 dib0090_write_reg(state, 0x07, state->
bb7 | (state->
dc->i << 7));
1733 dib0090_set_trim(state);
1740 ret = dib0090_get_offset(state, tune_state);
1747 dprintk(
"Change of sign of the minimum adc diff");
1753 if (state->
step == 0) {
1756 if (state->
dc->pga == 0 && state->
adc_diff > 0)
1773 dib0090_set_trim(state);
1774 dprintk(
"BB Offset Cal, BBreg=%hd,Offset=%hd,Value Set=%hd", state->
dc->addr, state->
adc_diff, state->
step);
1777 if (state->
dc->addr == 0)
1786 dib0090_write_reg(state, 0x07, state->
bb7 & ~0x0008);
1787 dib0090_write_reg(state, 0x1f, 0x7);
1801 switch (*tune_state) {
1809 #if defined(CONFIG_BAND_LBAND) || defined(CONFIG_BAND_SBAND)
1821 dib0090_write_reg(state, 0x10, 0x1b81 | (1 << 10) | (wbd_gain << 13) | (1 << 3));
1823 dib0090_write_reg(state, 0x24, ((
EN_UHF & 0x0fff) | (1 << 1)));
1829 state->
wbd_offset = dib0090_get_slow_adc_val(state);
1841 static void dib0090_set_bandwidth(
struct dib0090_state *state)
1845 if (state->
fe->dtv_property_cache.bandwidth_hz / 1000 <= 5000)
1847 else if (state->
fe->dtv_property_cache.bandwidth_hz / 1000 <= 6000)
1849 else if (state->
fe->dtv_property_cache.bandwidth_hz / 1000 <= 7000)
1857 dib0090_write_reg(state, 0x01, state->
bb_1_def);
1859 dib0090_write_reg(state, 0x03, 0x6008);
1860 dib0090_write_reg(state, 0x04, 0x1);
1862 dib0090_write_reg(state, 0x05, 0x9bcf);
1864 dib0090_write_reg(state, 0x02, (5 << 11) | (8 << 6) | (22 & 0x3f));
1865 dib0090_write_reg(state, 0x05, 0xabcd);
1869 static const struct dib0090_pll dib0090_pll_table[] = {
1870 #ifdef CONFIG_BAND_CBAND
1871 {56000, 0, 9, 48, 6},
1872 {70000, 1, 9, 48, 6},
1873 {87000, 0, 8, 32, 4},
1874 {105000, 1, 8, 32, 4},
1875 {115000, 0, 7, 24, 6},
1876 {140000, 1, 7, 24, 6},
1877 {170000, 0, 6, 16, 4},
1879 #ifdef CONFIG_BAND_VHF
1880 {200000, 1, 6, 16, 4},
1881 {230000, 0, 5, 12, 6},
1882 {280000, 1, 5, 12, 6},
1883 {340000, 0, 4, 8, 4},
1884 {380000, 1, 4, 8, 4},
1885 {450000, 0, 3, 6, 6},
1887 #ifdef CONFIG_BAND_UHF
1888 {580000, 1, 3, 6, 6},
1889 {700000, 0, 2, 4, 4},
1890 {860000, 1, 2, 4, 4},
1892 #ifdef CONFIG_BAND_LBAND
1893 {1800000, 1, 0, 2, 4},
1895 #ifdef CONFIG_BAND_SBAND
1896 {2900000, 0, 14, 1, 4},
1900 static const struct dib0090_tuning dib0090_tuning_table_fm_vhf_on_cband[] = {
1902 #ifdef CONFIG_BAND_CBAND
1903 {184000, 4, 1, 15, 0x280, 0x2912, 0xb94e,
EN_CAB},
1904 {227000, 4, 3, 15, 0x280, 0x2912, 0xb94e,
EN_CAB},
1905 {380000, 4, 7, 15, 0x280, 0x2912, 0xb94e,
EN_CAB},
1907 #ifdef CONFIG_BAND_UHF
1908 {520000, 2, 0, 15, 0x300, 0x1d12, 0xb9ce,
EN_UHF},
1909 {550000, 2, 2, 15, 0x300, 0x1d12, 0xb9ce,
EN_UHF},
1910 {650000, 2, 3, 15, 0x300, 0x1d12, 0xb9ce,
EN_UHF},
1911 {750000, 2, 5, 15, 0x300, 0x1d12, 0xb9ce,
EN_UHF},
1912 {850000, 2, 6, 15, 0x300, 0x1d12, 0xb9ce,
EN_UHF},
1913 {900000, 2, 7, 15, 0x300, 0x1d12, 0xb9ce,
EN_UHF},
1915 #ifdef CONFIG_BAND_LBAND
1916 {1500000, 4, 0, 20, 0x300, 0x1912, 0x82c9,
EN_LBD},
1917 {1600000, 4, 1, 20, 0x300, 0x1912, 0x82c9,
EN_LBD},
1918 {1800000, 4, 3, 20, 0x300, 0x1912, 0x82c9,
EN_LBD},
1920 #ifdef CONFIG_BAND_SBAND
1921 {2300000, 1, 4, 20, 0x300, 0x2d2A, 0x82c7,
EN_SBD},
1922 {2900000, 1, 7, 20, 0x280, 0x2deb, 0x8347,
EN_SBD},
1928 #ifdef CONFIG_BAND_CBAND
1929 {170000, 4, 1, 15, 0x280, 0x2912, 0xb94e,
EN_CAB},
1931 #ifdef CONFIG_BAND_VHF
1932 {184000, 1, 1, 15, 0x300, 0x4d12, 0xb94e,
EN_VHF},
1933 {227000, 1, 3, 15, 0x300, 0x4d12, 0xb94e,
EN_VHF},
1934 {380000, 1, 7, 15, 0x300, 0x4d12, 0xb94e,
EN_VHF},
1936 #ifdef CONFIG_BAND_UHF
1937 {520000, 2, 0, 15, 0x300, 0x1d12, 0xb9ce,
EN_UHF},
1938 {550000, 2, 2, 15, 0x300, 0x1d12, 0xb9ce,
EN_UHF},
1939 {650000, 2, 3, 15, 0x300, 0x1d12, 0xb9ce,
EN_UHF},
1940 {750000, 2, 5, 15, 0x300, 0x1d12, 0xb9ce,
EN_UHF},
1941 {850000, 2, 6, 15, 0x300, 0x1d12, 0xb9ce,
EN_UHF},
1942 {900000, 2, 7, 15, 0x300, 0x1d12, 0xb9ce,
EN_UHF},
1944 #ifdef CONFIG_BAND_LBAND
1945 {1500000, 4, 0, 20, 0x300, 0x1912, 0x82c9,
EN_LBD},
1946 {1600000, 4, 1, 20, 0x300, 0x1912, 0x82c9,
EN_LBD},
1947 {1800000, 4, 3, 20, 0x300, 0x1912, 0x82c9,
EN_LBD},
1949 #ifdef CONFIG_BAND_SBAND
1950 {2300000, 1, 4, 20, 0x300, 0x2d2A, 0x82c7,
EN_SBD},
1951 {2900000, 1, 7, 20, 0x280, 0x2deb, 0x8347,
EN_SBD},
1955 static const struct dib0090_tuning dib0090_p1g_tuning_table[] = {
1956 #ifdef CONFIG_BAND_CBAND
1957 {170000, 4, 1, 0x820f, 0x300, 0x2d22, 0x82cb,
EN_CAB},
1959 #ifdef CONFIG_BAND_VHF
1960 {184000, 1, 1, 15, 0x300, 0x4d12, 0xb94e,
EN_VHF},
1961 {227000, 1, 3, 15, 0x300, 0x4d12, 0xb94e,
EN_VHF},
1962 {380000, 1, 7, 15, 0x300, 0x4d12, 0xb94e,
EN_VHF},
1964 #ifdef CONFIG_BAND_UHF
1965 {510000, 2, 0, 15, 0x300, 0x1d12, 0xb9ce,
EN_UHF},
1966 {540000, 2, 1, 15, 0x300, 0x1d12, 0xb9ce,
EN_UHF},
1967 {600000, 2, 3, 15, 0x300, 0x1d12, 0xb9ce,
EN_UHF},
1968 {630000, 2, 4, 15, 0x300, 0x1d12, 0xb9ce,
EN_UHF},
1969 {680000, 2, 5, 15, 0x300, 0x1d12, 0xb9ce,
EN_UHF},
1970 {720000, 2, 6, 15, 0x300, 0x1d12, 0xb9ce,
EN_UHF},
1971 {900000, 2, 7, 15, 0x300, 0x1d12, 0xb9ce,
EN_UHF},
1973 #ifdef CONFIG_BAND_LBAND
1974 {1500000, 4, 0, 20, 0x300, 0x1912, 0x82c9,
EN_LBD},
1975 {1600000, 4, 1, 20, 0x300, 0x1912, 0x82c9,
EN_LBD},
1976 {1800000, 4, 3, 20, 0x300, 0x1912, 0x82c9,
EN_LBD},
1978 #ifdef CONFIG_BAND_SBAND
1979 {2300000, 1, 4, 20, 0x300, 0x2d2A, 0x82c7,
EN_SBD},
1980 {2900000, 1, 7, 20, 0x280, 0x2deb, 0x8347,
EN_SBD},
1984 static const struct dib0090_pll dib0090_p1g_pll_table[] = {
1985 #ifdef CONFIG_BAND_CBAND
1986 {57000, 0, 11, 48, 6},
1987 {70000, 1, 11, 48, 6},
1988 {86000, 0, 10, 32, 4},
1989 {105000, 1, 10, 32, 4},
1990 {115000, 0, 9, 24, 6},
1991 {140000, 1, 9, 24, 6},
1992 {170000, 0, 8, 16, 4},
1994 #ifdef CONFIG_BAND_VHF
1995 {200000, 1, 8, 16, 4},
1996 {230000, 0, 7, 12, 6},
1997 {280000, 1, 7, 12, 6},
1998 {340000, 0, 6, 8, 4},
1999 {380000, 1, 6, 8, 4},
2000 {455000, 0, 5, 6, 6},
2002 #ifdef CONFIG_BAND_UHF
2003 {580000, 1, 5, 6, 6},
2004 {680000, 0, 4, 4, 4},
2005 {860000, 1, 4, 4, 4},
2007 #ifdef CONFIG_BAND_LBAND
2008 {1800000, 1, 2, 2, 4},
2010 #ifdef CONFIG_BAND_SBAND
2011 {2900000, 0, 1, 1, 6},
2015 static const struct dib0090_tuning dib0090_p1g_tuning_table_fm_vhf_on_cband[] = {
2016 #ifdef CONFIG_BAND_CBAND
2017 {184000, 4, 3, 0x4187, 0x2c0, 0x2d22, 0x81cb,
EN_CAB},
2018 {227000, 4, 3, 0x4187, 0x2c0, 0x2d22, 0x81cb,
EN_CAB},
2019 {380000, 4, 3, 0x4187, 0x2c0, 0x2d22, 0x81cb,
EN_CAB},
2021 #ifdef CONFIG_BAND_UHF
2022 {520000, 2, 0, 15, 0x300, 0x1d12, 0xb9ce,
EN_UHF},
2023 {550000, 2, 2, 15, 0x300, 0x1d12, 0xb9ce,
EN_UHF},
2024 {650000, 2, 3, 15, 0x300, 0x1d12, 0xb9ce,
EN_UHF},
2025 {750000, 2, 5, 15, 0x300, 0x1d12, 0xb9ce,
EN_UHF},
2026 {850000, 2, 6, 15, 0x300, 0x1d12, 0xb9ce,
EN_UHF},
2027 {900000, 2, 7, 15, 0x300, 0x1d12, 0xb9ce,
EN_UHF},
2029 #ifdef CONFIG_BAND_LBAND
2030 {1500000, 4, 0, 20, 0x300, 0x1912, 0x82c9,
EN_LBD},
2031 {1600000, 4, 1, 20, 0x300, 0x1912, 0x82c9,
EN_LBD},
2032 {1800000, 4, 3, 20, 0x300, 0x1912, 0x82c9,
EN_LBD},
2034 #ifdef CONFIG_BAND_SBAND
2035 {2300000, 1, 4, 20, 0x300, 0x2d2A, 0x82c7,
EN_SBD},
2036 {2900000, 1, 7, 20, 0x280, 0x2deb, 0x8347,
EN_SBD},
2040 static const struct dib0090_tuning dib0090_tuning_table_cband_7090[] = {
2041 #ifdef CONFIG_BAND_CBAND
2042 {300000, 4, 3, 0x018F, 0x2c0, 0x2d22, 0xb9ce,
EN_CAB},
2043 {380000, 4, 10, 0x018F, 0x2c0, 0x2d22, 0xb9ce,
EN_CAB},
2044 {570000, 4, 10, 0x8190, 0x2c0, 0x2d22, 0xb9ce,
EN_CAB},
2045 {858000, 4, 5, 0x8190, 0x2c0, 0x2d22, 0xb9ce,
EN_CAB},
2049 static const struct dib0090_tuning dib0090_tuning_table_cband_7090e_sensitivity[] = {
2050 #ifdef CONFIG_BAND_CBAND
2051 { 300000, 0 , 3, 0x8105, 0x2c0, 0x2d12, 0xb84e,
EN_CAB },
2052 { 380000, 0 , 10, 0x810F, 0x2c0, 0x2d12, 0xb84e,
EN_CAB },
2053 { 600000, 0 , 10, 0x815E, 0x280, 0x2d12, 0xb84e,
EN_CAB },
2054 { 660000, 0 , 5, 0x85E3, 0x280, 0x2d12, 0xb84e,
EN_CAB },
2055 { 720000, 0 , 5, 0x852E, 0x280, 0x2d12, 0xb84e,
EN_CAB },
2056 { 860000, 0 , 4, 0x85E5, 0x280, 0x2d12, 0xb84e,
EN_CAB },
2065 dib0090_tuning_table_cband_7090e_sensitivity;
2066 const struct dib0090_tuning dib0090_tuning_table_cband_7090e_aci[] = {
2067 { 300000, 0 , 3, 0x8165, 0x2c0, 0x2d12, 0xb84e,
EN_CAB },
2068 { 650000, 0 , 4, 0x815B, 0x280, 0x2d12, 0xb84e,
EN_CAB },
2069 { 860000, 0 , 5, 0x84EF, 0x280, 0x2d12, 0xb84e,
EN_CAB },
2075 dprintk(
"%s() function can only be used for dib7090", __func__);
2079 if (cfg_sensitivity)
2080 tune = dib0090_tuning_table_cband_7090e_sensitivity;
2082 tune = dib0090_tuning_table_cband_7090e_aci;
2087 dib0090_write_reg(state, 0x09, (dib0090_read_reg(state, 0x09) & 0x8000)
2089 dib0090_write_reg(state, 0x0b, (dib0090_read_reg(state, 0x0b) & 0xf83f)
2090 | ((tune->
lna_tune << 6) & 0x07c0));
2103 u8 force_soft_search = 0;
2106 force_soft_search = 1;
2109 dprintk(
"Start Captrim search : %s", (force_soft_search == 1) ?
"FORCE SOFT SEARCH" :
"AUTO");
2110 dib0090_write_reg(state, 0x10, 0x2B1);
2111 dib0090_write_reg(state, 0x1e, 0x0032);
2115 if (!state->
identity.p1g || force_soft_search)
2120 if (!state->
identity.p1g || force_soft_search) {
2123 state->
captrim = state->
fcaptrim = dib0090_read_reg(state, 0x18) & 0x7f;
2130 if (state->
identity.p1g && !force_soft_search) {
2133 dib0090_write_reg(state, 0x40, (3 << 7) | (ratio << 2) | (1 << 1) | 1);
2134 dib0090_read_reg(state, 0x40);
2138 dib0090_write_reg(state, 0x18, lo4 | state->
captrim);
2146 if (state->
identity.p1g && !force_soft_search) {
2147 dib0090_write_reg(state, 0x40, 0x18c | (0 << 1) | 0);
2148 dib0090_read_reg(state, 0x40);
2150 state->
fcaptrim = dib0090_read_reg(state, 0x18) & 0x7F;
2156 adc = dib0090_get_slow_adc_val(state);
2164 if (adc >= adc_target) {
2168 adc = adc_target -
adc;
2172 if (adc < state->adc_diff) {
2179 if (state->
step >= 1)
2188 dib0090_write_reg(state, 0x18, lo4 | state->
fcaptrim);
2205 switch (*tune_state) {
2207 state->
wbdmux = dib0090_read_reg(state, 0x10);
2208 dib0090_write_reg(state, 0x10, (state->
wbdmux & ~(0xff << 3)) | (0x8 << 3));
2210 state->
bias = dib0090_read_reg(state, 0x13);
2211 dib0090_write_reg(state, 0x13, state->
bias | (0x3 << 8));
2218 state->
adc_diff = dib0090_get_slow_adc_val(state);
2219 dib0090_write_reg(state, 0x13, (state->
bias & ~(0x3 << 8)) | (0x2 << 8));
2224 val = dib0090_get_slow_adc_val(state);
2233 dib0090_write_reg(state, 0x13, state->
bias);
2234 dib0090_write_reg(state, 0x10, state->
wbdmux);
2238 if (state->
config->analog_output == 0)
2239 dib0090_write_reg(state, 0x23, dib0090_read_reg(state, 0x23) | (1 << 14));
2259 u32 FBDiv, Rest,
FREF, VCOF_kHz = 0;
2272 dib0090_write_reg(state, 0x23, dib0090_read_reg(state, 0x23) & ~(1 << 14));
2275 if (state->
config->analog_output == 0)
2276 dib0090_write_reg(state, 0x23, dib0090_read_reg(state, 0x23) | (1 << 14));
2280 return dib0090_dc_offset_calibration(state, tune_state);
2283 state->
current_rf = state->
fe->dtv_property_cache.frequency / 1000;
2284 return dib0090_wbd_calibration(state, tune_state);
2286 return dib0090_get_temperature(state, tune_state);
2288 return dib0090_captrim_search(state, tune_state);
2293 tmp = dib0090_read_reg(state, 0x39);
2294 if ((tmp >> 10) & 0x1)
2295 dib0090_write_reg(state, 0x39, tmp & ~(1 << 10));
2300 state->
fe->dtv_property_cache.frequency / 1000 + (state->
current_band ==
2302 freq_offset_khz_vhf);
2305 if ((state->
fe->dtv_property_cache.delivery_system ==
SYS_ISDBT && state->
fe->dtv_property_cache.isdbt_sb_mode == 1
2306 && state->
fe->dtv_property_cache.isdbt_partial_reception == 0)) {
2308 u8 found_offset = 0;
2309 u32 margin_khz = 100;
2311 if (LUT_offset !=
NULL) {
2312 while (LUT_offset->
RF_freq != 0xffff) {
2315 && LUT_offset->
std == state->
fe->dtv_property_cache.delivery_system) {
2324 if (found_offset == 0)
2332 tune = dib0090_tuning_table;
2334 tune = dib0090_p1g_tuning_table;
2336 tmp = (state->
identity.version >> 5) & 0x7;
2339 if (state->
config->force_cband_input) {
2343 if (state->
config->is_dib7090e)
2344 tune = dib0090_tuning_table_cband_7090e_sensitivity;
2346 tune = dib0090_tuning_table_cband_7090;
2351 if (state->
config->is_dib7090e)
2352 tune = dib0090_tuning_table_cband_7090e_sensitivity;
2354 tune = dib0090_tuning_table_cband_7090;
2358 if (tmp == 0x4 || tmp == 0x7) {
2363 tune = dib0090_tuning_table_fm_vhf_on_cband;
2365 tune = dib0090_p1g_tuning_table_fm_vhf_on_cband;
2369 pll = dib0090_pll_table;
2371 pll = dib0090_p1g_pll_table;
2382 dib0090_write_reg(state, 0x0b, 0xb800 | (tune->
switch_trim));
2386 FREF = state->
config->io.clock_khz;
2387 if (state->
config->fref_clock_ratio != 0)
2388 FREF /= state->
config->fref_clock_ratio;
2391 Rest = (VCOF_kHz / pll->
topresc) - FBDiv * FREF;
2395 else if (Rest < 2 *
LPF)
2397 else if (Rest > (FREF -
LPF)) {
2400 }
else if (Rest > (FREF - 2 *
LPF))
2401 Rest = FREF - 2 *
LPF;
2402 Rest = (Rest * 6528) / (FREF / 10);
2417 else if (state->
config->analog_output)
2435 if (!state->
config->io.pll_int_loop_filt) {
2438 else if (state->
identity.p1g || (Rest == 0))
2443 lo6 = (state->
config->io.pll_int_loop_filt << 3);
2448 if (state->
config->analog_output)
2449 lo6 |= (1 << 2) | 2;
2452 lo6 |= (1 << 2) | 2;
2454 lo6 |= (1 << 2) | 2;
2458 dib0090_write_reg(state, 0x15, (
u16) FBDiv);
2459 if (state->
config->fref_clock_ratio != 0)
2460 dib0090_write_reg(state, 0x16, (Den << 8) | state->
config->fref_clock_ratio);
2462 dib0090_write_reg(state, 0x16, (Den << 8) | 1);
2463 dib0090_write_reg(state, 0x17, (
u16) Rest);
2464 dib0090_write_reg(state, 0x19, lo5);
2465 dib0090_write_reg(state, 0x1c, lo6);
2468 if (state->
config->analog_output)
2469 lo6 = (lo6 & 0xff9f) | 0x2;
2488 dib0090_write_reg(state, 0x1e, 0x07ff);
2494 dprintk(
"FBDIV: %d, Rest: %d", (
u32) dib0090_read_reg(state, 0x15), (
u32) dib0090_read_reg(state, 0x17));
2495 dprintk(
"Num: %d, Den: %d, SD: %d", (
u32) dib0090_read_reg(state, 0x17), (
u32) (dib0090_read_reg(state, 0x16) >> 8),
2496 (
u32) dib0090_read_reg(state, 0x1c) & 0x3);
2505 state->
wbdmux = (c << 13) | (i << 11) | (
WBD | (state->
config->use_pwm_agc << 1));
2506 dib0090_write_reg(state, 0x10, state->
wbdmux);
2509 dprintk(
"P1G : The cable band is selected and lna_tune = %d", tune->
lna_tune);
2510 dib0090_write_reg(state, 0x09, tune->
lna_bias);
2515 dib0090_write_reg(state, 0x0c, tune->
v2i);
2516 dib0090_write_reg(state, 0x0d, tune->
mix);
2517 dib0090_write_reg(state, 0x0e, tune->
load);
2524 dib0090_set_bandwidth(state);
2577 ret = dib0090_tune(fe);
2589 .name =
"DiBcom DiB0090",
2590 .frequency_min = 45000000,
2591 .frequency_max = 860000000,
2592 .frequency_step = 1000,
2594 .release = dib0090_release,
2596 .init = dib0090_wakeup,
2597 .sleep = dib0090_sleep,
2598 .set_params = dib0090_set_params,
2599 .get_frequency = dib0090_get_frequency,
2604 .name =
"DiBcom DiB0090",
2605 .frequency_min = 45000000,
2606 .frequency_max = 860000000,
2607 .frequency_step = 1000,
2609 .release = dib0090_release,
2614 .get_frequency =
NULL,
2618 {470, 0, 250, 0, 100, 4},
2619 {860, 51, 866, 21, 375, 4},
2620 {1700, 0, 800, 0, 850, 4},
2621 {2900, 0, 250, 0, 100, 6},
2622 {0xFFFF, 0, 0, 0, 0, 0},
2642 if (dib0090_reset(fe) != 0)
2669 if (dib0090_fw_reset_digital(fe, st->
config) != 0)
2672 dprintk(
"DiB0090 FW: successfully identified");