Skip to content

Commit

Permalink
fix vga setting on freq change
Browse files Browse the repository at this point in the history
  • Loading branch information
krakenrf committed Mar 28, 2024
1 parent 4765898 commit 065e3d1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
1 change: 1 addition & 0 deletions include/tuner_r82xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
43 changes: 25 additions & 18 deletions src/tuner_r82xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 065e3d1

Please sign in to comment.