diff --git a/include/tuner_r82xx.h b/include/tuner_r82xx.h index a9b9f05..99d5682 100644 --- a/include/tuner_r82xx.h +++ b/include/tuner_r82xx.h @@ -118,5 +118,6 @@ int r82xx_set_freq(struct r82xx_priv *priv, uint32_t freq); int r82xx_set_gain(struct r82xx_priv *priv, int set_manual_gain, int gain); int r82xx_set_bandwidth(struct r82xx_priv *priv, int bandwidth, uint32_t rate); int r82xx_toggle_test(struct r82xx_priv *priv, int toggle); +int r82xx_set_vga_gain(struct r82xx_priv *priv); #endif diff --git a/src/tuner_r82xx.c b/src/tuner_r82xx.c index a70d62c..59aeb68 100644 --- a/src/tuner_r82xx.c +++ b/src/tuner_r82xx.c @@ -986,16 +986,7 @@ int r82xx_set_gain(struct r82xx_priv *priv, int set_manual_gain, int gain) if (rc < 0) return rc; - /* set fixed VGA gain based on frequency */ - if (priv->rf_freq > MHZ(1500)) { - rc = r82xx_write_reg_mask(priv, 0x0c, 0x0f, 0x9f); // Max 40.5 dB - } - else if (priv->rf_freq > MHZ(1000)) { - rc = r82xx_write_reg_mask(priv, 0x0c, 0x0b, 0x9f); - } - else { - rc = r82xx_write_reg_mask(priv, 0x0c, 0x08, 0x9f); // 16.3 dB - } + rc = r82xx_set_vga_gain(priv); if (rc < 0) return rc; @@ -1031,14 +1022,8 @@ int r82xx_set_gain(struct r82xx_priv *priv, int set_manual_gain, int gain) if (rc < 0) return rc; - /* set fixed VGA gain based on frequency */ - if (priv->rf_freq > MHZ(1500)) { - rc = r82xx_write_reg_mask(priv, 0x0c, 0x0f, 0x9f); - } - else { - /* set fixed VGA gain for now (26.5 dB) */ - rc = r82xx_write_reg_mask(priv, 0x0c, 0x0b, 0x9f); - } + /* set fixed VGA gain for now (26.5 dB) */ + rc = r82xx_write_reg_mask(priv, 0x0c, 0x0b, 0x9f); if (rc < 0) return rc; @@ -1047,6 +1032,24 @@ int r82xx_set_gain(struct r82xx_priv *priv, int set_manual_gain, int gain) return 0; } +int r82xx_set_vga_gain(struct r82xx_priv *priv) { + + int rc; + + /* set fixed VGA gain based on frequency */ + if (priv->rf_freq > MHZ(1350)) { + rc = r82xx_write_reg_mask(priv, 0x0c, 0x0f, 0x9f); // Max 40.5 dB + } + else if (priv->rf_freq > MHZ(1000)) { + rc = r82xx_write_reg_mask(priv, 0x0c, 0x0b, 0x9f); + } + else { + rc = r82xx_write_reg_mask(priv, 0x0c, 0x08, 0x9f); // 16.3 dB + } + + return rc; +} + /* Bandwidth contribution by low-pass filter. */ static const int r82xx_if_low_pass_bw_table[] = { 1700000, 1600000, 1550000, 1450000, 1200000, 900000, 700000, 550000, 450000, 350000 @@ -1168,6 +1171,10 @@ int r82xx_set_freq(struct r82xx_priv *priv, uint32_t freq) if (rc < 0) goto err; + rc = r82xx_set_vga_gain(priv); + if (rc < 0) + goto err; + rc = r82xx_set_pll(priv, lo_freq); if (rc < 0 || !priv->has_lock) goto err;