Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

V4L/DVB (13975): [STV090x] Added internal structure with shared settings and data.

As the STV0900 features two demodulation paths in one chip there is
some information used by both instances of the driver when used in
dual mode. This information is now shared in an internal structure
referenced by I2C adapter and address.

Do initialisation of the demodulator only once when used in dual mode.
Moved global mutex demod_lock to internal structure.
Moved dev_ver and mclk to internal structure.
Removed unused tuner_refclk from stv090x_state.

Signed-off-by: Andreas Regel <andreas.regel@gmx.de>
Signed-off-by: Manu Abraham <manu@linuxtv.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

authored by

Andreas Regel and committed by
Mauro Carvalho Chehab
97f7a2ae b79c6df7

+216 -92
+204 -85
drivers/media/dvb/frontends/stv090x.c
··· 37 37 static unsigned int verbose; 38 38 module_param(verbose, int, 0644); 39 39 40 - struct mutex demod_lock; 40 + /* internal params node */ 41 + struct stv090x_dev { 42 + /* pointer for internal params, one for each pair of demods */ 43 + struct stv090x_internal *internal; 44 + struct stv090x_dev *next_dev; 45 + }; 46 + 47 + /* first internal params */ 48 + static struct stv090x_dev *stv090x_first_dev; 49 + 50 + /* find chip by i2c adapter and i2c address */ 51 + static struct stv090x_dev *find_dev(struct i2c_adapter *i2c_adap, 52 + u8 i2c_addr) 53 + { 54 + struct stv090x_dev *temp_dev = stv090x_first_dev; 55 + 56 + /* 57 + Search of the last stv0900 chip or 58 + find it by i2c adapter and i2c address */ 59 + while ((temp_dev != NULL) && 60 + ((temp_dev->internal->i2c_adap != i2c_adap) || 61 + (temp_dev->internal->i2c_addr != i2c_addr))) { 62 + 63 + temp_dev = temp_dev->next_dev; 64 + } 65 + 66 + return temp_dev; 67 + } 68 + 69 + /* deallocating chip */ 70 + static void remove_dev(struct stv090x_internal *internal) 71 + { 72 + struct stv090x_dev *prev_dev = stv090x_first_dev; 73 + struct stv090x_dev *del_dev = find_dev(internal->i2c_adap, 74 + internal->i2c_addr); 75 + 76 + if (del_dev != NULL) { 77 + if (del_dev == stv090x_first_dev) { 78 + stv090x_first_dev = del_dev->next_dev; 79 + } else { 80 + while (prev_dev->next_dev != del_dev) 81 + prev_dev = prev_dev->next_dev; 82 + 83 + prev_dev->next_dev = del_dev->next_dev; 84 + } 85 + 86 + kfree(del_dev); 87 + } 88 + } 89 + 90 + /* allocating new chip */ 91 + static struct stv090x_dev *append_internal(struct stv090x_internal *internal) 92 + { 93 + struct stv090x_dev *new_dev; 94 + struct stv090x_dev *temp_dev; 95 + 96 + new_dev = kmalloc(sizeof(struct stv090x_dev), GFP_KERNEL); 97 + if (new_dev != NULL) { 98 + new_dev->internal = internal; 99 + new_dev->next_dev = NULL; 100 + 101 + /* append to list */ 102 + if (stv090x_first_dev == NULL) { 103 + stv090x_first_dev = new_dev; 104 + } else { 105 + temp_dev = stv090x_first_dev; 106 + while (temp_dev->next_dev != NULL) 107 + temp_dev = temp_dev->next_dev; 108 + 109 + temp_dev->next_dev = new_dev; 110 + } 111 + } 112 + 113 + return new_dev; 114 + } 115 + 41 116 42 117 /* DVBS1 and DSS C/N Lookup table */ 43 118 static const struct stv090x_tab stv090x_s1cn_tab[] = { ··· 830 755 831 756 if (srate > 60000000) { 832 757 sym = (srate << 4); /* SR * 2^16 / master_clk */ 833 - sym /= (state->mclk >> 12); 758 + sym /= (state->internal->mclk >> 12); 834 759 } else if (srate > 6000000) { 835 760 sym = (srate << 6); 836 - sym /= (state->mclk >> 10); 761 + sym /= (state->internal->mclk >> 10); 837 762 } else { 838 763 sym = (srate << 9); 839 - sym /= (state->mclk >> 7); 764 + sym /= (state->internal->mclk >> 7); 840 765 } 841 766 842 767 if (STV090x_WRITE_DEMOD(state, SFRINIT1, (sym >> 8) & 0x7f) < 0) /* MSB */ ··· 857 782 srate = 105 * (srate / 100); 858 783 if (srate > 60000000) { 859 784 sym = (srate << 4); /* SR * 2^16 / master_clk */ 860 - sym /= (state->mclk >> 12); 785 + sym /= (state->internal->mclk >> 12); 861 786 } else if (srate > 6000000) { 862 787 sym = (srate << 6); 863 - sym /= (state->mclk >> 10); 788 + sym /= (state->internal->mclk >> 10); 864 789 } else { 865 790 sym = (srate << 9); 866 - sym /= (state->mclk >> 7); 791 + sym /= (state->internal->mclk >> 7); 867 792 } 868 793 869 794 if (sym < 0x7fff) { ··· 891 816 srate = 95 * (srate / 100); 892 817 if (srate > 60000000) { 893 818 sym = (srate << 4); /* SR * 2^16 / master_clk */ 894 - sym /= (state->mclk >> 12); 819 + sym /= (state->internal->mclk >> 12); 895 820 } else if (srate > 6000000) { 896 821 sym = (srate << 6); 897 - sym /= (state->mclk >> 10); 822 + sym /= (state->internal->mclk >> 10); 898 823 } else { 899 824 sym = (srate << 9); 900 - sym /= (state->mclk >> 7); 825 + sym /= (state->internal->mclk >> 7); 901 826 } 902 827 903 828 if (STV090x_WRITE_DEMOD(state, SFRLOW1, ((sym >> 8) & 0x7f)) < 0) /* MSB */ ··· 1178 1103 1179 1104 switch (state->demod) { 1180 1105 case STV090x_DEMODULATOR_0: 1181 - mutex_lock(&demod_lock); 1106 + mutex_lock(&state->internal->demod_lock); 1182 1107 reg = stv090x_read_reg(state, STV090x_STOPCLK2); 1183 1108 STV090x_SETFIELD(reg, STOP_CLKVIT1_FIELD, enable); 1184 1109 if (stv090x_write_reg(state, STV090x_STOPCLK2, reg) < 0) 1185 1110 goto err; 1186 - mutex_unlock(&demod_lock); 1111 + mutex_unlock(&state->internal->demod_lock); 1187 1112 break; 1188 1113 1189 1114 case STV090x_DEMODULATOR_1: 1190 - mutex_lock(&demod_lock); 1115 + mutex_lock(&state->internal->demod_lock); 1191 1116 reg = stv090x_read_reg(state, STV090x_STOPCLK2); 1192 1117 STV090x_SETFIELD(reg, STOP_CLKVIT2_FIELD, enable); 1193 1118 if (stv090x_write_reg(state, STV090x_STOPCLK2, reg) < 0) 1194 1119 goto err; 1195 - mutex_unlock(&demod_lock); 1120 + mutex_unlock(&state->internal->demod_lock); 1196 1121 break; 1197 1122 1198 1123 default: ··· 1201 1126 } 1202 1127 return 0; 1203 1128 err: 1204 - mutex_unlock(&demod_lock); 1129 + mutex_unlock(&state->internal->demod_lock); 1205 1130 dprintk(FE_ERROR, 1, "I/O error"); 1206 1131 return -1; 1207 1132 } 1208 1133 1209 1134 static int stv090x_dvbs_track_crl(struct stv090x_state *state) 1210 1135 { 1211 - if (state->dev_ver >= 0x30) { 1136 + if (state->internal->dev_ver >= 0x30) { 1212 1137 /* Set ACLC BCLC optimised value vs SR */ 1213 1138 if (state->srate >= 15000000) { 1214 1139 if (STV090x_WRITE_DEMOD(state, ACLC, 0x2b) < 0) ··· 1290 1215 if (STV090x_WRITE_DEMOD(state, BCLC, 0x09) < 0) 1291 1216 goto err; 1292 1217 1293 - if (state->dev_ver <= 0x20) { 1218 + if (state->internal->dev_ver <= 0x20) { 1294 1219 /* enable S2 carrier loop */ 1295 1220 if (STV090x_WRITE_DEMOD(state, CAR2CFG, 0x26) < 0) 1296 1221 goto err; ··· 1336 1261 if (stv090x_dvbs_track_crl(state) < 0) 1337 1262 goto err; 1338 1263 1339 - if (state->dev_ver <= 0x20) { 1264 + if (state->internal->dev_ver <= 0x20) { 1340 1265 /* enable S2 carrier loop */ 1341 1266 if (STV090x_WRITE_DEMOD(state, CAR2CFG, 0x26) < 0) 1342 1267 goto err; ··· 1383 1308 if (STV090x_WRITE_DEMOD(state, DMDISTATE, reg) < 0) 1384 1309 goto err; 1385 1310 1386 - if (state->dev_ver <= 0x20) { 1311 + if (state->internal->dev_ver <= 0x20) { 1387 1312 if (state->srate <= 5000000) { 1388 1313 if (STV090x_WRITE_DEMOD(state, CARCFG, 0x44) < 0) 1389 1314 goto err; ··· 1427 1352 * CFR max = +1MHz 1428 1353 */ 1429 1354 freq_abs = 1000 << 16; 1430 - freq_abs /= (state->mclk / 1000); 1355 + freq_abs /= (state->internal->mclk / 1000); 1431 1356 freq = (s16) freq_abs; 1432 1357 } else { 1433 1358 /* COLD Start ··· 1437 1362 */ 1438 1363 freq_abs = (state->search_range / 2000) + 600; 1439 1364 freq_abs = freq_abs << 16; 1440 - freq_abs /= (state->mclk / 1000); 1365 + freq_abs /= (state->internal->mclk / 1000); 1441 1366 freq = (s16) freq_abs; 1442 1367 } 1443 1368 ··· 1460 1385 if (STV090x_WRITE_DEMOD(state, CFRINIT0, 0) < 0) 1461 1386 goto err; 1462 1387 1463 - if (state->dev_ver >= 0x20) { 1388 + if (state->internal->dev_ver >= 0x20) { 1464 1389 if (STV090x_WRITE_DEMOD(state, EQUALCFG, 0x41) < 0) 1465 1390 goto err; 1466 1391 if (STV090x_WRITE_DEMOD(state, FFECFG, 0x41) < 0) ··· 1497 1422 if (STV090x_WRITE_DEMOD(state, RTC, 0x88) < 0) 1498 1423 goto err; 1499 1424 1500 - if (state->dev_ver >= 0x20) { 1425 + if (state->internal->dev_ver >= 0x20) { 1501 1426 /*Frequency offset detector setting*/ 1502 1427 if (state->srate < 2000000) { 1503 - if (state->dev_ver <= 0x20) { 1428 + if (state->internal->dev_ver <= 0x20) { 1504 1429 /* Cut 2 */ 1505 1430 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x39) < 0) 1506 1431 goto err; ··· 1591 1516 steps = 1; 1592 1517 1593 1518 dir = 1; 1594 - freq_step = (1000000 * 256) / (state->mclk / 256); 1519 + freq_step = (1000000 * 256) / (state->internal->mclk / 256); 1595 1520 freq_init = 0; 1596 1521 1597 1522 for (i = 0; i < steps; i++) { ··· 1662 1587 u32 srate_coarse = 0, agc2 = 0, car_step = 1200, reg; 1663 1588 u32 agc2th; 1664 1589 1665 - if (state->dev_ver >= 0x30) 1590 + if (state->internal->dev_ver >= 0x30) 1666 1591 agc2th = 0x2e00; 1667 1592 else 1668 1593 agc2th = 0x1f00; ··· 1698 1623 if (STV090x_WRITE_DEMOD(state, AGC2REF, 0x50) < 0) 1699 1624 goto err; 1700 1625 1701 - if (state->dev_ver >= 0x30) { 1626 + if (state->internal->dev_ver >= 0x30) { 1702 1627 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x99) < 0) 1703 1628 goto err; 1704 1629 if (STV090x_WRITE_DEMOD(state, SFRSTEP, 0x98) < 0) 1705 1630 goto err; 1706 1631 1707 - } else if (state->dev_ver >= 0x20) { 1632 + } else if (state->internal->dev_ver >= 0x20) { 1708 1633 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x6a) < 0) 1709 1634 goto err; 1710 1635 if (STV090x_WRITE_DEMOD(state, SFRSTEP, 0x95) < 0) ··· 1756 1681 STV090x_READ_DEMOD(state, AGC2I0); 1757 1682 } 1758 1683 agc2 /= 10; 1759 - srate_coarse = stv090x_get_srate(state, state->mclk); 1684 + srate_coarse = stv090x_get_srate(state, state->internal->mclk); 1760 1685 cur_step++; 1761 1686 dir *= -1; 1762 1687 if ((tmg_cpt >= 5) && (agc2 < agc2th) && ··· 1808 1733 if (!tmg_lock) 1809 1734 srate_coarse = 0; 1810 1735 else 1811 - srate_coarse = stv090x_get_srate(state, state->mclk); 1736 + srate_coarse = stv090x_get_srate(state, state->internal->mclk); 1812 1737 1813 1738 return srate_coarse; 1814 1739 err: ··· 1820 1745 { 1821 1746 u32 srate_coarse, freq_coarse, sym, reg; 1822 1747 1823 - srate_coarse = stv090x_get_srate(state, state->mclk); 1748 + srate_coarse = stv090x_get_srate(state, state->internal->mclk); 1824 1749 freq_coarse = STV090x_READ_DEMOD(state, CFR2) << 8; 1825 1750 freq_coarse |= STV090x_READ_DEMOD(state, CFR1); 1826 1751 sym = 13 * (srate_coarse / 10); /* SFRUP = SFR + 30% */ ··· 1846 1771 if (STV090x_WRITE_DEMOD(state, AGC2REF, 0x38) < 0) 1847 1772 goto err; 1848 1773 1849 - if (state->dev_ver >= 0x30) { 1774 + if (state->internal->dev_ver >= 0x30) { 1850 1775 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x79) < 0) 1851 1776 goto err; 1852 - } else if (state->dev_ver >= 0x20) { 1777 + } else if (state->internal->dev_ver >= 0x20) { 1853 1778 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x49) < 0) 1854 1779 goto err; 1855 1780 } ··· 1857 1782 if (srate_coarse > 3000000) { 1858 1783 sym = 13 * (srate_coarse / 10); /* SFRUP = SFR + 30% */ 1859 1784 sym = (sym / 1000) * 65536; 1860 - sym /= (state->mclk / 1000); 1785 + sym /= (state->internal->mclk / 1000); 1861 1786 if (STV090x_WRITE_DEMOD(state, SFRUP1, (sym >> 8) & 0x7f) < 0) 1862 1787 goto err; 1863 1788 if (STV090x_WRITE_DEMOD(state, SFRUP0, sym & 0xff) < 0) 1864 1789 goto err; 1865 1790 sym = 10 * (srate_coarse / 13); /* SFRLOW = SFR - 30% */ 1866 1791 sym = (sym / 1000) * 65536; 1867 - sym /= (state->mclk / 1000); 1792 + sym /= (state->internal->mclk / 1000); 1868 1793 if (STV090x_WRITE_DEMOD(state, SFRLOW1, (sym >> 8) & 0x7f) < 0) 1869 1794 goto err; 1870 1795 if (STV090x_WRITE_DEMOD(state, SFRLOW0, sym & 0xff) < 0) 1871 1796 goto err; 1872 1797 sym = (srate_coarse / 1000) * 65536; 1873 - sym /= (state->mclk / 1000); 1798 + sym /= (state->internal->mclk / 1000); 1874 1799 if (STV090x_WRITE_DEMOD(state, SFRINIT1, (sym >> 8) & 0xff) < 0) 1875 1800 goto err; 1876 1801 if (STV090x_WRITE_DEMOD(state, SFRINIT0, sym & 0xff) < 0) ··· 1878 1803 } else { 1879 1804 sym = 13 * (srate_coarse / 10); /* SFRUP = SFR + 30% */ 1880 1805 sym = (sym / 100) * 65536; 1881 - sym /= (state->mclk / 100); 1806 + sym /= (state->internal->mclk / 100); 1882 1807 if (STV090x_WRITE_DEMOD(state, SFRUP1, (sym >> 8) & 0x7f) < 0) 1883 1808 goto err; 1884 1809 if (STV090x_WRITE_DEMOD(state, SFRUP0, sym & 0xff) < 0) 1885 1810 goto err; 1886 1811 sym = 10 * (srate_coarse / 14); /* SFRLOW = SFR - 30% */ 1887 1812 sym = (sym / 100) * 65536; 1888 - sym /= (state->mclk / 100); 1813 + sym /= (state->internal->mclk / 100); 1889 1814 if (STV090x_WRITE_DEMOD(state, SFRLOW1, (sym >> 8) & 0x7f) < 0) 1890 1815 goto err; 1891 1816 if (STV090x_WRITE_DEMOD(state, SFRLOW0, sym & 0xff) < 0) 1892 1817 goto err; 1893 1818 sym = (srate_coarse / 100) * 65536; 1894 - sym /= (state->mclk / 100); 1819 + sym /= (state->internal->mclk / 100); 1895 1820 if (STV090x_WRITE_DEMOD(state, SFRINIT1, (sym >> 8) & 0xff) < 0) 1896 1821 goto err; 1897 1822 if (STV090x_WRITE_DEMOD(state, SFRINIT0, sym & 0xff) < 0) ··· 1960 1885 1961 1886 agc2 = stv090x_get_agc2_min_level(state); 1962 1887 1963 - if (agc2 > STV090x_SEARCH_AGC2_TH(state->dev_ver)) { 1888 + if (agc2 > STV090x_SEARCH_AGC2_TH(state->internal->dev_ver)) { 1964 1889 lock = 0; 1965 1890 } else { 1966 1891 1967 - if (state->dev_ver <= 0x20) { 1892 + if (state->internal->dev_ver <= 0x20) { 1968 1893 if (STV090x_WRITE_DEMOD(state, CARCFG, 0xc4) < 0) 1969 1894 goto err; 1970 1895 } else { ··· 1976 1901 if (STV090x_WRITE_DEMOD(state, RTCS2, 0x44) < 0) 1977 1902 goto err; 1978 1903 1979 - if (state->dev_ver >= 0x20) { 1904 + if (state->internal->dev_ver >= 0x20) { 1980 1905 if (STV090x_WRITE_DEMOD(state, EQUALCFG, 0x41) < 0) 1981 1906 goto err; 1982 1907 if (STV090x_WRITE_DEMOD(state, FFECFG, 0x41) < 0) ··· 2221 2146 car_max = state->search_range / 1000; 2222 2147 car_max += car_max / 10; 2223 2148 car_max = 65536 * (car_max / 2); 2224 - car_max /= (state->mclk / 1000); 2149 + car_max /= (state->internal->mclk / 1000); 2225 2150 2226 2151 if (car_max > 0x4000) 2227 2152 car_max = 0x4000 ; /* maxcarrier should be<= +-1/4 Mclk */ 2228 2153 2229 2154 inc = srate; 2230 - inc /= state->mclk / 1000; 2155 + inc /= state->internal->mclk / 1000; 2231 2156 inc *= 256; 2232 2157 inc *= 256; 2233 2158 inc /= 1000; ··· 2288 2213 2289 2214 car_max += (car_max / 10); /* 10% margin */ 2290 2215 car_max = (65536 * car_max / 2); 2291 - car_max /= state->mclk / 1000; 2216 + car_max /= state->internal->mclk / 1000; 2292 2217 2293 2218 if (car_max > 0x4000) 2294 2219 car_max = 0x4000; ··· 2313 2238 car_max = state->search_range / 1000; 2314 2239 car_max += (car_max / 10); 2315 2240 car_max = (65536 * car_max / 2); 2316 - car_max /= (state->mclk / 1000); 2241 + car_max /= (state->internal->mclk / 1000); 2317 2242 if (car_max > 0x4000) 2318 2243 car_max = 0x4000; 2319 2244 ··· 2383 2308 case STV090x_SEARCH_DVBS1: 2384 2309 case STV090x_SEARCH_DSS: 2385 2310 /* accelerate the frequency detector */ 2386 - if (state->dev_ver >= 0x20) { 2311 + if (state->internal->dev_ver >= 0x20) { 2387 2312 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x3B) < 0) 2388 2313 goto err; 2389 2314 } ··· 2394 2319 break; 2395 2320 2396 2321 case STV090x_SEARCH_DVBS2: 2397 - if (state->dev_ver >= 0x20) { 2322 + if (state->internal->dev_ver >= 0x20) { 2398 2323 if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x79) < 0) 2399 2324 goto err; 2400 2325 } ··· 2407 2332 case STV090x_SEARCH_AUTO: 2408 2333 default: 2409 2334 /* accelerate the frequency detector */ 2410 - if (state->dev_ver >= 0x20) { 2335 + if (state->internal->dev_ver >= 0x20) { 2411 2336 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x3b) < 0) 2412 2337 goto err; 2413 2338 if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x79) < 0) ··· 2429 2354 /*run the SW search 2 times maximum*/ 2430 2355 if (lock || no_signal || (trials == 2)) { 2431 2356 /*Check if the demod is not losing lock in DVBS2*/ 2432 - if (state->dev_ver >= 0x20) { 2357 + if (state->internal->dev_ver >= 0x20) { 2433 2358 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x49) < 0) 2434 2359 goto err; 2435 2360 if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x9e) < 0) ··· 2451 2376 /*FALSE lock, The demod is loosing lock */ 2452 2377 lock = 0; 2453 2378 if (trials < 2) { 2454 - if (state->dev_ver >= 0x20) { 2379 + if (state->internal->dev_ver >= 0x20) { 2455 2380 if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x79) < 0) 2456 2381 goto err; 2457 2382 } ··· 2501 2426 derot |= STV090x_READ_DEMOD(state, CFR0); 2502 2427 2503 2428 derot = comp2(derot, 24); 2504 - int_1 = state->mclk >> 12; 2429 + int_1 = mclk >> 12; 2505 2430 int_2 = derot >> 12; 2506 2431 2507 2432 /* carrier_frequency = MasterClock * Reg / 2^24 */ 2508 - tmp_1 = state->mclk % 0x1000; 2433 + tmp_1 = mclk % 0x1000; 2509 2434 tmp_2 = derot % 0x1000; 2510 2435 2511 2436 derot = (int_1 * int_2) + ··· 2587 2512 if (stv090x_i2c_gate_ctrl(fe, 0) < 0) 2588 2513 goto err; 2589 2514 2590 - offst_freq = stv090x_get_car_freq(state, state->mclk) / 1000; 2515 + offst_freq = stv090x_get_car_freq(state, state->internal->mclk) / 1000; 2591 2516 state->frequency += offst_freq; 2592 2517 2593 2518 if (stv090x_get_viterbi(state) < 0) ··· 2658 2583 s32 i; 2659 2584 struct stv090x_long_frame_crloop *car_loop, *car_loop_qpsk_low, *car_loop_apsk_low; 2660 2585 2661 - if (state->dev_ver == 0x20) { 2586 + if (state->internal->dev_ver == 0x20) { 2662 2587 car_loop = stv090x_s2_crl_cut20; 2663 2588 car_loop_qpsk_low = stv090x_s2_lowqpsk_crl_cut20; 2664 2589 car_loop_apsk_low = stv090x_s2_apsk_crl_cut20; ··· 2779 2704 break; 2780 2705 } 2781 2706 2782 - if (state->dev_ver >= 0x30) { 2707 + if (state->internal->dev_ver >= 0x30) { 2783 2708 /* Cut 3.0 and up */ 2784 2709 short_crl = stv090x_s2_short_crl_cut30; 2785 2710 } else { ··· 2811 2736 s32 srate, pilots, aclc, f_1, f_0, i = 0, blind_tune = 0; 2812 2737 u32 reg; 2813 2738 2814 - srate = stv090x_get_srate(state, state->mclk); 2739 + srate = stv090x_get_srate(state, state->internal->mclk); 2815 2740 srate += stv090x_get_tmgoffst(state, srate); 2816 2741 2817 2742 switch (state->delsys) { ··· 2830 2755 if (STV090x_WRITE_DEMOD(state, DEMOD, reg) < 0) 2831 2756 goto err; 2832 2757 2833 - if (state->dev_ver >= 0x30) { 2758 + if (state->internal->dev_ver >= 0x30) { 2834 2759 if (stv090x_get_viterbi(state) < 0) 2835 2760 goto err; 2836 2761 ··· 2947 2872 goto err; 2948 2873 } 2949 2874 2950 - if (state->dev_ver >= 0x20) { 2875 + if (state->internal->dev_ver >= 0x20) { 2951 2876 if ((state->search_mode == STV090x_SEARCH_DVBS1) || 2952 2877 (state->search_mode == STV090x_SEARCH_DSS) || 2953 2878 (state->search_mode == STV090x_SEARCH_AUTO)) { ··· 2969 2894 if (STV090x_WRITE_DEMOD(state, SFRLOW1, 0x80) < 0) 2970 2895 goto err; 2971 2896 2972 - if ((state->dev_ver >= 0x20) || (blind_tune == 1) || (state->srate < 10000000)) { 2897 + if ((state->internal->dev_ver >= 0x20) || (blind_tune == 1) || 2898 + (state->srate < 10000000)) { 2973 2899 /* update initial carrier freq with the found freq offset */ 2974 2900 if (STV090x_WRITE_DEMOD(state, CFRINIT1, f_1) < 0) 2975 2901 goto err; ··· 2978 2902 goto err; 2979 2903 state->tuner_bw = stv090x_car_width(srate, state->rolloff) + 10000000; 2980 2904 2981 - if ((state->dev_ver >= 0x20) || (blind_tune == 1)) { 2905 + if ((state->internal->dev_ver >= 0x20) || (blind_tune == 1)) { 2982 2906 2983 2907 if (state->algo != STV090x_WARM_SEARCH) { 2984 2908 ··· 3030 2954 3031 2955 } 3032 2956 3033 - if (state->dev_ver >= 0x20) { 2957 + if (state->internal->dev_ver >= 0x20) { 3034 2958 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x49) < 0) 3035 2959 goto err; 3036 2960 } ··· 3106 3030 { 3107 3031 u32 reg; 3108 3032 3109 - if (state->dev_ver <= 0x20) { 3033 + if (state->internal->dev_ver <= 0x20) { 3110 3034 /* rolloff to auto mode if DVBS2 */ 3111 3035 reg = STV090x_READ_DEMOD(state, DEMOD); 3112 3036 STV090x_SETFIELD_Px(reg, MANUAL_SXROLLOFF_FIELD, 0x00); ··· 3142 3066 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x5c) < 0) /* Demod stop */ 3143 3067 goto err; 3144 3068 3145 - if (state->dev_ver >= 0x20) { 3069 + if (state->internal->dev_ver >= 0x20) { 3146 3070 if (state->srate > 5000000) { 3147 3071 if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x9e) < 0) 3148 3072 goto err; ··· 3182 3106 if (STV090x_WRITE_DEMOD(state, AGC2REF, 0x38) < 0) 3183 3107 goto err; 3184 3108 3185 - if (state->dev_ver >= 0x20) { 3109 + if (state->internal->dev_ver >= 0x20) { 3186 3110 if (STV090x_WRITE_DEMOD(state, KREFTMG, 0x5a) < 0) 3187 3111 goto err; 3188 3112 if (state->algo == STV090x_COLD_SEARCH) ··· 3200 3124 if (stv090x_set_srate(state, state->srate) < 0) 3201 3125 goto err; 3202 3126 3203 - if (stv090x_set_max_srate(state, state->mclk, state->srate) < 0) 3127 + if (stv090x_set_max_srate(state, state->internal->mclk, 3128 + state->srate) < 0) 3204 3129 goto err; 3205 - if (stv090x_set_min_srate(state, state->mclk, state->srate) < 0) 3130 + if (stv090x_set_min_srate(state, state->internal->mclk, 3131 + state->srate) < 0) 3206 3132 goto err; 3207 3133 3208 3134 if (state->srate >= 10000000) ··· 3276 3198 reg = STV090x_READ_DEMOD(state, DEMOD); 3277 3199 STV090x_SETFIELD_Px(reg, SPECINV_CONTROL_FIELD, state->inversion); 3278 3200 3279 - if (state->dev_ver <= 0x20) { 3201 + if (state->internal->dev_ver <= 0x20) { 3280 3202 /* rolloff to auto mode if DVBS2 */ 3281 3203 STV090x_SETFIELD_Px(reg, MANUAL_SXROLLOFF_FIELD, 1); 3282 3204 } else { ··· 3320 3242 if ((lock) && (signal_state == STV090x_RANGEOK)) { /* signal within Range */ 3321 3243 stv090x_optimize_track(state); 3322 3244 3323 - if (state->dev_ver >= 0x20) { 3245 + if (state->internal->dev_ver >= 0x20) { 3324 3246 /* >= Cut 2.0 :release TS reset after 3325 3247 * demod lock and optimized Tracking 3326 3248 */ ··· 3852 3774 { 3853 3775 struct stv090x_state *state = fe->demodulator_priv; 3854 3776 3777 + state->internal->num_used--; 3778 + if (state->internal->num_used <= 0) { 3779 + 3780 + dprintk(FE_ERROR, 1, "Actually removing"); 3781 + 3782 + remove_dev(state->internal); 3783 + kfree(state->internal); 3784 + } 3785 + 3855 3786 kfree(state); 3856 3787 } 3857 3788 ··· 3992 3905 if (stv090x_write_reg(state, STV090x_NCOARSE, reg) < 0) 3993 3906 goto err; 3994 3907 3995 - state->mclk = stv090x_get_mclk(state); 3908 + state->internal->mclk = stv090x_get_mclk(state); 3996 3909 3997 3910 /*Set the DiseqC frequency to 22KHz */ 3998 - div = state->mclk / 704000; 3911 + div = state->internal->mclk / 704000; 3999 3912 if (STV090x_WRITE_DEMOD(state, F22TX, div) < 0) 4000 3913 goto err; 4001 3914 if (STV090x_WRITE_DEMOD(state, F22RX, div) < 0) ··· 4011 3924 { 4012 3925 u32 reg; 4013 3926 4014 - if (state->dev_ver >= 0x20) { 3927 + if (state->internal->dev_ver >= 0x20) { 4015 3928 switch (state->config->ts1_mode) { 4016 3929 case STV090x_TSMODE_PARALLEL_PUNCTURED: 4017 3930 case STV090x_TSMODE_DVBCI: ··· 4279 4192 } 4280 4193 4281 4194 /* STV090x init */ 4282 - if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x5c) < 0) /* Stop Demod */ 4195 + 4196 + /* Stop Demod */ 4197 + if (stv090x_write_reg(state, STV090x_P1_DMDISTATE, 0x5c) < 0) 4198 + goto err; 4199 + if (stv090x_write_reg(state, STV090x_P2_DMDISTATE, 0x5c) < 0) 4283 4200 goto err; 4284 4201 4285 4202 msleep(5); 4286 4203 4287 - if (STV090x_WRITE_DEMOD(state, TNRCFG, 0x6c) < 0) /* check register ! (No Tuner Mode) */ 4204 + /* Set No Tuner Mode */ 4205 + if (stv090x_write_reg(state, STV090x_P1_TNRCFG, 0x6c) < 0) 4206 + goto err; 4207 + if (stv090x_write_reg(state, STV090x_P2_TNRCFG, 0x6c) < 0) 4288 4208 goto err; 4289 4209 4210 + /* I2C repeater OFF */ 4290 4211 STV090x_SETFIELD_Px(reg, ENARPT_LEVEL_FIELD, config->repeater_level); 4291 - if (STV090x_WRITE_DEMOD(state, I2CRPT, reg) < 0) /* repeater OFF */ 4212 + if (stv090x_write_reg(state, STV090x_P1_I2CRPT, reg) < 0) 4213 + goto err; 4214 + if (stv090x_write_reg(state, STV090x_P2_I2CRPT, reg) < 0) 4292 4215 goto err; 4293 4216 4294 4217 if (stv090x_write_reg(state, STV090x_NCOARSE, 0x13) < 0) /* set PLL divider */ ··· 4317 4220 goto err; 4318 4221 } 4319 4222 4320 - state->dev_ver = stv090x_read_reg(state, STV090x_MID); 4321 - if (state->dev_ver >= 0x20) { 4223 + state->internal->dev_ver = stv090x_read_reg(state, STV090x_MID); 4224 + if (state->internal->dev_ver >= 0x20) { 4322 4225 if (stv090x_write_reg(state, STV090x_TSGENERAL, 0x0c) < 0) 4323 4226 goto err; 4324 4227 ··· 4329 4232 goto err; 4330 4233 } 4331 4234 4332 - } else if (state->dev_ver < 0x20) { 4235 + } else if (state->internal->dev_ver < 0x20) { 4333 4236 dprintk(FE_ERROR, 1, "ERROR: Unsupported Cut: 0x%02x!", 4334 - state->dev_ver); 4237 + state->internal->dev_ver); 4335 4238 4336 4239 goto err; 4337 - } else if (state->dev_ver > 0x30) { 4240 + } else if (state->internal->dev_ver > 0x30) { 4338 4241 /* we shouldn't bail out from here */ 4339 4242 dprintk(FE_ERROR, 1, "INFO: Cut: 0x%02x probably incomplete support!", 4340 - state->dev_ver); 4243 + state->internal->dev_ver); 4341 4244 } 4342 4245 4343 4246 if (stv090x_write_reg(state, STV090x_TSTRES0, 0x80) < 0) ··· 4400 4303 enum stv090x_demodulator demod) 4401 4304 { 4402 4305 struct stv090x_state *state = NULL; 4306 + struct stv090x_dev *temp_int; 4403 4307 4404 4308 state = kzalloc(sizeof (struct stv090x_state), GFP_KERNEL); 4405 4309 if (state == NULL) ··· 4416 4318 state->device = config->device; 4417 4319 state->rolloff = STV090x_RO_35; /* default */ 4418 4320 4419 - if (state->demod == STV090x_DEMODULATOR_0) 4420 - mutex_init(&demod_lock); 4321 + temp_int = find_dev(state->i2c, 4322 + state->config->address); 4323 + 4324 + if ((temp_int != NULL) && (state->demod_mode == STV090x_DUAL)) { 4325 + state->internal = temp_int->internal; 4326 + state->internal->num_used++; 4327 + dprintk(FE_INFO, 1, "Found Internal Structure!"); 4328 + dprintk(FE_ERROR, 1, "Attaching %s demodulator(%d) Cut=0x%02x", 4329 + state->device == STV0900 ? "STV0900" : "STV0903", 4330 + demod, 4331 + state->internal->dev_ver); 4332 + return &state->frontend; 4333 + } else { 4334 + state->internal = kmalloc(sizeof(struct stv090x_internal), 4335 + GFP_KERNEL); 4336 + temp_int = append_internal(state->internal); 4337 + state->internal->num_used = 1; 4338 + state->internal->i2c_adap = state->i2c; 4339 + state->internal->i2c_addr = state->config->address; 4340 + dprintk(FE_INFO, 1, "Create New Internal Structure!"); 4341 + } 4342 + 4343 + mutex_init(&state->internal->demod_lock); 4421 4344 4422 4345 if (stv090x_sleep(&state->frontend) < 0) { 4423 4346 dprintk(FE_ERROR, 1, "Error putting device to sleep"); ··· 4454 4335 goto error; 4455 4336 } 4456 4337 4457 - dprintk(FE_ERROR, 1, "Attaching %s demodulator(%d) Cut=0x%02x\n", 4338 + dprintk(FE_ERROR, 1, "Attaching %s demodulator(%d) Cut=0x%02x", 4458 4339 state->device == STV0900 ? "STV0900" : "STV0903", 4459 4340 demod, 4460 - state->dev_ver); 4341 + state->internal->dev_ver); 4461 4342 4462 4343 return &state->frontend; 4463 4344
-2
drivers/media/dvb/frontends/stv090x.h
··· 68 68 u32 xtal; /* default: 8000000 */ 69 69 u8 address; /* default: 0x68 */ 70 70 71 - u32 ref_clk; /* default: 16000000 FIXME to tuner config */ 72 - 73 71 u8 ts1_mode; 74 72 u8 ts2_mode; 75 73
+12 -4
drivers/media/dvb/frontends/stv090x_priv.h
··· 230 230 s32 read; 231 231 }; 232 232 233 + struct stv090x_internal { 234 + struct i2c_adapter *i2c_adap; 235 + u8 i2c_addr; 236 + 237 + struct mutex demod_lock; /* Lock access to shared register */ 238 + s32 mclk; /* Masterclock Divider factor */ 239 + u32 dev_ver; 240 + 241 + int num_used; 242 + }; 243 + 233 244 struct stv090x_state { 234 245 enum stv090x_device device; 235 246 enum stv090x_demodulator demod; 236 247 enum stv090x_mode demod_mode; 237 - u32 dev_ver; 248 + struct stv090x_internal *internal; 238 249 239 250 struct i2c_adapter *i2c; 240 251 const struct stv090x_config *config; ··· 267 256 u32 frequency; 268 257 u32 srate; 269 258 270 - s32 mclk; /* Masterclock Divider factor */ 271 259 s32 tuner_bw; 272 - 273 - u32 tuner_refclk; 274 260 275 261 s32 search_range; 276 262
-1
drivers/media/dvb/ttpci/budget.c
··· 435 435 436 436 .xtal = 27000000, 437 437 .address = 0x68, 438 - .ref_clk = 27000000, 439 438 440 439 .ts1_mode = STV090x_TSMODE_DVBCI, 441 440 .ts2_mode = STV090x_TSMODE_SERIAL_CONTINUOUS,