Lines Matching +full:x +full:- +full:tal
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"
335 int r = reg - REG_SHADOW_START; in shadow_store()
343 if (len > NUM_REGS - r) in shadow_store()
344 len = NUM_REGS - r; in shadow_store()
346 tuner_dbg("%s: prev reg=%02x len=%d: %*ph\n", in shadow_store()
349 memcpy(&priv->regs[r], val, len); in shadow_store()
361 if (len > priv->cfg->max_i2c_msg_len - 1) in r820t_write()
362 size = priv->cfg->max_i2c_msg_len - 1; in r820t_write()
367 priv->buf[0] = reg; in r820t_write()
368 memcpy(&priv->buf[1], &val[pos], size); in r820t_write()
370 rc = tuner_i2c_xfer_send(&priv->i2c_props, priv->buf, size + 1); in r820t_write()
372 tuner_info("%s: i2c wr failed=%d reg=%02x len=%d: %*ph\n", in r820t_write()
373 __func__, rc, reg, size, size, &priv->buf[1]); in r820t_write()
376 return -EREMOTEIO; in r820t_write()
378 tuner_dbg("%s: i2c wr reg=%02x len=%d: %*ph\n", in r820t_write()
379 __func__, reg, size, size, &priv->buf[1]); in r820t_write()
382 len -= size; in r820t_write()
391 u8 tmp = val; /* work around GCC PR81715 with asan-stack=1 */ in r820t_write_reg()
398 reg -= REG_SHADOW_START; in r820t_read_cache_reg()
401 return priv->regs[reg]; in r820t_read_cache_reg()
403 return -EINVAL; in r820t_read_cache_reg()
423 u8 *p = &priv->buf[1]; in r820t_read()
425 priv->buf[0] = reg; in r820t_read()
427 rc = tuner_i2c_xfer_send_recv(&priv->i2c_props, priv->buf, 1, p, len); in r820t_read()
429 tuner_info("%s: i2c rd failed=%d reg=%02x len=%d: %*ph\n", in r820t_read()
433 return -EREMOTEIO; in r820t_read()
440 tuner_dbg("%s: i2c rd reg=%02x len=%d: %*ph\n", in r820t_read()
458 for (i = 0; i < ARRAY_SIZE(freq_ranges) - 1; i++) { in r820t_set_mux()
467 rc = r820t_write_reg_mask(priv, 0x17, range->open_d, 0x08); in r820t_set_mux()
472 rc = r820t_write_reg_mask(priv, 0x1a, range->rf_mux_ploy, 0xc3); in r820t_set_mux()
477 rc = r820t_write_reg(priv, 0x1b, range->tf_c); in r820t_set_mux()
482 switch (priv->xtal_cap_sel) { in r820t_set_mux()
485 val = range->xtal_cap20p | 0x08; in r820t_set_mux()
488 val = range->xtal_cap10p | 0x08; in r820t_set_mux()
491 val = range->xtal_cap0p | 0x00; in r820t_set_mux()
495 val = range->xtal_cap0p | 0x08; in r820t_set_mux()
502 if (priv->imr_done) { in r820t_set_mux()
503 reg08 = priv->imr_data[range->imr_mem].gain_x; in r820t_set_mux()
504 reg09 = priv->imr_data[range->imr_mem].phase_y; in r820t_set_mux()
539 pll_ref = priv->cfg->xtal / 1000; in r820t_set_pll()
542 /* Doesn't exist on rtl-sdk, and on field tests, caused troubles */ in r820t_set_pll()
543 if ((priv->cfg->rafael_chip == CHIP_R620D) || in r820t_set_pll()
544 (priv->cfg->rafael_chip == CHIP_R828D) || in r820t_set_pll()
545 (priv->cfg->rafael_chip == CHIP_R828)) { in r820t_set_pll()
553 if (priv->cfg->xtal > 24000000) { in r820t_set_pll()
601 if (priv->cfg->rafael_chip != CHIP_R828D) { in r820t_set_pll()
603 div_num = div_num - 1; in r820t_set_pll()
614 vco_fra = vco_freq - 2 * pll_ref * nint; in r820t_set_pll()
628 ni = (nint - 13) / 4; in r820t_set_pll()
629 si = nint - 4 * ni - 13; in r820t_set_pll()
649 vco_fra = vco_fra - 2 * pll_ref / n_sdm; in r820t_set_pll()
656 tuner_dbg("freq %d kHz, pll ref %d%s, sdm=0x%04x\n", in r820t_set_pll()
685 priv->has_lock = false; in r820t_set_pll()
689 priv->has_lock = true; in r820t_set_pll()
713 mixer_top = 0x14; /* mixer top:14 , top-1, low-discharge */ in r820t_sysfreq_sel()
718 mixer_top = 0x24; /* mixer top:13 , top-1, low-discharge */ in r820t_sysfreq_sel()
732 mixer_top = 0x24; /* mixer top:13 , top-1, low-discharge */ in r820t_sysfreq_sel()
745 mixer_top = 0x24; /* mixer top:13 , top-1, low-discharge */ in r820t_sysfreq_sel()
758 mixer_top = 0x24; /* mixer top:13 , top-1, low-discharge */ in r820t_sysfreq_sel()
770 default: /* DVB-T 8M */ in r820t_sysfreq_sel()
771 mixer_top = 0x24; /* mixer top:13 , top-1, low-discharge */ in r820t_sysfreq_sel()
785 if (priv->cfg->use_diplexer && in r820t_sysfreq_sel()
786 ((priv->cfg->rafael_chip == CHIP_R820T) || in r820t_sysfreq_sel()
787 (priv->cfg->rafael_chip == CHIP_R828S) || in r820t_sysfreq_sel()
788 (priv->cfg->rafael_chip == CHIP_R820C))) { in r820t_sysfreq_sel()
797 if (priv->cfg->use_predetect) { in r820t_sysfreq_sel()
816 /* Air-IN only for Astrometa */ in r820t_sysfreq_sel()
961 ext_enable = 0x40; /* r30[6]=1 ext enable; r30[5]:1 ext at lna max-1 */ in r820t_set_tv_standard()
973 ext_enable = 0x40; /* r30[6]=1 ext enable; r30[5]:1 ext at lna max-1 */ in r820t_set_tv_standard()
981 filt_cal_lo = 56000; /* 52000->56000 */ in r820t_set_tv_standard()
986 ext_enable = 0x60; /* r30[6]=1 ext enable; r30[5]:1 ext at lna max-1 */ 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()
1019 ext_enable = 0x60; /* r30[6]=1 ext enable; r30[5]:1 ext at lna max-1 */ in r820t_set_tv_standard()
1031 ext_enable = 0x60; /* r30[6]=1 ext enable; r30[5]:1 ext at lna max-1 */ in r820t_set_tv_standard()
1040 memcpy(priv->regs, r820t_init_array, sizeof(r820t_init_array)); in r820t_set_tv_standard()
1043 if (priv->imr_done) in r820t_set_tv_standard()
1044 val = 1 | priv->xtal_cap_sel << 1; in r820t_set_tv_standard()
1063 priv->int_freq = if_khz * 1000; in r820t_set_tv_standard()
1066 if (type != priv->type) in r820t_set_tv_standard()
1068 else if ((type == V4L2_TUNER_ANALOG_TV) && (std != priv->std)) in r820t_set_tv_standard()
1071 ((delsys != priv->delsys) || bw != priv->bw)) in r820t_set_tv_standard()
1089 /* X'tal cap 0pF for PLL */ in r820t_set_tv_standard()
1095 if (rc < 0 || !priv->has_lock) in r820t_set_tv_standard()
1120 priv->fil_cal_code = data[4] & 0x0f; in r820t_set_tv_standard()
1121 if (priv->fil_cal_code && priv->fil_cal_code != 0x0f) in r820t_set_tv_standard()
1125 if (priv->fil_cal_code == 0x0f) in r820t_set_tv_standard()
1126 priv->fil_cal_code = 0; in r820t_set_tv_standard()
1130 filt_q | priv->fil_cal_code, 0x1f); in r820t_set_tv_standard()
1175 /* Store current standard. If it changes, re-calibrate the tuner */ in r820t_set_tv_standard()
1176 priv->delsys = delsys; in r820t_set_tv_standard()
1177 priv->type = type; in r820t_set_tv_standard()
1178 priv->std = std; in r820t_set_tv_standard()
1179 priv->bw = bw; in r820t_set_tv_standard()
1200 * measured with a Racal 6103E GSM test set at 928 MHz with -60 dBm
1202 * http://steve-m.de/projects/rtl-sdr/gain_measurement/r820t/
1210 0, 5, 10, 10, 19, 9, 10, 25, 17, 10, 8, 16, 13, 6, 3, -8
1291 struct r820t_priv *priv = fe->tuner_priv; in generic_set_freq()
1303 lo_freq = freq - priv->int_freq; in generic_set_freq()
1305 lo_freq = freq + priv->int_freq; in generic_set_freq()
1312 if (rc < 0 || !priv->has_lock) in generic_set_freq()
1338 if (!priv->init_done) in r820t_standby()
1374 priv->type = -1; in r820t_standby()
1389 memcpy(priv->regs, r820t_init_array, sizeof(r820t_init_array)); in r820t_xtal_check()
1428 if (priv->cfg->xtal == 16000000 && (val > 29 || val < 23)) in r820t_xtal_check()
1436 return -EINVAL; in r820t_xtal_check()
1446 memcpy(priv->regs, r820t_init_array, sizeof(r820t_init_array)); in r820t_imr_prepare()
1448 /* lna off (air-in off) */ in r820t_imr_prepare()
1520 rc = sum - max - min; in r820t_multi_read()
1529 struct r820t_sect_type cross[5]; /* (0,0)(0,Q-1)(0,I-1)(Q-1,0)(I-1,0) */ in r820t_imr_cross()
1549 cross[i].phase_y = reg09 + 1; /* Q-1 */ in r820t_imr_cross()
1553 cross[i].phase_y = (reg09 | 0x20) + 1; /* I-1 */ in r820t_imr_cross()
1556 cross[i].gain_x = reg08 + 1; /* Q-1 */ in r820t_imr_cross()
1560 cross[i].gain_x = (reg08 | 0x20) + 1; /* I-1 */ in r820t_imr_cross()
1582 if ((tmp.phase_y & 0x1f) == 1) { /* y-direction */ in r820t_imr_cross()
1588 } else { /* (0,0) or x-direction */ in r820t_imr_cross()
1602 for (i = 3; i > 0; i--) { in r820t_compre_cor()
1603 if (iq[0].value > iq[i - 1].value) in r820t_compre_cor()
1604 swap(iq[0], iq[i - 1]); in r820t_compre_cor()
1698 if (i == 0) { /* try right-side point */ in r820t_iq_tree()
1700 } else if (i == 1) { /* try left-side point */ in r820t_iq_tree()
1703 tmp = 2 - (var_val & 0x1f); in r820t_iq_tree()
1705 /* b[5]:I/Q selection. 0:Q-path, 1:I-path */ in r820t_iq_tree()
1713 var_val -= 2; in r820t_iq_tree()
1727 /* Try X-1 column and save min result to compare_bet[0] */ in r820t_section()
1728 if (!(iq_point->gain_x & 0x1f)) in r820t_section()
1729 compare_iq[0].gain_x = ((iq_point->gain_x) & 0xdf) + 1; /* Q-path, Gain=1 */ in r820t_section()
1731 compare_iq[0].gain_x = iq_point->gain_x - 1; /* left point */ in r820t_section()
1732 compare_iq[0].phase_y = iq_point->phase_y; in r820t_section()
1734 /* y-direction */ in r820t_section()
1744 /* Try X column and save min result to compare_bet[1] */ in r820t_section()
1745 compare_iq[0].gain_x = iq_point->gain_x; in r820t_section()
1746 compare_iq[0].phase_y = iq_point->phase_y; in r820t_section()
1757 /* Try X+1 column and save min result to compare_bet[2] */ in r820t_section()
1758 if ((iq_point->gain_x & 0x1f) == 0x00) in r820t_section()
1759 compare_iq[0].gain_x = ((iq_point->gain_x) | 0x20) + 1; /* I-path, Gain=1 */ in r820t_section()
1761 compare_iq[0].gain_x = iq_point->gain_x + 1; in r820t_section()
1762 compare_iq[0].phase_y = iq_point->phase_y; in r820t_section()
1808 u8 x_direction = 0; /* 1:x, 0:y */ in r820t_iq()
1855 /* section-9 check */ in r820t_iq()
1878 * try (x-1), (x), (x+1) columns, and find min IMR result point in r820t_f_imr()
1895 if (priv->cfg->xtal > 24000000) in r820t_imr()
1896 ring_ref = priv->cfg->xtal / 2000; in r820t_imr()
1898 ring_ref = priv->cfg->xtal / 1000; in r820t_imr()
1979 rc = r820t_set_mux(priv, (ring_freq - 5300) * 1000); in r820t_imr()
1984 (ring_freq - 5300) * 1000); in r820t_imr()
1985 if (!priv->has_lock) in r820t_imr()
1986 rc = -EINVAL; in r820t_imr()
1993 imr_point.gain_x = priv->imr_data[3].gain_x; in r820t_imr()
1994 imr_point.phase_y = priv->imr_data[3].phase_y; in r820t_imr()
1995 imr_point.value = priv->imr_data[3].value; in r820t_imr()
2005 priv->imr_data[0].gain_x = imr_point.gain_x; in r820t_imr()
2006 priv->imr_data[0].phase_y = imr_point.phase_y; in r820t_imr()
2007 priv->imr_data[0].value = imr_point.value; in r820t_imr()
2010 priv->imr_data[1].gain_x = imr_point.gain_x; in r820t_imr()
2011 priv->imr_data[1].phase_y = imr_point.phase_y; in r820t_imr()
2012 priv->imr_data[1].value = imr_point.value; in r820t_imr()
2015 priv->imr_data[2].gain_x = imr_point.gain_x; in r820t_imr()
2016 priv->imr_data[2].phase_y = imr_point.phase_y; in r820t_imr()
2017 priv->imr_data[2].value = imr_point.value; in r820t_imr()
2020 priv->imr_data[3].gain_x = imr_point.gain_x; in r820t_imr()
2021 priv->imr_data[3].phase_y = imr_point.phase_y; in r820t_imr()
2022 priv->imr_data[3].value = imr_point.value; in r820t_imr()
2025 priv->imr_data[4].gain_x = imr_point.gain_x; in r820t_imr()
2026 priv->imr_data[4].phase_y = imr_point.phase_y; in r820t_imr()
2027 priv->imr_data[4].value = imr_point.value; in r820t_imr()
2030 priv->imr_data[4].gain_x = imr_point.gain_x; in r820t_imr()
2031 priv->imr_data[4].phase_y = imr_point.phase_y; in r820t_imr()
2032 priv->imr_data[4].value = imr_point.value; in r820t_imr()
2044 if (priv->init_done) in r820t_imr_callibrate()
2048 if ((priv->cfg->rafael_chip == CHIP_R820T) || in r820t_imr_callibrate()
2049 (priv->cfg->rafael_chip == CHIP_R828S) || in r820t_imr_callibrate()
2050 (priv->cfg->rafael_chip == CHIP_R820C)) { in r820t_imr_callibrate()
2051 priv->xtal_cap_sel = XTAL_HIGH_CAP_0P; in r820t_imr_callibrate()
2065 priv->xtal_cap_sel = xtal_cap; in r820t_imr_callibrate()
2070 * as what is done by rtl-sdr userspace library. Useful for testing in r820t_imr_callibrate()
2073 priv->init_done = true; in r820t_imr_callibrate()
2104 priv->init_done = true; in r820t_imr_callibrate()
2105 priv->imr_done = true; in r820t_imr_callibrate()
2126 struct r820t_priv *priv = fe->tuner_priv; in r820t_init()
2131 mutex_lock(&priv->lock); in r820t_init()
2132 if (fe->ops.i2c_gate_ctrl) in r820t_init()
2133 fe->ops.i2c_gate_ctrl(fe, 1); in r820t_init()
2144 if (fe->ops.i2c_gate_ctrl) in r820t_init()
2145 fe->ops.i2c_gate_ctrl(fe, 0); in r820t_init()
2146 mutex_unlock(&priv->lock); in r820t_init()
2155 struct r820t_priv *priv = fe->tuner_priv; in r820t_sleep()
2160 mutex_lock(&priv->lock); in r820t_sleep()
2161 if (fe->ops.i2c_gate_ctrl) in r820t_sleep()
2162 fe->ops.i2c_gate_ctrl(fe, 1); in r820t_sleep()
2166 if (fe->ops.i2c_gate_ctrl) in r820t_sleep()
2167 fe->ops.i2c_gate_ctrl(fe, 0); in r820t_sleep()
2168 mutex_unlock(&priv->lock); in r820t_sleep()
2177 struct r820t_priv *priv = fe->tuner_priv; in r820t_set_analog_freq()
2184 if (!p->std) in r820t_set_analog_freq()
2185 p->std = V4L2_STD_MN; in r820t_set_analog_freq()
2187 if ((p->std == V4L2_STD_PAL_M) || (p->std == V4L2_STD_NTSC)) in r820t_set_analog_freq()
2192 mutex_lock(&priv->lock); in r820t_set_analog_freq()
2193 if (fe->ops.i2c_gate_ctrl) in r820t_set_analog_freq()
2194 fe->ops.i2c_gate_ctrl(fe, 1); in r820t_set_analog_freq()
2196 rc = generic_set_freq(fe, 62500l * p->frequency, bw, in r820t_set_analog_freq()
2197 V4L2_TUNER_ANALOG_TV, p->std, SYS_UNDEFINED); in r820t_set_analog_freq()
2199 if (fe->ops.i2c_gate_ctrl) in r820t_set_analog_freq()
2200 fe->ops.i2c_gate_ctrl(fe, 0); in r820t_set_analog_freq()
2201 mutex_unlock(&priv->lock); in r820t_set_analog_freq()
2208 struct r820t_priv *priv = fe->tuner_priv; in r820t_set_params()
2209 struct dtv_frontend_properties *c = &fe->dtv_property_cache; in r820t_set_params()
2214 __func__, c->delivery_system, c->frequency, c->bandwidth_hz); in r820t_set_params()
2216 mutex_lock(&priv->lock); in r820t_set_params()
2217 if (fe->ops.i2c_gate_ctrl) in r820t_set_params()
2218 fe->ops.i2c_gate_ctrl(fe, 1); in r820t_set_params()
2220 bw = (c->bandwidth_hz + 500000) / 1000000; in r820t_set_params()
2224 rc = generic_set_freq(fe, c->frequency, bw, in r820t_set_params()
2225 V4L2_TUNER_DIGITAL_TV, 0, c->delivery_system); in r820t_set_params()
2227 if (fe->ops.i2c_gate_ctrl) in r820t_set_params()
2228 fe->ops.i2c_gate_ctrl(fe, 0); in r820t_set_params()
2229 mutex_unlock(&priv->lock); in r820t_set_params()
2238 struct r820t_priv *priv = fe->tuner_priv; in r820t_signal()
2241 mutex_lock(&priv->lock); in r820t_signal()
2242 if (fe->ops.i2c_gate_ctrl) in r820t_signal()
2243 fe->ops.i2c_gate_ctrl(fe, 1); in r820t_signal()
2245 if (priv->has_lock) { in r820t_signal()
2251 *strength = (45 - rc) << 4 | 0xff; in r820t_signal()
2259 if (fe->ops.i2c_gate_ctrl) in r820t_signal()
2260 fe->ops.i2c_gate_ctrl(fe, 0); in r820t_signal()
2261 mutex_unlock(&priv->lock); in r820t_signal()
2265 priv->has_lock ? "PLL locked" : "no signal", in r820t_signal()
2273 struct r820t_priv *priv = fe->tuner_priv; in r820t_get_if_frequency()
2277 *frequency = priv->int_freq; in r820t_get_if_frequency()
2284 struct r820t_priv *priv = fe->tuner_priv; in r820t_release()
2295 fe->tuner_priv = NULL; in r820t_release()
2318 int rc = -ENODEV; in r820t_attach()
2326 i2c, cfg->i2c_addr, in r820t_attach()
2334 priv->cfg = cfg; in r820t_attach()
2336 mutex_init(&priv->lock); in r820t_attach()
2338 fe->tuner_priv = priv; in r820t_attach()
2342 fe->tuner_priv = priv; in r820t_attach()
2346 if (fe->ops.i2c_gate_ctrl) in r820t_attach()
2347 fe->ops.i2c_gate_ctrl(fe, 1); in r820t_attach()
2360 if (fe->ops.i2c_gate_ctrl) in r820t_attach()
2361 fe->ops.i2c_gate_ctrl(fe, 0); in r820t_attach()
2365 memcpy(&fe->ops.tuner_ops, &r820t_tuner_ops, in r820t_attach()
2370 if (fe->ops.i2c_gate_ctrl) in r820t_attach()
2371 fe->ops.i2c_gate_ctrl(fe, 0); in r820t_attach()