23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/string.h>
26 #include <linux/slab.h>
60 while ((temp_dev !=
NULL) &&
61 ((temp_dev->
internal->i2c_adap != i2c_adap) ||
62 (temp_dev->
internal->i2c_addr != i2c_addr))) {
77 if (del_dev !=
NULL) {
78 if (del_dev == stv090x_first_dev) {
79 stv090x_first_dev = del_dev->
next_dev;
81 while (prev_dev->
next_dev != del_dev)
98 if (new_dev !=
NULL) {
103 if (stv090x_first_dev ==
NULL) {
104 stv090x_first_dev = new_dev;
106 temp_dev = stv090x_first_dev;
119 static const struct stv090x_tab stv090x_s1cn_tab[] = {
175 static const struct stv090x_tab stv090x_s2cn_tab[] = {
234 static const struct stv090x_tab stv090x_rf_tab[] = {
585 {
STV090x_QPSK_12, 0x1f, 0x3f, 0x1e, 0x3f, 0x3d, 0x1f, 0x3d, 0x3e, 0x3d, 0x1e },
586 {
STV090x_QPSK_35, 0x2f, 0x3f, 0x2e, 0x2f, 0x3d, 0x0f, 0x0e, 0x2e, 0x3d, 0x0e },
587 {
STV090x_QPSK_23, 0x2f, 0x3f, 0x2e, 0x2f, 0x0e, 0x0f, 0x0e, 0x1e, 0x3d, 0x3d },
588 {
STV090x_QPSK_34, 0x3f, 0x3f, 0x3e, 0x1f, 0x0e, 0x3e, 0x0e, 0x1e, 0x3d, 0x3d },
589 {
STV090x_QPSK_45, 0x3f, 0x3f, 0x3e, 0x1f, 0x0e, 0x3e, 0x0e, 0x1e, 0x3d, 0x3d },
590 {
STV090x_QPSK_56, 0x3f, 0x3f, 0x3e, 0x1f, 0x0e, 0x3e, 0x0e, 0x1e, 0x3d, 0x3d },
591 {
STV090x_QPSK_89, 0x3f, 0x3f, 0x3e, 0x1f, 0x1e, 0x3e, 0x0e, 0x1e, 0x3d, 0x3d },
592 {
STV090x_QPSK_910, 0x3f, 0x3f, 0x3e, 0x1f, 0x1e, 0x3e, 0x0e, 0x1e, 0x3d, 0x3d },
593 {
STV090x_8PSK_35, 0x3c, 0x3e, 0x1c, 0x2e, 0x0c, 0x1e, 0x2b, 0x2d, 0x1b, 0x1d },
594 {
STV090x_8PSK_23, 0x1d, 0x3e, 0x3c, 0x2e, 0x2c, 0x1e, 0x0c, 0x2d, 0x2b, 0x1d },
595 {
STV090x_8PSK_34, 0x0e, 0x3e, 0x3d, 0x2e, 0x0d, 0x1e, 0x2c, 0x2d, 0x0c, 0x1d },
596 {
STV090x_8PSK_56, 0x2e, 0x3e, 0x1e, 0x2e, 0x2d, 0x1e, 0x3c, 0x2d, 0x2c, 0x1d },
597 {
STV090x_8PSK_89, 0x3e, 0x3e, 0x1e, 0x2e, 0x3d, 0x1e, 0x0d, 0x2d, 0x3c, 0x1d },
598 {
STV090x_8PSK_910, 0x3e, 0x3e, 0x1e, 0x2e, 0x3d, 0x1e, 0x1d, 0x2d, 0x0d, 0x1d }
604 {
STV090x_QPSK_12, 0x3c, 0x2c, 0x0c, 0x2c, 0x1b, 0x2c, 0x1b, 0x1c, 0x0b, 0x3b },
605 {
STV090x_QPSK_35, 0x0d, 0x0d, 0x0c, 0x0d, 0x1b, 0x3c, 0x1b, 0x1c, 0x0b, 0x3b },
606 {
STV090x_QPSK_23, 0x1d, 0x0d, 0x0c, 0x1d, 0x2b, 0x3c, 0x1b, 0x1c, 0x0b, 0x3b },
607 {
STV090x_QPSK_34, 0x1d, 0x1d, 0x0c, 0x1d, 0x2b, 0x3c, 0x1b, 0x1c, 0x0b, 0x3b },
608 {
STV090x_QPSK_45, 0x2d, 0x1d, 0x1c, 0x1d, 0x2b, 0x3c, 0x2b, 0x0c, 0x1b, 0x3b },
609 {
STV090x_QPSK_56, 0x2d, 0x1d, 0x1c, 0x1d, 0x2b, 0x3c, 0x2b, 0x0c, 0x1b, 0x3b },
610 {
STV090x_QPSK_89, 0x3d, 0x2d, 0x1c, 0x1d, 0x3b, 0x3c, 0x2b, 0x0c, 0x1b, 0x3b },
611 {
STV090x_QPSK_910, 0x3d, 0x2d, 0x1c, 0x1d, 0x3b, 0x3c, 0x2b, 0x0c, 0x1b, 0x3b },
612 {
STV090x_8PSK_35, 0x39, 0x29, 0x39, 0x19, 0x19, 0x19, 0x19, 0x19, 0x09, 0x19 },
613 {
STV090x_8PSK_23, 0x2a, 0x39, 0x1a, 0x0a, 0x39, 0x0a, 0x29, 0x39, 0x29, 0x0a },
614 {
STV090x_8PSK_34, 0x2b, 0x3a, 0x1b, 0x1b, 0x3a, 0x1b, 0x1a, 0x0b, 0x1a, 0x3a },
615 {
STV090x_8PSK_56, 0x0c, 0x1b, 0x3b, 0x3b, 0x1b, 0x3b, 0x3a, 0x3b, 0x3a, 0x1b },
616 {
STV090x_8PSK_89, 0x0d, 0x3c, 0x2c, 0x2c, 0x2b, 0x0c, 0x0b, 0x3b, 0x0b, 0x1b },
617 {
STV090x_8PSK_910, 0x0d, 0x0d, 0x2c, 0x3c, 0x3b, 0x1c, 0x0b, 0x3b, 0x0b, 0x1b }
623 {
STV090x_16APSK_23, 0x0c, 0x0c, 0x0c, 0x0c, 0x1d, 0x0c, 0x3c, 0x0c, 0x2c, 0x0c },
624 {
STV090x_16APSK_34, 0x0c, 0x0c, 0x0c, 0x0c, 0x0e, 0x0c, 0x2d, 0x0c, 0x1d, 0x0c },
625 {
STV090x_16APSK_45, 0x0c, 0x0c, 0x0c, 0x0c, 0x1e, 0x0c, 0x3d, 0x0c, 0x2d, 0x0c },
626 {
STV090x_16APSK_56, 0x0c, 0x0c, 0x0c, 0x0c, 0x1e, 0x0c, 0x3d, 0x0c, 0x2d, 0x0c },
627 {
STV090x_16APSK_89, 0x0c, 0x0c, 0x0c, 0x0c, 0x2e, 0x0c, 0x0e, 0x0c, 0x3d, 0x0c },
628 {
STV090x_16APSK_910, 0x0c, 0x0c, 0x0c, 0x0c, 0x2e, 0x0c, 0x0e, 0x0c, 0x3d, 0x0c },
629 {
STV090x_32APSK_34, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c },
630 {
STV090x_32APSK_45, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c },
631 {
STV090x_32APSK_56, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c },
632 {
STV090x_32APSK_89, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c },
633 {
STV090x_32APSK_910, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c }
639 {
STV090x_16APSK_23, 0x0a, 0x0a, 0x0a, 0x0a, 0x1a, 0x0a, 0x3a, 0x0a, 0x2a, 0x0a },
640 {
STV090x_16APSK_34, 0x0a, 0x0a, 0x0a, 0x0a, 0x0b, 0x0a, 0x3b, 0x0a, 0x1b, 0x0a },
641 {
STV090x_16APSK_45, 0x0a, 0x0a, 0x0a, 0x0a, 0x1b, 0x0a, 0x3b, 0x0a, 0x2b, 0x0a },
642 {
STV090x_16APSK_56, 0x0a, 0x0a, 0x0a, 0x0a, 0x1b, 0x0a, 0x3b, 0x0a, 0x2b, 0x0a },
643 {
STV090x_16APSK_89, 0x0a, 0x0a, 0x0a, 0x0a, 0x2b, 0x0a, 0x0c, 0x0a, 0x3b, 0x0a },
644 {
STV090x_16APSK_910, 0x0a, 0x0a, 0x0a, 0x0a, 0x2b, 0x0a, 0x0c, 0x0a, 0x3b, 0x0a },
645 {
STV090x_32APSK_34, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a },
646 {
STV090x_32APSK_45, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a },
647 {
STV090x_32APSK_56, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a },
648 {
STV090x_32APSK_89, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a },
649 {
STV090x_32APSK_910, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a }
654 {
STV090x_QPSK_14, 0x0f, 0x3f, 0x0e, 0x3f, 0x2d, 0x2f, 0x2d, 0x1f, 0x3d, 0x3e },
655 {
STV090x_QPSK_13, 0x0f, 0x3f, 0x0e, 0x3f, 0x2d, 0x2f, 0x3d, 0x0f, 0x3d, 0x2e },
656 {
STV090x_QPSK_25, 0x1f, 0x3f, 0x1e, 0x3f, 0x3d, 0x1f, 0x3d, 0x3e, 0x3d, 0x2e }
661 {
STV090x_QPSK_14, 0x0c, 0x3c, 0x0b, 0x3c, 0x2a, 0x2c, 0x2a, 0x1c, 0x3a, 0x3b },
662 {
STV090x_QPSK_13, 0x0c, 0x3c, 0x0b, 0x3c, 0x2a, 0x2c, 0x3a, 0x0c, 0x3a, 0x2b },
663 {
STV090x_QPSK_25, 0x1c, 0x3c, 0x1b, 0x3c, 0x3a, 0x1c, 0x3a, 0x3b, 0x3a, 0x2b }
684 static inline s32 comp2(
s32 __x,
s32 __width)
689 return (__x >= (1 << (__width - 1))) ? (__x - (1 << __width)) : __x;
697 u8 b0[] = { reg >> 8, reg & 0xff };
701 { .addr = config->
address, .flags = 0, .buf = b0, .len = 2 },
709 "Read error, Reg=[0x%02x], Status=%d",
718 return (
unsigned int)
buf;
730 memcpy(&buf[2], data, count);
736 for (i = 0; i <
count; i++)
744 dprintk(
FE_ERROR, 1,
"Reg=[0x%04x], Data=[0x%02x ...], Count=%u, Status=%d",
745 reg, data[0], count, ret);
752 static int stv090x_write_reg(
struct stv090x_state *state,
unsigned int reg,
u8 data)
754 return stv090x_write_regs(state, reg, &data, 1);
771 if (state->
config->tuner_i2c_lock)
792 if (state->
config->tuner_i2c_lock)
801 if (state->
config->tuner_i2c_lock)
808 static void stv090x_get_lock_tmg(
struct stv090x_state *state)
810 switch (state->
algo) {
813 if (state->
srate <= 1500000) {
816 }
else if (state->
srate <= 5000000) {
829 if (state->
srate <= 1000000) {
832 }
else if (state->
srate <= 2000000) {
835 }
else if (state->
srate <= 5000000) {
838 }
else if (state->
srate <= 10000000) {
841 }
else if (state->
srate <= 20000000) {
859 if (srate > 60000000) {
861 sym /= (state->
internal->mclk >> 12);
862 }
else if (srate > 6000000) {
864 sym /= (state->
internal->mclk >> 10);
867 sym /= (state->
internal->mclk >> 7);
885 srate = 105 * (srate / 100);
886 if (srate > 60000000) {
888 sym /= (state->
internal->mclk >> 12);
889 }
else if (srate > 6000000) {
891 sym /= (state->
internal->mclk >> 10);
894 sym /= (state->
internal->mclk >> 7);
919 srate = 95 * (srate / 100);
920 if (srate > 60000000) {
922 sym /= (state->
internal->mclk >> 12);
923 }
else if (srate > 6000000) {
925 sym /= (state->
internal->mclk >> 10);
928 sym /= (state->
internal->mclk >> 7);
958 return srate + (srate *
ro) / 100;
961 static int stv090x_set_vit_thacq(
struct stv090x_state *state)
981 static int stv090x_set_vit_thtracq(
struct stv090x_state *state)
1013 switch (state->
fec) {
1048 switch (state->
fec) {
1119 static int stv090x_activate_modcod(
struct stv090x_state *state)
1160 static int stv090x_activate_modcod_single(
struct stv090x_state *state)
1203 static int stv090x_vitclk_ctl(
struct stv090x_state *state,
int enable)
1207 switch (state->
demod) {
1237 static int stv090x_dvbs_track_crl(
struct stv090x_state *state)
1239 if (state->
internal->dev_ver >= 0x30) {
1241 if (state->
srate >= 15000000) {
1246 }
else if ((state->
srate >= 7000000) && (15000000 > state->
srate)) {
1251 }
else if (state->
srate < 7000000) {
1271 static int stv090x_delivery_search(
struct stv090x_state *state)
1287 if (stv090x_vitclk_ctl(state, 0) < 0)
1290 if (stv090x_dvbs_track_crl(state) < 0)
1296 if (stv090x_set_vit_thacq(state) < 0)
1298 if (stv090x_set_viterbi(state) < 0)
1313 if (stv090x_vitclk_ctl(state, 1) < 0)
1321 if (state->
internal->dev_ver <= 0x20) {
1333 if (stv090x_activate_modcod(state) < 0)
1340 if (stv090x_activate_modcod_single(state) < 0)
1344 if (stv090x_set_vit_thtracq(state) < 0)
1361 if (stv090x_vitclk_ctl(state, 0) < 0)
1364 if (stv090x_dvbs_track_crl(state) < 0)
1367 if (state->
internal->dev_ver <= 0x20) {
1379 if (stv090x_activate_modcod(state) < 0)
1386 if (stv090x_activate_modcod_single(state) < 0)
1390 if (stv090x_set_vit_thacq(state) < 0)
1393 if (stv090x_set_viterbi(state) < 0)
1403 static int stv090x_start_search(
struct stv090x_state *state)
1414 if (state->
internal->dev_ver <= 0x20) {
1415 if (state->
srate <= 5000000) {
1441 if (state->
srate <= 5000000) {
1457 freq_abs = 1000 << 16;
1458 freq_abs /= (state->
internal->mclk / 1000);
1459 freq = (
s16) freq_abs;
1467 freq_abs = freq_abs << 16;
1468 freq_abs /= (state->
internal->mclk / 1000);
1469 freq = (
s16) freq_abs;
1491 if (state->
internal->dev_ver >= 0x20) {
1528 if (state->
internal->dev_ver >= 0x20) {
1530 if (state->
srate < 2000000) {
1531 if (state->
internal->dev_ver <= 0x20) {
1542 }
else if (state->
srate < 10000000) {
1554 if (state->
srate < 10000000) {
1563 switch (state->
algo) {
1591 static int stv090x_get_agc2_min_level(
struct stv090x_state *state)
1593 u32 agc2_min = 0xffff, agc2 = 0, freq_init, freq_step,
reg;
1614 if (stv090x_set_srate(state, 1000000) < 0)
1622 freq_step = (1000000 * 256) / (state->
internal->mclk / 256);
1625 for (i = 0; i <
steps; i++) {
1627 freq_init = freq_init + (freq_step *
i);
1629 freq_init = freq_init - (freq_step *
i);
1644 for (j = 0; j < 10; j++) {
1649 if (agc2 < agc2_min)
1662 s32 srate, int_1, int_2, tmp_1, tmp_2;
1669 srate = ((r3 << 24) | (r2 << 16) | (r1 << 8) | r0);
1672 int_2 = srate >> 16;
1674 tmp_1 = clk % 0x10000;
1675 tmp_2 = srate % 0x10000;
1677 srate = (int_1 * int_2) +
1678 ((int_1 * tmp_2) >> 16) +
1679 ((int_2 * tmp_1) >> 16);
1688 int tmg_lock = 0,
i;
1690 u32 srate_coarse = 0, agc2 = 0, car_step = 1200,
reg;
1693 if (state->
internal->dev_ver >= 0x30)
1729 if (state->
internal->dev_ver >= 0x30) {
1735 }
else if (state->
internal->dev_ver >= 0x20) {
1742 if (state->
srate <= 2000000)
1744 else if (state->
srate <= 5000000)
1746 else if (state->
srate <= 12000000)
1751 steps = -1 + ((state->
search_range / 1000) / car_step);
1753 steps = (2 *
steps) + 1;
1756 else if (steps > 10) {
1764 while ((!tmg_lock) && (cur_step <
steps)) {
1779 for (i = 0; i < 10; i++) {
1787 srate_coarse = stv090x_get_srate(state, state->
internal->mclk);
1790 if ((tmg_cpt >= 5) && (agc2 < agc2th) &&
1791 (srate_coarse < 50000000) && (srate_coarse > 850000))
1793 else if (cur_step < steps) {
1795 freq += cur_step * car_step;
1797 freq -= cur_step * car_step;
1800 if (stv090x_i2c_gate_ctrl(state, 1) < 0)
1803 if (state->
config->tuner_set_frequency) {
1804 if (state->
config->tuner_set_frequency(fe, freq) < 0)
1808 if (state->
config->tuner_set_bandwidth) {
1813 if (stv090x_i2c_gate_ctrl(state, 0) < 0)
1818 if (stv090x_i2c_gate_ctrl(state, 1) < 0)
1821 if (state->
config->tuner_get_status) {
1822 if (state->
config->tuner_get_status(fe, ®) < 0)
1831 if (stv090x_i2c_gate_ctrl(state, 0) < 0)
1839 srate_coarse = stv090x_get_srate(state, state->
internal->mclk);
1841 return srate_coarse;
1844 stv090x_i2c_gate_ctrl(state, 0);
1852 u32 srate_coarse, freq_coarse, sym,
reg;
1854 srate_coarse = stv090x_get_srate(state, state->
internal->mclk);
1857 sym = 13 * (srate_coarse / 10);
1859 if (sym < state->srate)
1880 if (state->
internal->dev_ver >= 0x30) {
1883 }
else if (state->
internal->dev_ver >= 0x20) {
1888 if (srate_coarse > 3000000) {
1889 sym = 13 * (srate_coarse / 10);
1890 sym = (sym / 1000) * 65536;
1891 sym /= (state->
internal->mclk / 1000);
1896 sym = 10 * (srate_coarse / 13);
1897 sym = (sym / 1000) * 65536;
1898 sym /= (state->
internal->mclk / 1000);
1903 sym = (srate_coarse / 1000) * 65536;
1904 sym /= (state->
internal->mclk / 1000);
1910 sym = 13 * (srate_coarse / 10);
1911 sym = (sym / 100) * 65536;
1912 sym /= (state->
internal->mclk / 100);
1917 sym = 10 * (srate_coarse / 14);
1918 sym = (sym / 100) * 65536;
1919 sym /= (state->
internal->mclk / 100);
1924 sym = (srate_coarse / 100) * 65536;
1925 sym /= (state->
internal->mclk / 100);
1941 return srate_coarse;
1954 while ((timer < timeout) && (!lock)) {
1982 static int stv090x_blind_search(
struct stv090x_state *state)
1984 u32 agc2,
reg, srate_coarse;
1985 s32 cpt_fail, agc2_ovflw,
i;
1986 u8 k_ref, k_max, k_min;
1987 int coarse_fail = 0;
1993 agc2 = stv090x_get_agc2_min_level(state);
1999 if (state->
internal->dev_ver <= 0x20) {
2011 if (state->
internal->dev_ver >= 0x20) {
2026 if (stv090x_srate_srch_coarse(state) != 0) {
2027 srate_coarse = stv090x_srate_srch_fine(state);
2028 if (srate_coarse != 0) {
2029 stv090x_get_lock_tmg(state);
2030 lock = stv090x_get_dmdlock(state,
2038 for (i = 0; i < 10; i++) {
2049 if ((cpt_fail > 7) || (agc2_ovflw > 7))
2055 }
while ((k_ref >= k_min) && (!lock) && (!coarse_fail));
2069 u8 freq, tmg_thh, tmg_thl;
2103 for (i = 0; i < 10; i++) {
2133 static int stv090x_get_coldlock(
struct stv090x_state *state,
s32 timeout_dmd)
2138 s32 car_step,
steps, cur_step, dir,
freq, timeout_lock;
2141 if (state->
srate >= 10000000)
2142 timeout_lock = timeout_dmd / 3;
2144 timeout_lock = timeout_dmd / 2;
2146 lock = stv090x_get_dmdlock(state, timeout_lock);
2148 if (state->
srate >= 10000000) {
2149 if (stv090x_chk_tmg(state)) {
2154 lock = stv090x_get_dmdlock(state, timeout_dmd);
2159 if (state->
srate <= 4000000)
2161 else if (state->
srate <= 7000000)
2163 else if (state->
srate <= 10000000)
2170 steps = 2 * (steps + 1);
2173 else if (steps > 12)
2182 while ((cur_step <= steps) && (!lock)) {
2184 freq += cur_step * car_step;
2186 freq -= cur_step * car_step;
2189 if (stv090x_i2c_gate_ctrl(state, 1) < 0)
2192 if (state->
config->tuner_set_frequency) {
2193 if (state->
config->tuner_set_frequency(fe, freq) < 0)
2197 if (state->
config->tuner_set_bandwidth) {
2202 if (stv090x_i2c_gate_ctrl(state, 0) < 0)
2207 if (stv090x_i2c_gate_ctrl(state, 1) < 0)
2210 if (state->
config->tuner_get_status) {
2211 if (state->
config->tuner_get_status(fe, ®) < 0)
2220 if (stv090x_i2c_gate_ctrl(state, 0) < 0)
2232 lock = stv090x_get_dmdlock(state, (timeout_dmd / 3));
2244 stv090x_i2c_gate_ctrl(state, 0);
2250 static int stv090x_get_loop_params(
struct stv090x_state *state,
s32 *freq_inc,
s32 *timeout_sw,
s32 *steps)
2252 s32 timeout,
inc, steps_max, srate, car_max;
2254 srate = state->
srate;
2256 car_max += car_max / 10;
2257 car_max = 65536 * (car_max / 2);
2258 car_max /= (state->
internal->mclk / 1000);
2260 if (car_max > 0x4000)
2264 inc /= state->
internal->mclk / 1000;
2288 if ((inc > car_max) || (inc < 0))
2293 timeout /= (srate / 1000);
2295 if ((timeout > 100) || (timeout < 0))
2298 steps_max = (car_max /
inc) + 1;
2299 if ((steps_max > 100) || (steps_max < 0)) {
2301 inc = car_max / steps_max;
2304 *timeout_sw = timeout;
2312 s32 offst_car, agc2, car_max;
2317 offst_car = comp2(offst_car, 16);
2323 car_max += (car_max / 10);
2324 car_max = (65536 * car_max / 2);
2325 car_max /= state->
internal->mclk / 1000;
2327 if (car_max > 0x4000)
2330 if ((agc2 > 0x2000) || (offst_car > 2 * car_max) || (offst_car < -2 * car_max)) {
2341 static int stv090x_search_car_loop(
struct stv090x_state *state,
s32 inc,
s32 timeout,
int zigzag,
s32 steps_max)
2343 int no_signal, lock = 0;
2344 s32 cpt_step = 0, offst_freq, car_max;
2348 car_max += (car_max / 10);
2349 car_max = (65536 * car_max / 2);
2350 car_max /= (state->
internal->mclk / 1000);
2351 if (car_max > 0x4000)
2357 offst_freq = -car_max +
inc;
2375 if (offst_freq >= 0)
2376 offst_freq = -offst_freq - 2 *
inc;
2378 offst_freq = -offst_freq;
2380 offst_freq += 2 *
inc;
2385 lock = stv090x_get_dmdlock(state, timeout);
2386 no_signal = stv090x_chk_signal(state);
2390 ((offst_freq - inc) < car_max) &&
2391 ((offst_freq + inc) > -car_max) &&
2392 (cpt_step < steps_max));
2407 int no_signal, zigzag, lock = 0;
2410 s32 dvbs2_fly_wheel;
2411 s32 inc, timeout_step, trials, steps_max;
2414 stv090x_get_loop_params(state, &inc, &timeout_step, &steps_max);
2420 if (state->
internal->dev_ver >= 0x20) {
2431 if (state->
internal->dev_ver >= 0x20) {
2444 if (state->
internal->dev_ver >= 0x20) {
2459 lock = stv090x_search_car_loop(state, inc, timeout_step, zigzag, steps_max);
2460 no_signal = stv090x_chk_signal(state);
2464 if (lock || no_signal || (trials == 2)) {
2466 if (state->
internal->dev_ver >= 0x20) {
2479 if (dvbs2_fly_wheel < 0xd) {
2484 if (dvbs2_fly_wheel < 0xd) {
2488 if (state->
internal->dev_ver >= 0x20) {
2499 }
while ((!lock) && (trials < 2) && (!no_signal));
2531 s32 derot, int_1, int_2, tmp_1, tmp_2;
2537 derot = comp2(derot, 24);
2539 int_2 = derot >> 12;
2542 tmp_1 = mclk % 0x1000;
2543 tmp_2 = derot % 0x1000;
2545 derot = (int_1 * int_2) +
2546 ((int_1 * tmp_2) >> 12) +
2547 ((int_2 * tmp_1) >> 12);
2598 s32 i = 0, offst_freq;
2605 while ((i <= 50) && (tmg != 0) && (tmg != 0xff)) {
2611 state->
delsys = stv090x_get_std(state);
2613 if (stv090x_i2c_gate_ctrl(state, 1) < 0)
2616 if (state->
config->tuner_get_frequency) {
2621 if (stv090x_i2c_gate_ctrl(state, 0) < 0)
2624 offst_freq = stv090x_get_car_freq(state, state->
internal->mclk) / 1000;
2627 if (stv090x_get_viterbi(state) < 0)
2641 if (stv090x_i2c_gate_ctrl(state, 1) < 0)
2644 if (state->
config->tuner_get_frequency) {
2649 if (stv090x_i2c_gate_ctrl(state, 0) < 0)
2654 else if (
abs(offst_freq) <= (stv090x_car_width(state->
srate, state->
rolloff) / 2000))
2668 stv090x_i2c_gate_ctrl(state, 0);
2682 offst_tmg = comp2(offst_tmg, 24);
2686 offst_tmg = ((
s32) srate * 10) / ((
s32) 0x1000000 / offst_tmg);
2698 if (state->
internal->dev_ver == 0x20) {
2699 car_loop = stv090x_s2_crl_cut20;
2700 car_loop_qpsk_low = stv090x_s2_lowqpsk_crl_cut20;
2701 car_loop_apsk_low = stv090x_s2_apsk_crl_cut20;
2704 car_loop = stv090x_s2_crl_cut30;
2705 car_loop_qpsk_low = stv090x_s2_lowqpsk_crl_cut30;
2706 car_loop_apsk_low = stv090x_s2_apsk_crl_cut30;
2711 while ((i < 3) && (modcod != car_loop_qpsk_low[i].modcod))
2719 while ((i < 14) && (modcod != car_loop[i].modcod))
2724 while ((i < 11) && (modcod != car_loop_apsk_low[i].modcod))
2734 if (state->
srate <= 3000000)
2736 else if (state->
srate <= 7000000)
2738 else if (state->
srate <= 15000000)
2740 else if (state->
srate <= 25000000)
2745 if (state->
srate <= 3000000)
2747 else if (state->
srate <= 7000000)
2749 else if (state->
srate <= 15000000)
2751 else if (state->
srate <= 25000000)
2759 if (state->
srate <= 3000000)
2761 else if (state->
srate <= 7000000)
2763 else if (state->
srate <= 15000000)
2765 else if (state->
srate <= 25000000)
2770 if (state->
srate <= 3000000)
2772 else if (state->
srate <= 7000000)
2774 else if (state->
srate <= 15000000)
2776 else if (state->
srate <= 25000000)
2782 if (state->
srate <= 3000000)
2784 else if (state->
srate <= 7000000)
2786 else if (state->
srate <= 15000000)
2788 else if (state->
srate <= 25000000)
2819 if (state->
internal->dev_ver >= 0x30) {
2821 short_crl = stv090x_s2_short_crl_cut30;
2824 short_crl = stv090x_s2_short_crl_cut20;
2827 if (state->
srate <= 3000000)
2829 else if (state->
srate <= 7000000)
2831 else if (state->
srate <= 15000000)
2833 else if (state->
srate <= 25000000)
2841 static int stv090x_optimize_track(
struct stv090x_state *state)
2847 s32 srate, pilots, aclc, f_1, f_0, i = 0, blind_tune = 0;
2850 srate = stv090x_get_srate(state, state->
internal->mclk);
2851 srate += stv090x_get_tmgoffst(state, srate);
2869 if (state->
internal->dev_ver >= 0x30) {
2870 if (stv090x_get_viterbi(state) < 0)
2896 if (state->
internal->dev_ver >= 0x30) {
2906 aclc = stv090x_optimize_carloop(state, modcod, pilots);
2930 aclc = stv090x_optimize_carloop_short(state);
2979 if (stv090x_set_srate(state, srate) < 0)
2983 if (stv090x_dvbs_track_crl(state) < 0)
2987 if (state->
internal->dev_ver >= 0x20) {
3009 if ((state->
internal->dev_ver >= 0x20) || (blind_tune == 1) ||
3010 (state->
srate < 10000000)) {
3016 state->
tuner_bw = stv090x_car_width(srate, state->
rolloff) + 10000000;
3018 if ((state->
internal->dev_ver >= 0x20) || (blind_tune == 1)) {
3022 if (stv090x_i2c_gate_ctrl(state, 1) < 0)
3025 if (state->
config->tuner_set_bandwidth) {
3030 if (stv090x_i2c_gate_ctrl(state, 0) < 0)
3040 stv090x_get_lock_tmg(state);
3042 if (!(stv090x_get_dmdlock(state, (state->
DemodTimeout / 2)))) {
3054 while ((!(stv090x_get_dmdlock(state, (state->
DemodTimeout / 2)))) && (i <= 2)) {
3070 if (state->
internal->dev_ver >= 0x20) {
3076 stv090x_set_vit_thtracq(state);
3081 stv090x_i2c_gate_ctrl(state, 0);
3089 s32 timer = 0, lock = 0,
stat;
3092 while ((timer < timeout) && (!lock)) {
3121 static int stv090x_get_lock(
struct stv090x_state *state,
s32 timeout_dmd,
s32 timeout_fec)
3127 lock = stv090x_get_dmdlock(state, timeout_dmd);
3129 lock = stv090x_get_feclock(state, timeout_fec);
3134 while ((timer < timeout_fec) && (!lock)) {
3145 static int stv090x_set_s2rolloff(
struct stv090x_state *state)
3149 if (state->
internal->dev_ver <= 0x20) {
3174 s32 agc1_power, power_iq = 0,
i;
3175 int lock = 0, low_sr = 0;
3185 if (state->
internal->dev_ver >= 0x20) {
3186 if (state->
srate > 5000000) {
3195 stv090x_get_lock_tmg(state);
3203 if (stv090x_set_srate(state, 1000000) < 0)
3212 if (state->
srate < 2000000) {
3225 if (state->
internal->dev_ver >= 0x20) {
3240 if (stv090x_set_srate(state, state->
srate) < 0)
3243 if (stv090x_set_max_srate(state, state->
internal->mclk,
3246 if (stv090x_set_min_srate(state, state->
internal->mclk,
3250 if (state->
srate >= 10000000)
3257 if (stv090x_i2c_gate_ctrl(state, 1) < 0)
3260 if (state->
config->tuner_set_bbgain) {
3261 reg = state->
config->tuner_bbgain;
3264 if (state->
config->tuner_set_bbgain(fe, reg) < 0)
3268 if (state->
config->tuner_set_frequency) {
3273 if (state->
config->tuner_set_bandwidth) {
3278 if (stv090x_i2c_gate_ctrl(state, 0) < 0)
3283 if (state->
config->tuner_get_status) {
3284 if (stv090x_i2c_gate_ctrl(state, 1) < 0)
3286 if (state->
config->tuner_get_status(fe, ®) < 0)
3288 if (stv090x_i2c_gate_ctrl(state, 0) < 0)
3303 if (agc1_power == 0) {
3307 for (i = 0; i < 5; i++) {
3322 if (state->
internal->dev_ver <= 0x20) {
3332 if (stv090x_delivery_search(state) < 0)
3336 if (stv090x_start_search(state) < 0)
3342 return signal_state;
3345 lock = stv090x_blind_search(state);
3348 lock = stv090x_get_coldlock(state, state->
DemodTimeout);
3351 lock = stv090x_get_dmdlock(state, state->
DemodTimeout);
3355 if (stv090x_chk_tmg(state))
3356 lock = stv090x_sw_algo(state);
3361 signal_state = stv090x_get_sig_params(state);
3364 stv090x_optimize_track(state);
3366 if (state->
internal->dev_ver >= 0x20) {
3386 lock = stv090x_get_lock(state, state->
FecTimeout,
3390 stv090x_set_s2rolloff(state);
3416 stv090x_chk_signal(state);
3419 return signal_state;
3422 stv090x_i2c_gate_ctrl(state, 0);
3428 static int stv090x_set_mis(
struct stv090x_state *state,
int mis)
3432 if (mis < 0 || mis > 255) {
3469 if (state->
srate > 10000000) {
3477 stv090x_set_mis(state, props->
stream_id);
3505 switch (search_state) {
3546 s32 count_4, count_3, count_2, count_1, count_0,
count;
3550 stv090x_read_status(fe, &status);
3564 *per = ((h << 16) | (m << 8) |
l);
3572 if ((!count_4) && (!count_3)) {
3573 count = (count_2 & 0xff) << 16;
3574 count |= (count_1 & 0xff) << 8;
3575 count |= count_0 & 0xff;
3593 static int stv090x_table_lookup(
const struct stv090x_tab *tab,
int max,
int val)
3598 if ((val >= tab[min].
read && val < tab[max].
read) ||
3599 (val >= tab[max].read && val < tab[min].read)) {
3600 while ((max - min) > 1) {
3601 med = (max +
min) / 2;
3602 if ((val >= tab[min].read && val < tab[med].read) ||
3608 res = ((val - tab[
min].
read) *
3609 (tab[max].real - tab[min].real) /
3613 if (tab[min].read < tab[max].read) {
3614 if (val < tab[min].read)
3616 else if (val >= tab[max].read)
3619 if (val >= tab[min].read)
3621 else if (val < tab[max].read)
3629 static int stv090x_read_signal_strength(
struct dvb_frontend *fe,
u16 *strength)
3633 s32 agc_0, agc_1, agc;
3642 str = stv090x_table_lookup(stv090x_rf_tab,
3644 if (agc > stv090x_rf_tab[0].read)
3646 else if (agc < stv090x_rf_tab[
ARRAY_SIZE(stv090x_rf_tab) - 1].read)
3648 *strength = (str + 100) * 0xFFFF / 100;
3657 s32 val_0, val_1, val = 0;
3668 for (i = 0; i < 16; i++) {
3678 div = stv090x_s2cn_tab[0].
read -
3679 stv090x_s2cn_tab[last].
read;
3680 *cnr = 0xFFFF - ((val * 0xFFFF) / div);
3690 for (i = 0; i < 16; i++) {
3700 div = stv090x_s1cn_tab[0].
read -
3701 stv090x_s1cn_tab[last].
read;
3702 *cnr = 0xFFFF - ((val * 0xFFFF) / div);
3760 (state->
config->diseqc_envelope_mode) ? 4 : 2);
3772 for (i = 0; i < cmd->
msg_len; i++) {
3789 while ((!idle) && (i < 10)) {
3805 u32 reg, idle = 0, fifo_full = 1;
3812 mode = (state->
config->diseqc_envelope_mode) ? 5 : 3;
3815 mode = (state->
config->diseqc_envelope_mode) ? 4 : 2;
3846 while ((!idle) && (i < 10)) {
3862 u32 reg = 0, i = 0, rx_end = 0;
3864 while ((rx_end != 1) && (i < 10)) {
3873 for (i = 0; i < reply->
msg_len; i++)
3884 u8 full_standby = 0;
3886 if (stv090x_i2c_gate_ctrl(state, 1) < 0)
3889 if (state->
config->tuner_sleep) {
3890 if (state->
config->tuner_sleep(fe) < 0)
3894 if (stv090x_i2c_gate_ctrl(state, 0) < 0)
3903 switch (state->
demod) {
4007 stv090x_i2c_gate_ctrl(state, 0);
4031 switch (state->
demod) {
4116 if (state->
internal->num_used <= 0) {
4133 switch (ldpc_mode) {
4189 if (stv090x_stop_modcod(state) < 0)
4191 if (stv090x_activate_modcod_single(state) < 0)
4237 return (div + 1) * config->
xtal /
ratio;
4248 div = ((clk_sel *
mclk) / config->
xtal) - 1;
4255 state->
internal->mclk = stv090x_get_mclk(state);
4258 div = state->
internal->mclk / 704000;
4274 if (state->
internal->dev_ver >= 0x20) {
4275 switch (state->
config->ts1_mode) {
4278 switch (state->
config->ts2_mode) {
4308 switch (state->
config->ts2_mode) {
4325 switch (state->
config->ts1_mode) {
4328 switch (state->
config->ts2_mode) {
4357 switch (state->
config->ts2_mode) {
4373 switch (state->
config->ts1_mode) {
4414 switch (state->
config->ts2_mode) {
4455 if (state->
config->ts1_clk > 0) {
4458 switch (state->
config->ts1_mode) {
4463 (state->
config->ts1_clk / 4);
4472 (state->
config->ts1_clk / 32);
4487 if (state->
config->ts2_clk > 0) {
4490 switch (state->
config->ts2_mode) {
4495 (state->
config->ts2_clk / 4);
4504 (state->
config->ts2_clk / 32);
4551 if (stv090x_i2c_gate_ctrl(state, 1) < 0)
4559 if (stv090x_i2c_gate_ctrl(state, 0) < 0)
4562 stv090x_set_mclk(state, 135000000, config->
xtal);
4567 stv090x_get_mclk(state);
4570 if (stv090x_wakeup(fe) < 0) {
4575 if (stv090x_ldpc_mode(state, state->
demod_mode) < 0)
4587 if (stv090x_i2c_gate_ctrl(state, 1) < 0)
4600 if (stv090x_i2c_gate_ctrl(state, 0) < 0)
4603 if (stv090x_set_tspath(state) < 0)
4609 stv090x_i2c_gate_ctrl(state, 0);
4621 unsigned long t1_size = 0, t2_size = 0;
4628 stv090x_initval = stv0900_initval;
4630 stv090x_cut20_val = stv0900_cut20_val;
4634 stv090x_initval = stv0903_initval;
4636 stv090x_cut20_val = stv0903_cut20_val;
4674 for (i = 0; i < t1_size; i++) {
4675 if (stv090x_write_reg(state, stv090x_initval[i].
addr, stv090x_initval[i].data) < 0)
4680 if (state->
internal->dev_ver >= 0x20) {
4686 for (i = 0; i < t2_size; i++) {
4687 if (stv090x_write_reg(state, stv090x_cut20_val[i].
addr, stv090x_cut20_val[i].data) < 0)
4691 }
else if (state->
internal->dev_ver < 0x20) {
4696 }
else if (state->
internal->dev_ver > 0x30) {
4698 dprintk(
FE_ERROR, 1,
"INFO: Cut: 0x%02x probably incomplete support!",
4744 .name =
"STV090x Multistandard",
4745 .frequency_min = 950000,
4746 .frequency_max = 2150000,
4747 .frequency_stepsize = 0,
4748 .frequency_tolerance = 0,
4749 .symbol_rate_min = 1000000,
4750 .symbol_rate_max = 45000000,
4757 .release = stv090x_release,
4758 .init = stv090x_init,
4760 .sleep = stv090x_sleep,
4761 .get_frontend_algo = stv090x_frontend_algo,
4763 .diseqc_send_master_cmd = stv090x_send_diseqc_msg,
4764 .diseqc_send_burst = stv090x_send_diseqc_burst,
4765 .diseqc_recv_slave_reply = stv090x_recv_slave_reply,
4766 .set_tone = stv090x_set_tone,
4769 .read_status = stv090x_read_status,
4770 .read_ber = stv090x_read_per,
4771 .read_signal_strength = stv090x_read_signal_strength,
4772 .read_snr = stv090x_read_cnr,
4792 state->
demod = demod;
4797 temp_int = find_dev(state->
i2c,
4809 temp_int = append_internal(state->
internal);
4824 if (stv090x_setup(&state->
frontend) < 0) {
4830 if (state->
internal->dev_ver >= 0x30)