26 #include <linux/kernel.h>
27 #include <linux/module.h>
28 #include <linux/string.h>
29 #include <linux/slab.h>
30 #include <linux/i2c.h>
42 #define dprintk(args...) \
45 printk(KERN_DEBUG args); \
551 #define RF_LOOKUP_TABLE_SIZE 31
552 #define RF_LOOKUP_TABLE2_SIZE 16
556 48, 50, 51, 53, 54, 56, 57, 58, 60, 61, 62, 63,
557 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75,
558 76, 77, 78, 80, 83, 85, 88,
560 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
561 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 46, 47,
562 49, 50, 52, 53, 54, 55, 56,
568 28, 29, 31, 32, 34, 35, 36, 37,
569 38, 39, 40, 41, 42, 43, 44, 45,
571 57, 58, 59, 60, 61, 62, 63, 64,
572 65, 66, 67, 68, 69, 70, 71, 72,
772 .addr = state->
config->demod_address,
781 memcpy(buf + 2, data, len);
795 return stv0367_writeregs(state, reg, &data, 1);
809 .addr = state->
config->demod_address,
832 u8 position = 0,
i = 0;
834 (*mask) = label & 0xff;
836 while ((position == 0) && (
i < 8)) {
837 position = ((*mask) >>
i) & 0x01;
848 reg = stv0367_readreg(state, (label >> 16) & 0xffff);
849 extract_mask_pos(label, &mask, &pos);
851 val = mask & (val <<
pos);
853 reg = (reg & (~mask)) |
val;
854 stv0367_writereg(state, (label >> 16) & 0xffff, reg);
858 static void stv0367_setbits(
u8 *reg,
u32 label,
u8 val)
862 extract_mask_pos(label, &mask, &pos);
864 val = mask & (val <<
pos);
866 (*reg) = ((*reg) & (~mask)) |
val;
874 extract_mask_pos(label, &mask, &pos);
876 val = stv0367_readreg(state, label >> 16);
877 val = (val &
mask) >> pos;
886 extract_mask_pos(label, &mask, &pos);
888 return (reg & mask) >>
pos;
922 frontend_ops = &fe->
ops;
932 dprintk(
"%s: frequency=%d\n", __func__, freq);
940 static u16 CellsCoeffs_8MHz_367cofdm[3][6][5] = {
942 {0x10EF, 0xE205, 0x10EF, 0xCE49, 0x6DA7},
943 {0x2151, 0xc557, 0x2151, 0xc705, 0x6f93},
944 {0x2503, 0xc000, 0x2503, 0xc375, 0x7194},
945 {0x20E9, 0xca94, 0x20e9, 0xc153, 0x7194},
946 {0x06EF, 0xF852, 0x06EF, 0xC057, 0x7207},
947 {0x0000, 0x0ECC, 0x0ECC, 0x0000, 0x3647}
949 {0x10A0, 0xE2AF, 0x10A1, 0xCE76, 0x6D6D},
950 {0x20DC, 0xC676, 0x20D9, 0xC80A, 0x6F29},
951 {0x2532, 0xC000, 0x251D, 0xC391, 0x706F},
952 {0x1F7A, 0xCD2B, 0x2032, 0xC15E, 0x711F},
953 {0x0698, 0xFA5E, 0x0568, 0xC059, 0x7193},
954 {0x0000, 0x0918, 0x149C, 0x0000, 0x3642}
956 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000},
957 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000},
958 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000},
959 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000},
960 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000},
961 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000}
965 static u16 CellsCoeffs_7MHz_367cofdm[3][6][5] = {
967 {0x12CA, 0xDDAF, 0x12CA, 0xCCEB, 0x6FB1},
968 {0x2329, 0xC000, 0x2329, 0xC6B0, 0x725F},
969 {0x2394, 0xC000, 0x2394, 0xC2C7, 0x7410},
970 {0x251C, 0xC000, 0x251C, 0xC103, 0x74D9},
971 {0x0804, 0xF546, 0x0804, 0xC040, 0x7544},
972 {0x0000, 0x0CD9, 0x0CD9, 0x0000, 0x370A}
974 {0x1285, 0xDE47, 0x1285, 0xCD17, 0x6F76},
975 {0x234C, 0xC000, 0x2348, 0xC6DA, 0x7206},
976 {0x23B4, 0xC000, 0x23AC, 0xC2DB, 0x73B3},
977 {0x253D, 0xC000, 0x25B6, 0xC10B, 0x747F},
978 {0x0721, 0xF79C, 0x065F, 0xC041, 0x74EB},
979 {0x0000, 0x08FA, 0x1162, 0x0000, 0x36FF}
981 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000},
982 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000},
983 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000},
984 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000},
985 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000},
986 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000}
990 static u16 CellsCoeffs_6MHz_367cofdm[3][6][5] = {
992 {0x1699, 0xD5B8, 0x1699, 0xCBC3, 0x713B},
993 {0x2245, 0xC000, 0x2245, 0xC568, 0x74D5},
994 {0x227F, 0xC000, 0x227F, 0xC1FC, 0x76C6},
995 {0x235E, 0xC000, 0x235E, 0xC0A7, 0x778A},
996 {0x0ECB, 0xEA0B, 0x0ECB, 0xC027, 0x77DD},
997 {0x0000, 0x0B68, 0x0B68, 0x0000, 0xC89A},
999 {0x1655, 0xD64E, 0x1658, 0xCBEF, 0x70FE},
1000 {0x225E, 0xC000, 0x2256, 0xC589, 0x7489},
1001 {0x2293, 0xC000, 0x2295, 0xC209, 0x767E},
1002 {0x2377, 0xC000, 0x23AA, 0xC0AB, 0x7746},
1003 {0x0DC7, 0xEBC8, 0x0D07, 0xC027, 0x7799},
1004 {0x0000, 0x0888, 0x0E9C, 0x0000, 0x3757}
1007 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000},
1008 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000},
1009 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000},
1010 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000},
1011 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000},
1012 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000}
1036 mclk_Hz = ((ExtClk_Hz / 2) * n) / (m * (1 <<
p));
1038 dprintk(
"N=%d M=%d P=%d mclk_Hz=%d ExtClk_Hz=%d\n",
1039 n, m, p, mclk_Hz, ExtClk_Hz);
1041 mclk_Hz = ExtClk_Hz;
1043 dprintk(
"%s: mclk_Hz=%d\n", __func__, mclk_Hz);
1048 static int stv0367ter_filt_coeff_init(
struct stv0367_state *state,
1049 u16 CellsCoeffs[3][6][5],
u32 DemodXtal)
1055 freq = stv0367ter_get_mclk(state, DemodXtal);
1057 if (freq == 53125000)
1059 else if (freq == 54000000)
1061 else if (freq == 52500000)
1066 for (i = 1; i <= 6; i++) {
1069 for (j = 1; j <= 5; j++) {
1070 stv0367_writereg(state,
1072 MSB(CellsCoeffs[k][i-1][j-1]));
1073 stv0367_writereg(state,
1075 LSB(CellsCoeffs[k][i-1][j-1]));
1083 static void stv0367ter_agc_iir_lock_detect_set(
struct stv0367_state *state)
1111 static int stv0367_iir_filt_init(
struct stv0367_state *state,
u8 Bandwidth,
1118 switch (Bandwidth) {
1120 if (!stv0367ter_filt_coeff_init(state,
1121 CellsCoeffs_6MHz_367cofdm,
1126 if (!stv0367ter_filt_coeff_init(state,
1127 CellsCoeffs_7MHz_367cofdm,
1132 if (!stv0367ter_filt_coeff_init(state,
1133 CellsCoeffs_8MHz_367cofdm,
1146 static void stv0367ter_agc_iir_rst(
struct stv0367_state *state)
1167 static int stv0367ter_duration(
s32 mode,
int tempo1,
int tempo2,
int tempo3)
1169 int local_tempo = 0;
1172 local_tempo = tempo1;
1175 local_tempo = tempo2;
1179 local_tempo = tempo3;
1193 unsigned short int SYR_var;
1200 while ((!SYR_var) && (wd > 0)) {
1211 dprintk(
"stv0367ter_check_syr SYRStatus %s\n",
1212 SYR_var == 0 ?
"No Symbol" :
"OK");
1222 s32 CPAMPvalue = 0, CPAMPStatus, CPAMPMin;
1245 dprintk(
"%s: CPAMPMin=%d wd=%d\n", __func__, CPAMPMin, wd);
1248 while ((CPAMPvalue < CPAMPMin) && (wd > 0)) {
1254 dprintk(
"******last CPAMPvalue= %d at wd=%d\n", CPAMPvalue, wd);
1255 if (CPAMPvalue < CPAMPMin) {
1270 short int wd, tempo;
1271 u8 try, u_var1 = 0, u_var2 = 0, u_var3 = 0, u_var4 = 0,
mode, guard;
1285 if (state->
config->if_iq_mode != 0)
1302 if (stv0367ter_check_cpamp(state, mode) ==
1316 dprintk(
"LOCK OK! mode=%d SYR_STAT=0x%x R367TER_STATUS=0x%x\n",
1321 dprintk(
"PRVIT=0x%x I2CRPT=0x%x\n", tmp, tmp2);
1324 dprintk(
"GAIN_SRC1=0x%x\n", tmp);
1326 if ((mode != 0) && (mode != 1) && (mode != 2))
1359 u_var1 = stv0367_readbits(state,
F367TER_LK);
1364 wd = stv0367ter_duration(mode, 125, 500, 250);
1365 tempo = stv0367ter_duration(mode, 4, 16, 8);
1368 while (((!u_var1) || (!u_var2) || (!u_var3)) && (wd >= 0)) {
1371 u_var1 = stv0367_readbits(state,
F367TER_LK);
1417 wd = stv0367ter_duration(mode, 125, 500, 250);
1420 while ((!u_var4) && (wd >= 0)) {
1443 dprintk(
"FE_TER_LOCKOK !!!\n");
1449 static void stv0367ter_set_ts_mode(
struct stv0367_state *state,
1473 static void stv0367ter_set_clk_pol(
struct stv0367_state *state,
1507 static int stv0367ter_standby(
struct dvb_frontend *fe,
u8 standby_on)
1528 return stv0367ter_standby(fe, 1);
1539 ter_state->
pBER = 0;
1542 stv0367_writereg(state, def0367ter[i].
addr,
1543 def0367ter[i].
value);
1545 switch (state->
config->xtal) {
1554 dprintk(
"FE_STV0367TER_SetCLKgen for 27Mhz\n");
1570 stv0367ter_set_ts_mode(state, state->
config->ts_mode);
1571 stv0367ter_set_clk_pol(state, state->
config->clk_pol);
1585 int offset = 0, tempo = 0;
1589 s32 timing_offset = 0;
1590 u32 trl_nomrate = 0, InternalFreq = 0,
temp = 0;
1598 switch (state->
config->if_iq_mode) {
1600 dprintk(
"ALGO: FE_TER_NORMAL_IF_TUNER selected\n");
1606 dprintk(
"ALGO: FE_TER_LONGPATH_IF_TUNER selected\n");
1612 dprintk(
"ALGO: FE_TER_IQ_TUNER selected\n");
1626 dprintk(
"%s: inversion AUTO\n", __func__);
1648 (ter_state->
pBW != ter_state->
bw)) {
1649 stv0367ter_agc_iir_lock_detect_set(state);
1662 if (!stv0367_iir_filt_init(state, ter_state->
bw,
1666 ter_state->
pBW = ter_state->
bw;
1668 stv0367ter_agc_iir_rst(state);
1676 InternalFreq = stv0367ter_get_mclk(state, state->
config->xtal) / 1000;
1678 ((((ter_state->
bw * 64 * (1 << 15) * 100)
1679 / (InternalFreq)) * 10) / 7);
1689 temp = (
int)(((1 << 17) * ter_state->
bw * 1000) / (7 * (InternalFreq)));
1696 ((InternalFreq - state->
config->if_khz) * (1 << 16)
1705 ter_state->
pBER = 0;
1730 if (offset > 8388607)
1733 offset = offset * 2 / 16384;
1736 offset = (offset * 4464) / 1000;
1738 offset = (offset * 223) / 100;
1740 offset = (offset * 111) / 100;
1744 (stv0367_readbits(state,
1746 offset = offset * -1;
1749 if (ter_state->
bw == 6)
1750 offset = (offset * 6) / 8;
1751 else if (ter_state->
bw == 7)
1752 offset = (offset * 7) / 8;
1757 while ((timing_offset == 0) && (tempo > 0)) {
1761 + 256 * stv0367_readbits(state,
1763 if (timing_offset >= 32768)
1764 timing_offset -= 65536;
1765 trl_nomrate = (512 * stv0367_readbits(state,
1770 timing_offset = ((signed)(1000000 / trl_nomrate) *
1771 timing_offset) / 2048;
1775 if (timing_offset <= 0) {
1776 timing_offset = (timing_offset - 11) / 22;
1779 timing_offset = (timing_offset + 11) / 22;
1783 for (counter = 0; counter <
abs(timing_offset); counter++) {
1784 trl_nomrate +=
step;
1806 static int stv0367ter_set_frontend(
struct dvb_frontend *fe)
1818 if (fe->
ops.tuner_ops.set_params) {
1819 if (fe->
ops.i2c_gate_ctrl)
1820 fe->
ops.i2c_gate_ctrl(fe, 1);
1821 fe->
ops.tuner_ops.set_params(fe);
1822 if (fe->
ops.i2c_gate_ctrl)
1823 fe->
ops.i2c_gate_ctrl(fe, 0);
1888 stv0367ter_algo(fe);
1894 SenseTrials[
index] = SenseTrials[0];
1895 SenseTrials[(index + 1) % 2] = (SenseTrials[1] + 1) % 2;
1926 static int stv0367ter_get_frontend(
struct dvb_frontend *fe)
1934 int constell = 0,
Data = 0;
1936 p->
frequency = stv0367_get_tuner_freq(fe);
1943 else if (constell == 1)
2038 *snr = snru32 / 1000;
2051 locked = (stv0367_readbits(state,
F367TER_LK));
2083 dprintk(
"%s: stv0367 has locked\n", __func__);
2093 u32 Errors = 0, tber = 0, temporary = 0;
2094 int abc = 0, def = 0;
2103 + ((
u32)stv0367_readbits(state,
2107 tber = ter_state->
pBER;
2116 }
else if (abc == 0x7) {
2118 temporary = (Errors * 1000000000) / (8 * (1 << 14));
2119 temporary = temporary;
2120 }
else if (Errors <= 42) {
2121 temporary = (Errors * 100000000) / (8 * (1 << 14));
2122 temporary = temporary * 10;
2123 }
else if (Errors <= 429) {
2124 temporary = (Errors * 10000000) / (8 * (1 << 14));
2125 temporary = temporary * 100;
2126 }
else if (Errors <= 4294) {
2127 temporary = (Errors * 1000000) / (8 * (1 << 14));
2128 temporary = temporary * 1000;
2129 }
else if (Errors <= 42949) {
2130 temporary = (Errors * 100000) / (8 * (1 << 14));
2131 temporary = temporary * 10000;
2132 }
else if (Errors <= 429496) {
2133 temporary = (Errors * 10000) / (8 * (1 << 14));
2134 temporary = temporary * 100000;
2136 temporary = (Errors * 1000) / (8 * (1 << 14));
2137 temporary = temporary * 100000;
2146 tber = temporary / 4;
2149 tber = temporary / 16;
2152 tber = temporary / 64;
2155 tber = temporary / 256;
2160 if ((Errors < 4294967) && (Errors > 429496))
2166 ter_state->
pBER = tber;
2176 u32 Errors = 0, Per = 0, temporary = 0;
2177 int abc = 0, def = 0, cpt = 0;
2180 (cpt < 400)) || ((Errors == 0) && (cpt < 400))) {
2194 else if (abc == 0x9) {
2196 temporary = (Errors * 1000000000) / (8 * (1 << 8));
2197 temporary = temporary;
2198 }
else if (Errors <= 42) {
2199 temporary = (Errors * 100000000) / (8 * (1 << 8));
2200 temporary = temporary * 10;
2201 }
else if (Errors <= 429) {
2202 temporary = (Errors * 10000000) / (8 * (1 << 8));
2203 temporary = temporary * 100;
2204 }
else if (Errors <= 4294) {
2205 temporary = (Errors * 1000000) / (8 * (1 << 8));
2206 temporary = temporary * 1000;
2207 }
else if (Errors <= 42949) {
2208 temporary = (Errors * 100000) / (8 * (1 << 8));
2209 temporary = temporary * 10000;
2211 temporary = (Errors * 10000) / (8 * (1 << 8));
2212 temporary = temporary * 100000;
2221 Per = temporary / 4;
2224 Per = temporary / 16;
2227 Per = temporary / 64;
2230 Per = temporary / 256;
2236 ter_state->
pPER = Per;
2241 static int stv0367_get_tune_settings(
struct dvb_frontend *fe,
2264 .name =
"ST STV0367 DVB-T",
2265 .frequency_min = 47000000,
2266 .frequency_max = 862000000,
2267 .frequency_stepsize = 15625,
2268 .frequency_tolerance = 0,
2278 .release = stv0367_release,
2280 .sleep = stv0367ter_sleep,
2281 .i2c_gate_ctrl = stv0367ter_gate_ctrl,
2282 .set_frontend = stv0367ter_set_frontend,
2283 .get_frontend = stv0367ter_get_frontend,
2284 .get_tune_settings = stv0367_get_tune_settings,
2285 .read_status = stv0367ter_read_status,
2286 .read_ber = stv0367ter_read_ber,
2288 .read_snr = stv0367ter_read_snr,
2289 .read_ucblocks = stv0367ter_read_ucblocks,
2303 if (ter_state ==
NULL)
2310 state->
fe.ops = stv0367ter_ops;
2311 state->
fe.demodulator_priv =
state;
2312 state->
chip_id = stv0367_readreg(state, 0xf000);
2329 static int stv0367cab_gate_ctrl(
struct dvb_frontend *fe,
int enable)
2361 mclk_Hz = ((ExtClk_Hz / 2) * N) / (M * (1 <<
P));
2362 dprintk(
"stv0367cab_get_mclk BYPASS_PLLXN mclk_Hz=%d\n",
2365 mclk_Hz = ExtClk_Hz;
2367 dprintk(
"stv0367cab_get_mclk final mclk_Hz=%d\n", mclk_Hz);
2374 u32 ADCClk_Hz = ExtClk_Hz;
2376 ADCClk_Hz = stv0367cab_get_mclk(fe, ExtClk_Hz);
2416 if (SymbolRate > 45000000) {
2420 }
else if (SymbolRate > 25000000) {
2438 if (SymbolRate > 45000000)
2440 else if (SymbolRate > 25000000)
2453 if (SymbolRate > 45000000)
2455 else if (SymbolRate > 25000000)
2479 u32 adc_hz,
s32 derot_hz)
2484 adc_khz = adc_hz / 1000;
2486 dprintk(
"%s: adc_hz=%d derot_hz=%d\n", __func__, adc_hz, derot_hz);
2489 if (derot_hz < 1000000)
2490 derot_hz = adc_hz / 4;
2491 if (derot_hz > adc_hz)
2492 derot_hz = derot_hz - adc_hz;
2493 sampled_if = (
u32)derot_hz / 1000;
2494 sampled_if *= 32768;
2495 sampled_if /= adc_khz;
2499 if (sampled_if > 8388607)
2500 sampled_if = 8388607;
2502 dprintk(
"%s: sampled_if=0x%x\n", __func__, sampled_if);
2520 sampled_if *= (adc_hz / 1000);
2522 sampled_if /= 32768;
2528 u32 mclk_hz,
u32 SymbolRate,
2531 u32 QamSizeCorr = 0;
2532 u32 u32_tmp = 0, u32_tmp1 = 0;
2569 u32_tmp = 256 * SymbolRate;
2570 u32_tmp = u32_tmp / adc_hz;
2575 adp_khz = (mclk_hz >> 1) / 1000;
2577 u32_tmp = SymbolRate;
2578 u32_tmp1 = SymbolRate;
2580 if (u32_tmp < 2097152) {
2583 u32_tmp = u32_tmp / adp_khz;
2584 u32_tmp = u32_tmp * 16384;
2586 u32_tmp = u32_tmp * 8;
2592 u32_tmp1 = u32_tmp1 / adp_khz;
2593 u32_tmp1 *= QamSizeCorr * 9;
2594 u32_tmp1 = u32_tmp1 / 10000000;
2596 }
else if (u32_tmp < 4194304) {
2599 u32_tmp = u32_tmp / adp_khz;
2600 u32_tmp = u32_tmp * 16384;
2602 u32_tmp = u32_tmp * 16;
2608 u32_tmp1 = u32_tmp1 / adp_khz;
2609 u32_tmp1 *= QamSizeCorr * 9;
2610 u32_tmp1 = u32_tmp1 / 5000000;
2611 }
else if (u32_tmp < 8388607) {
2614 u32_tmp = u32_tmp / adp_khz;
2615 u32_tmp = u32_tmp * 16384;
2617 u32_tmp = u32_tmp * 32;
2623 u32_tmp1 = u32_tmp1 / adp_khz;
2624 u32_tmp1 *= QamSizeCorr * 9;
2625 u32_tmp1 = u32_tmp1 / 2500000;
2629 u32_tmp = u32_tmp / adp_khz;
2630 u32_tmp = u32_tmp * 16384;
2632 u32_tmp = u32_tmp * 64;
2638 u32_tmp1 = u32_tmp1 / adp_khz;
2639 u32_tmp1 *= QamSizeCorr * 9;
2640 u32_tmp1 = u32_tmp1 / 1250000;
2647 stv0367cab_SetIirAdjacentcoefficient(state, mclk_hz,
2652 stv0367cab_SetAllPasscoefficient(state, mclk_hz, SymbolRate);
2680 adp_khz = (mclk_hz >> 1) / 1000;
2682 if (regsym < 134217728) {
2683 regsym = regsym * 32;
2684 regsym = regsym / 32768;
2685 regsym = adp_khz * regsym;
2686 regsym = regsym / 128;
2689 }
else if (regsym < 268435456) {
2690 regsym = regsym * 16;
2691 regsym = regsym / 32768;
2692 regsym = adp_khz * regsym;
2693 regsym = regsym / 128;
2696 }
else if (regsym < 536870912) {
2697 regsym = regsym * 8;
2698 regsym = regsym / 32768;
2699 regsym = adp_khz * regsym;
2700 regsym = regsym / 128;
2704 regsym = regsym * 4;
2705 regsym = regsym / 32768;
2706 regsym = adp_khz * regsym;
2707 regsym = regsym / 128;
2725 dprintk(
"%s: stv0367 has locked\n", __func__);
2731 static int stv0367cab_standby(
struct dvb_frontend *fe,
u8 standby_on)
2762 return stv0367cab_standby(fe, 1);
2774 stv0367_writereg(state, def0367cab[i].
addr,
2775 def0367cab[i].
value);
2777 switch (state->
config->ts_mode) {
2779 dprintk(
"Setting TSMode = STV0367_DVBCI_CLOCK\n");
2792 switch (state->
config->clk_pol) {
2812 cab_state->
mclk = stv0367cab_get_mclk(fe, state->
config->xtal);
2813 cab_state->
adc_clk = stv0367cab_get_adc_freq(fe, state->
config->xtal);
2823 u32 QAMFEC_Lock, QAM_Lock, u32_tmp,
2824 LockTime, TRLTimeOut, AGCTimeOut, CRLSymbols,
2825 CRLTimeOut, EQLTimeOut, DemodTimeOut, FECTimeOut;
2847 CRLSymbols = 150000;
2851 CRLSymbols = 250000;
2855 CRLSymbols = 200000;
2859 CRLSymbols = 250000;
2863 CRLSymbols = 250000;
2867 CRLSymbols = 200000;
2872 if (pIntParams->search_range < 0) {
2873 CRLTimeOut = (25 * CRLSymbols *
2874 (-pIntParams->search_range / 1000)) /
2875 (pIntParams->symbol_rate / 1000);
2878 CRLTimeOut = (25 * CRLSymbols * (cab_state->
search_range / 1000)) /
2881 CRLTimeOut = (1000 * CRLTimeOut) / p->
symbol_rate;
2883 if (CRLTimeOut < 50)
2890 DemodTimeOut = AGCTimeOut + TRLTimeOut + CRLTimeOut + EQLTimeOut;
2892 dprintk(
"%s: DemodTimeOut=%d\n", __func__, DemodTimeOut);
2908 stv0367cab_set_derot_freq(state, cab_state->
adc_clk,
2917 tuner_lock = stv0367cab_tuner_get_status(fe);
2918 if (tuner_lock == 0)
2919 return FE_367CAB_NOTUNER;
2927 if ((LockTime >= (DemodTimeOut - EQLTimeOut)) &&
2933 LockTime = DemodTimeOut;
2934 else if ((LockTime >= (AGCTimeOut + TRLTimeOut)) &&
2942 LockTime = DemodTimeOut;
2943 u32_tmp = stv0367_readbits(state,
2945 (stv0367_readbits(state,
2947 (stv0367_readbits(state,
2949 if (u32_tmp >= 131072)
2950 u32_tmp = 262144 - u32_tmp;
2951 u32_tmp = u32_tmp / (1 << (11 - stv0367_readbits(state,
2954 if (u32_tmp < stv0367_readbits(state,
2956 256 * stv0367_readbits(state,
2963 dprintk(
"QAM_Lock=0x%x LockTime=%d\n", QAM_Lock, LockTime);
2966 dprintk(
"R367CAB_IT_STATUS1=0x%x\n", tmp);
2968 }
while (((QAM_Lock != 0x0c) && (QAM_Lock != 0x0b)) &&
2969 (LockTime < DemodTimeOut));
2971 dprintk(
"QAM_Lock=0x%x\n", QAM_Lock);
2974 dprintk(
"R367CAB_IT_STATUS1=0x%x\n", tmp);
2976 dprintk(
"R367CAB_IT_STATUS2=0x%x\n", tmp);
2978 tmp = stv0367cab_get_derot_freq(state, cab_state->
adc_clk);
2979 dprintk(
"stv0367cab_get_derot_freq=0x%x\n", tmp);
2981 if ((QAM_Lock == 0x0c) || (QAM_Lock == 0x0b)) {
2987 QAMFEC_Lock = stv0367_readbits(state,
2989 }
while (!QAMFEC_Lock && (LockTime < FECTimeOut));
2996 cab_state->
spect_inv = stv0367_readbits(state,
3000 if (state->
config->if_khz != 0) {
3003 FE_Cab_TunerGetFrequency(pIntParams->hTuner)
3004 - stv0367cab_get_derot_freq(state, cab_state->
adc_clk)
3008 FE_Cab_TunerGetFrequency(pIntParams->hTuner)
3009 - stv0367cab_get_derot_freq(state, cab_state->
adc_clk)
3014 FE_Cab_TunerGetFrequency(pIntParams->hTuner) +
3015 stv0367cab_get_derot_freq(state,
3020 cab_state->
symbol_rate = stv0367cab_GetSymbolRate(state,
3077 static int stv0367cab_set_frontend(
struct dvb_frontend *fe)
3084 dprintk(
"%s: freq = %d, srate = %d\n", __func__,
3112 if (fe->
ops.tuner_ops.set_params) {
3113 if (fe->
ops.i2c_gate_ctrl)
3114 fe->
ops.i2c_gate_ctrl(fe, 1);
3115 fe->
ops.tuner_ops.set_params(fe);
3116 if (fe->
ops.i2c_gate_ctrl)
3117 fe->
ops.i2c_gate_ctrl(fe, 0);
3125 stv0367cab_set_srate(state,
3131 cab_state->
state = stv0367cab_algo(state, p);
3135 static int stv0367cab_get_frontend(
struct dvb_frontend *fe)
3168 p->
frequency = stv0367_get_tuner_freq(fe);
3172 if (state->
config->if_khz == 0) {
3174 (stv0367cab_get_derot_freq(state, cab_state->
adc_clk) -
3181 - stv0367cab_get_derot_freq(state, cab_state->
adc_clk)
3185 - stv0367cab_get_derot_freq(state, cab_state->
adc_clk));
3191 void stv0367cab_GetErrorCount(state,
enum stv0367cab_mod QAMSize,
3194 stv0367cab_OptimiseNByteAndGetBER(state, QAMSize, symbol_rate, Monitor_results);
3195 stv0367cab_GetPacketsCount(state, Monitor_results);
3210 s32 RfAgcPwm = 0, IfAgcPwm = 0;
3218 RfAgcPwm = 100 * RfAgcPwm / 1023;
3223 if (IfAgcPwm >= 2048)
3228 IfAgcPwm = 100 * IfAgcPwm / 4095;
3231 if (RfAgcPwm < 90 && IfAgcPwm < 28) {
3238 if (i == RF_LOOKUP_TABLE_SIZE)
3247 if (i == RF_LOOKUP_TABLE2_SIZE)
3253 static int stv0367cab_read_strength(
struct dvb_frontend *fe,
u16 *strength)
3257 s32 signal = stv0367cab_get_rf_lvl(state);
3259 dprintk(
"%s: signal=%d dBm\n", __func__, signal);
3264 *strength = (22 + signal) * (-1311);
3266 dprintk(
"%s: strength=%d\n", __func__, (*strength));
3274 u32 noisepercentage;
3310 for (i = 0; i < 10; i++) {
3324 noisepercentage = 100;
3325 else if (
temp >= 3981)
3326 noisepercentage = 93;
3327 else if (
temp >= 3162)
3328 noisepercentage = 86;
3329 else if (
temp >= 2512)
3330 noisepercentage = 79;
3331 else if (
temp >= 1995)
3332 noisepercentage = 72;
3333 else if (
temp >= 1585)
3334 noisepercentage = 65;
3335 else if (
temp >= 1259)
3336 noisepercentage = 58;
3337 else if (
temp >= 1000)
3338 noisepercentage = 50;
3339 else if (
temp >= 794)
3340 noisepercentage = 43;
3341 else if (
temp >= 501)
3342 noisepercentage = 36;
3343 else if (
temp >= 316)
3344 noisepercentage = 29;
3345 else if (
temp >= 200)
3346 noisepercentage = 22;
3347 else if (
temp >= 158)
3348 noisepercentage = 14;
3349 else if (
temp >= 126)
3350 noisepercentage = 7;
3352 noisepercentage = 0;
3354 dprintk(
"%s: noisepercentage=%d\n", __func__, noisepercentage);
3356 *snr = (noisepercentage * 65535) / 100;
3361 static int stv0367cab_read_ucblcks(
struct dvb_frontend *fe,
u32 *ucblocks)
3364 int corrected, tscount;
3373 dprintk(
"%s: uncorrected blocks=%d corrected blocks=%d tscount=%d\n",
3374 __func__, *ucblocks, corrected, tscount);
3382 .name =
"ST STV0367 DVB-C",
3383 .frequency_min = 47000000,
3384 .frequency_max = 862000000,
3385 .frequency_stepsize = 62500,
3386 .symbol_rate_min = 870000,
3387 .symbol_rate_max = 11700000,
3393 .release = stv0367_release,
3395 .sleep = stv0367cab_sleep,
3396 .i2c_gate_ctrl = stv0367cab_gate_ctrl,
3397 .set_frontend = stv0367cab_set_frontend,
3398 .get_frontend = stv0367cab_get_frontend,
3399 .read_status = stv0367cab_read_status,
3401 .read_signal_strength = stv0367cab_read_strength,
3402 .read_snr = stv0367cab_read_snr,
3403 .read_ucblocks = stv0367cab_read_ucblcks,
3404 .get_tune_settings = stv0367_get_tune_settings,
3418 if (cab_state ==
NULL)
3426 state->
fe.ops = stv0367cab_ops;
3427 state->
fe.demodulator_priv =
state;
3428 state->
chip_id = stv0367_readreg(state, 0xf000);