Lines Matching +full:ext +full:- +full:26 +full:m

1 // SPDX-License-Identifier: GPL-2.0
7 // that it is part of rtl-sdr git tree, released under GPLv2:
8 // https://groups.google.com/forum/#!topic/ultra-cheap-sdr/Y3rBEOFtHug
9 // https://github.com/n1gp/gr-baz
30 #include "tuner-i2c.h"
355 int r = reg - REG_SHADOW_START; in shadow_store()
363 if (len > NUM_REGS - r) in shadow_store()
364 len = NUM_REGS - r; in shadow_store()
369 memcpy(&priv->regs[r], val, len); in shadow_store()
381 if (len > priv->cfg->max_i2c_msg_len - 1) in r820t_write()
382 size = priv->cfg->max_i2c_msg_len - 1; in r820t_write()
387 priv->buf[0] = reg; in r820t_write()
388 memcpy(&priv->buf[1], &val[pos], size); in r820t_write()
390 rc = tuner_i2c_xfer_send(&priv->i2c_props, priv->buf, size + 1); in r820t_write()
393 __func__, rc, reg, size, size, &priv->buf[1]); in r820t_write()
396 return -EREMOTEIO; in r820t_write()
399 __func__, reg, size, size, &priv->buf[1]); in r820t_write()
402 len -= size; in r820t_write()
411 u8 tmp = val; /* work around GCC PR81715 with asan-stack=1 */ in r820t_write_reg()
418 reg -= REG_SHADOW_START; in r820t_read_cache_reg()
421 return priv->regs[reg]; in r820t_read_cache_reg()
423 return -EINVAL; in r820t_read_cache_reg()
443 u8 *p = &priv->buf[1]; in r820t_read()
445 priv->buf[0] = reg; in r820t_read()
447 rc = tuner_i2c_xfer_send_recv(&priv->i2c_props, priv->buf, 1, p, len); in r820t_read()
453 return -EREMOTEIO; in r820t_read()
478 for (i = 0; i < ARRAY_SIZE(freq_ranges) - 1; i++) { in r820t_set_mux()
487 rc = r820t_write_reg_mask(priv, 0x17, range->open_d, 0x08); in r820t_set_mux()
492 rc = r820t_write_reg_mask(priv, 0x1a, range->rf_mux_ploy, 0xc3); in r820t_set_mux()
497 rc = r820t_write_reg(priv, 0x1b, range->tf_c); in r820t_set_mux()
502 switch (priv->xtal_cap_sel) { in r820t_set_mux()
505 val = range->xtal_cap20p | 0x08; in r820t_set_mux()
508 val = range->xtal_cap10p | 0x08; in r820t_set_mux()
511 val = range->xtal_cap0p | 0x00; in r820t_set_mux()
515 val = range->xtal_cap0p | 0x08; in r820t_set_mux()
522 if (priv->imr_done) { in r820t_set_mux()
523 reg08 = priv->imr_data[range->imr_mem].gain_x; in r820t_set_mux()
524 reg09 = priv->imr_data[range->imr_mem].phase_y; in r820t_set_mux()
559 pll_ref = priv->cfg->xtal / 1000; in r820t_set_pll()
562 /* Doesn't exist on rtl-sdk, and on field tests, caused troubles */ in r820t_set_pll()
563 if ((priv->cfg->rafael_chip == CHIP_R620D) || in r820t_set_pll()
564 (priv->cfg->rafael_chip == CHIP_R828D) || in r820t_set_pll()
565 (priv->cfg->rafael_chip == CHIP_R828)) { in r820t_set_pll()
573 if (priv->cfg->xtal > 24000000) { in r820t_set_pll()
621 if (priv->cfg->rafael_chip != CHIP_R828D) { in r820t_set_pll()
623 div_num = div_num - 1; in r820t_set_pll()
634 vco_fra = vco_freq - 2 * pll_ref * nint; in r820t_set_pll()
648 ni = (nint - 13) / 4; in r820t_set_pll()
649 si = nint - 4 * ni - 13; in r820t_set_pll()
669 vco_fra = vco_fra - 2 * pll_ref / n_sdm; in r820t_set_pll()
705 priv->has_lock = false; in r820t_set_pll()
709 priv->has_lock = true; in r820t_set_pll()
733 mixer_top = 0x14; /* mixer top:14 , top-1, low-discharge */ in r820t_sysfreq_sel()
738 mixer_top = 0x24; /* mixer top:13 , top-1, low-discharge */ in r820t_sysfreq_sel()
752 mixer_top = 0x24; /* mixer top:13 , top-1, low-discharge */ in r820t_sysfreq_sel()
765 mixer_top = 0x24; /* mixer top:13 , top-1, low-discharge */ in r820t_sysfreq_sel()
778 mixer_top = 0x24; /* mixer top:13 , top-1, low-discharge */ in r820t_sysfreq_sel()
790 default: /* DVB-T 8M */ in r820t_sysfreq_sel()
791 mixer_top = 0x24; /* mixer top:13 , top-1, low-discharge */ in r820t_sysfreq_sel()
805 if (priv->cfg->use_diplexer && in r820t_sysfreq_sel()
806 ((priv->cfg->rafael_chip == CHIP_R820T) || in r820t_sysfreq_sel()
807 (priv->cfg->rafael_chip == CHIP_R828S) || in r820t_sysfreq_sel()
808 (priv->cfg->rafael_chip == CHIP_R820C))) { in r820t_sysfreq_sel()
817 if (priv->cfg->use_predetect) { in r820t_sysfreq_sel()
836 /* Air-IN only for Astrometa */ in r820t_sysfreq_sel()
968 hp_cor = 0x6a; /* 1.7m disable, +2cap, 1.25mhz */ in r820t_set_tv_standard()
969 ext_enable = 0x40; /* r30[6], ext enable; r30[5]:0 ext at lna max */ in r820t_set_tv_standard()
980 hp_cor = 0x0b; /* 1.7m disable, +0cap, 1.0mhz */ in r820t_set_tv_standard()
981 ext_enable = 0x40; /* r30[6]=1 ext enable; r30[5]:1 ext at lna max-1 */ in r820t_set_tv_standard()
992 hp_cor = 0x6a; /* 1.7m disable, +0cap, 1.0mhz */ in r820t_set_tv_standard()
993 ext_enable = 0x40; /* r30[6]=1 ext enable; r30[5]:1 ext at lna max-1 */ in r820t_set_tv_standard()
1001 filt_cal_lo = 56000; /* 52000->56000 */ in r820t_set_tv_standard()
1005 hp_cor = 0x6b; /* 1.7m disable, +2cap, 1.0mhz */ in r820t_set_tv_standard()
1006 ext_enable = 0x60; /* r30[6]=1 ext enable; r30[5]:1 ext at lna max-1 */ in r820t_set_tv_standard()
1025 hp_cor = 0x2b; /* 1.7m disable, +1cap, 1.0mhz */ in r820t_set_tv_standard()
1026 ext_enable = 0x60; /* r30[6]=1 ext enable; r30[5]:1 ext at lna max-1 */ in r820t_set_tv_standard()
1038 hp_cor = 0x2a; /* 1.7m disable, +1cap, 1.25mhz */ in r820t_set_tv_standard()
1039 ext_enable = 0x60; /* r30[6]=1 ext enable; r30[5]:1 ext at lna max-1 */ in r820t_set_tv_standard()
1050 hp_cor = 0x0b; /* 1.7m disable, +0cap, 1.0mhz */ in r820t_set_tv_standard()
1051 ext_enable = 0x60; /* r30[6]=1 ext enable; r30[5]:1 ext at lna max-1 */ in r820t_set_tv_standard()
1060 memcpy(priv->regs, r820t_init_array, sizeof(r820t_init_array)); in r820t_set_tv_standard()
1063 if (priv->imr_done) in r820t_set_tv_standard()
1064 val = 1 | priv->xtal_cap_sel << 1; in r820t_set_tv_standard()
1083 priv->int_freq = if_khz * 1000; in r820t_set_tv_standard()
1086 if (type != priv->type) in r820t_set_tv_standard()
1088 else if ((type == V4L2_TUNER_ANALOG_TV) && (std != priv->std)) in r820t_set_tv_standard()
1091 ((delsys != priv->delsys) || bw != priv->bw)) in r820t_set_tv_standard()
1115 if (rc < 0 || !priv->has_lock) in r820t_set_tv_standard()
1140 priv->fil_cal_code = data[4] & 0x0f; in r820t_set_tv_standard()
1141 if (priv->fil_cal_code && priv->fil_cal_code != 0x0f) in r820t_set_tv_standard()
1145 if (priv->fil_cal_code == 0x0f) in r820t_set_tv_standard()
1146 priv->fil_cal_code = 0; in r820t_set_tv_standard()
1150 filt_q | priv->fil_cal_code, 0x1f); in r820t_set_tv_standard()
1195 /* Store current standard. If it changes, re-calibrate the tuner */ in r820t_set_tv_standard()
1196 priv->delsys = delsys; in r820t_set_tv_standard()
1197 priv->type = type; in r820t_set_tv_standard()
1198 priv->std = std; in r820t_set_tv_standard()
1199 priv->bw = bw; in r820t_set_tv_standard()
1220 * measured with a Racal 6103E GSM test set at 928 MHz with -60 dBm
1222 * http://steve-m.de/projects/rtl-sdr/gain_measurement/r820t/
1226 0, 9, 13, 40, 38, 13, 31, 22, 26, 31, 26, 14, 19, 5, 35, 13
1230 0, 5, 10, 10, 19, 9, 10, 25, 17, 10, 8, 16, 13, 6, 3, -8
1311 struct r820t_priv *priv = fe->tuner_priv; in generic_set_freq()
1323 lo_freq = freq - priv->int_freq; in generic_set_freq()
1325 lo_freq = freq + priv->int_freq; in generic_set_freq()
1332 if (rc < 0 || !priv->has_lock) in generic_set_freq()
1358 if (!priv->init_done) in r820t_standby()
1394 priv->type = -1; in r820t_standby()
1409 memcpy(priv->regs, r820t_init_array, sizeof(r820t_init_array)); in r820t_xtal_check()
1448 if (priv->cfg->xtal == 16000000 && (val > 29 || val < 23)) in r820t_xtal_check()
1456 return -EINVAL; in r820t_xtal_check()
1466 memcpy(priv->regs, r820t_init_array, sizeof(r820t_init_array)); in r820t_imr_prepare()
1468 /* lna off (air-in off) */ in r820t_imr_prepare()
1483 /* filter bw=+2cap, hp=5M */ in r820t_imr_prepare()
1540 rc = sum - max - min; in r820t_multi_read()
1549 struct r820t_sect_type cross[5]; /* (0,0)(0,Q-1)(0,I-1)(Q-1,0)(I-1,0) */ in r820t_imr_cross()
1569 cross[i].phase_y = reg09 + 1; /* Q-1 */ in r820t_imr_cross()
1573 cross[i].phase_y = (reg09 | 0x20) + 1; /* I-1 */ in r820t_imr_cross()
1576 cross[i].gain_x = reg08 + 1; /* Q-1 */ in r820t_imr_cross()
1580 cross[i].gain_x = (reg08 | 0x20) + 1; /* I-1 */ in r820t_imr_cross()
1602 if ((tmp.phase_y & 0x1f) == 1) { /* y-direction */ in r820t_imr_cross()
1608 } else { /* (0,0) or x-direction */ in r820t_imr_cross()
1622 for (i = 3; i > 0; i--) { in r820t_compre_cor()
1623 if (iq[0].value > iq[i - 1].value) in r820t_compre_cor()
1624 swap(iq[0], iq[i - 1]); in r820t_compre_cor()
1718 if (i == 0) { /* try right-side point */ in r820t_iq_tree()
1720 } else if (i == 1) { /* try left-side point */ in r820t_iq_tree()
1723 tmp = 2 - (var_val & 0x1f); in r820t_iq_tree()
1725 /* b[5]:I/Q selection. 0:Q-path, 1:I-path */ in r820t_iq_tree()
1733 var_val -= 2; in r820t_iq_tree()
1747 /* Try X-1 column and save min result to compare_bet[0] */ in r820t_section()
1748 if (!(iq_point->gain_x & 0x1f)) in r820t_section()
1749 compare_iq[0].gain_x = ((iq_point->gain_x) & 0xdf) + 1; /* Q-path, Gain=1 */ in r820t_section()
1751 compare_iq[0].gain_x = iq_point->gain_x - 1; /* left point */ in r820t_section()
1752 compare_iq[0].phase_y = iq_point->phase_y; in r820t_section()
1754 /* y-direction */ in r820t_section()
1765 compare_iq[0].gain_x = iq_point->gain_x; in r820t_section()
1766 compare_iq[0].phase_y = iq_point->phase_y; in r820t_section()
1778 if ((iq_point->gain_x & 0x1f) == 0x00) in r820t_section()
1779 compare_iq[0].gain_x = ((iq_point->gain_x) | 0x20) + 1; /* I-path, Gain=1 */ in r820t_section()
1781 compare_iq[0].gain_x = iq_point->gain_x + 1; in r820t_section()
1782 compare_iq[0].phase_y = iq_point->phase_y; in r820t_section()
1875 /* section-9 check */ in r820t_iq()
1898 * try (x-1), (x), (x+1) columns, and find min IMR result point in r820t_f_imr()
1915 if (priv->cfg->xtal > 24000000) in r820t_imr()
1916 ring_ref = priv->cfg->xtal / 2000; in r820t_imr()
1918 ring_ref = priv->cfg->xtal / 1000; in r820t_imr()
1999 rc = r820t_set_mux(priv, (ring_freq - 5300) * 1000); in r820t_imr()
2004 (ring_freq - 5300) * 1000); in r820t_imr()
2005 if (!priv->has_lock) in r820t_imr()
2006 rc = -EINVAL; in r820t_imr()
2013 imr_point.gain_x = priv->imr_data[3].gain_x; in r820t_imr()
2014 imr_point.phase_y = priv->imr_data[3].phase_y; in r820t_imr()
2015 imr_point.value = priv->imr_data[3].value; in r820t_imr()
2025 priv->imr_data[0].gain_x = imr_point.gain_x; in r820t_imr()
2026 priv->imr_data[0].phase_y = imr_point.phase_y; in r820t_imr()
2027 priv->imr_data[0].value = imr_point.value; in r820t_imr()
2030 priv->imr_data[1].gain_x = imr_point.gain_x; in r820t_imr()
2031 priv->imr_data[1].phase_y = imr_point.phase_y; in r820t_imr()
2032 priv->imr_data[1].value = imr_point.value; in r820t_imr()
2035 priv->imr_data[2].gain_x = imr_point.gain_x; in r820t_imr()
2036 priv->imr_data[2].phase_y = imr_point.phase_y; in r820t_imr()
2037 priv->imr_data[2].value = imr_point.value; in r820t_imr()
2040 priv->imr_data[3].gain_x = imr_point.gain_x; in r820t_imr()
2041 priv->imr_data[3].phase_y = imr_point.phase_y; in r820t_imr()
2042 priv->imr_data[3].value = imr_point.value; in r820t_imr()
2045 priv->imr_data[4].gain_x = imr_point.gain_x; in r820t_imr()
2046 priv->imr_data[4].phase_y = imr_point.phase_y; in r820t_imr()
2047 priv->imr_data[4].value = imr_point.value; in r820t_imr()
2050 priv->imr_data[4].gain_x = imr_point.gain_x; in r820t_imr()
2051 priv->imr_data[4].phase_y = imr_point.phase_y; in r820t_imr()
2052 priv->imr_data[4].value = imr_point.value; in r820t_imr()
2064 if (priv->init_done) in r820t_imr_callibrate()
2068 if ((priv->cfg->rafael_chip == CHIP_R820T) || in r820t_imr_callibrate()
2069 (priv->cfg->rafael_chip == CHIP_R828S) || in r820t_imr_callibrate()
2070 (priv->cfg->rafael_chip == CHIP_R820C)) { in r820t_imr_callibrate()
2071 priv->xtal_cap_sel = XTAL_HIGH_CAP_0P; in r820t_imr_callibrate()
2085 priv->xtal_cap_sel = xtal_cap; in r820t_imr_callibrate()
2090 * as what is done by rtl-sdr userspace library. Useful for testing in r820t_imr_callibrate()
2093 priv->init_done = true; in r820t_imr_callibrate()
2124 priv->init_done = true; in r820t_imr_callibrate()
2125 priv->imr_done = true; in r820t_imr_callibrate()
2146 struct r820t_priv *priv = fe->tuner_priv; in r820t_init()
2151 mutex_lock(&priv->lock); in r820t_init()
2152 if (fe->ops.i2c_gate_ctrl) in r820t_init()
2153 fe->ops.i2c_gate_ctrl(fe, 1); in r820t_init()
2164 if (fe->ops.i2c_gate_ctrl) in r820t_init()
2165 fe->ops.i2c_gate_ctrl(fe, 0); in r820t_init()
2166 mutex_unlock(&priv->lock); in r820t_init()
2175 struct r820t_priv *priv = fe->tuner_priv; in r820t_sleep()
2180 mutex_lock(&priv->lock); in r820t_sleep()
2181 if (fe->ops.i2c_gate_ctrl) in r820t_sleep()
2182 fe->ops.i2c_gate_ctrl(fe, 1); in r820t_sleep()
2186 if (fe->ops.i2c_gate_ctrl) in r820t_sleep()
2187 fe->ops.i2c_gate_ctrl(fe, 0); in r820t_sleep()
2188 mutex_unlock(&priv->lock); in r820t_sleep()
2197 struct r820t_priv *priv = fe->tuner_priv; in r820t_set_analog_freq()
2204 if (!p->std) in r820t_set_analog_freq()
2205 p->std = V4L2_STD_MN; in r820t_set_analog_freq()
2207 if ((p->std == V4L2_STD_PAL_M) || (p->std == V4L2_STD_NTSC)) in r820t_set_analog_freq()
2212 mutex_lock(&priv->lock); in r820t_set_analog_freq()
2213 if (fe->ops.i2c_gate_ctrl) in r820t_set_analog_freq()
2214 fe->ops.i2c_gate_ctrl(fe, 1); in r820t_set_analog_freq()
2216 rc = generic_set_freq(fe, 62500l * p->frequency, bw, in r820t_set_analog_freq()
2217 V4L2_TUNER_ANALOG_TV, p->std, SYS_UNDEFINED); in r820t_set_analog_freq()
2219 if (fe->ops.i2c_gate_ctrl) in r820t_set_analog_freq()
2220 fe->ops.i2c_gate_ctrl(fe, 0); in r820t_set_analog_freq()
2221 mutex_unlock(&priv->lock); in r820t_set_analog_freq()
2228 struct r820t_priv *priv = fe->tuner_priv; in r820t_set_params()
2229 struct dtv_frontend_properties *c = &fe->dtv_property_cache; in r820t_set_params()
2234 __func__, c->delivery_system, c->frequency, c->bandwidth_hz); in r820t_set_params()
2236 mutex_lock(&priv->lock); in r820t_set_params()
2237 if (fe->ops.i2c_gate_ctrl) in r820t_set_params()
2238 fe->ops.i2c_gate_ctrl(fe, 1); in r820t_set_params()
2240 bw = (c->bandwidth_hz + 500000) / 1000000; in r820t_set_params()
2244 rc = generic_set_freq(fe, c->frequency, bw, in r820t_set_params()
2245 V4L2_TUNER_DIGITAL_TV, 0, c->delivery_system); in r820t_set_params()
2247 if (fe->ops.i2c_gate_ctrl) in r820t_set_params()
2248 fe->ops.i2c_gate_ctrl(fe, 0); in r820t_set_params()
2249 mutex_unlock(&priv->lock); in r820t_set_params()
2258 struct r820t_priv *priv = fe->tuner_priv; in r820t_signal()
2261 mutex_lock(&priv->lock); in r820t_signal()
2262 if (fe->ops.i2c_gate_ctrl) in r820t_signal()
2263 fe->ops.i2c_gate_ctrl(fe, 1); in r820t_signal()
2265 if (priv->has_lock) { in r820t_signal()
2271 *strength = (45 - rc) << 4 | 0xff; in r820t_signal()
2279 if (fe->ops.i2c_gate_ctrl) in r820t_signal()
2280 fe->ops.i2c_gate_ctrl(fe, 0); in r820t_signal()
2281 mutex_unlock(&priv->lock); in r820t_signal()
2285 priv->has_lock ? "PLL locked" : "no signal", in r820t_signal()
2293 struct r820t_priv *priv = fe->tuner_priv; in r820t_get_if_frequency()
2297 *frequency = priv->int_freq; in r820t_get_if_frequency()
2304 struct r820t_priv *priv = fe->tuner_priv; in r820t_release()
2315 fe->tuner_priv = NULL; in r820t_release()
2338 int rc = -ENODEV; in r820t_attach()
2346 i2c, cfg->i2c_addr, in r820t_attach()
2354 priv->cfg = cfg; in r820t_attach()
2356 mutex_init(&priv->lock); in r820t_attach()
2358 fe->tuner_priv = priv; in r820t_attach()
2362 fe->tuner_priv = priv; in r820t_attach()
2366 if (fe->ops.i2c_gate_ctrl) in r820t_attach()
2367 fe->ops.i2c_gate_ctrl(fe, 1); in r820t_attach()
2380 r820t_chip_enum_to_str(cfg->rafael_chip)); in r820t_attach()
2382 if (fe->ops.i2c_gate_ctrl) in r820t_attach()
2383 fe->ops.i2c_gate_ctrl(fe, 0); in r820t_attach()
2387 memcpy(&fe->ops.tuner_ops, &r820t_tuner_ops, in r820t_attach()
2392 if (fe->ops.i2c_gate_ctrl) in r820t_attach()
2393 fe->ops.i2c_gate_ctrl(fe, 0); in r820t_attach()