Skip to content

Commit

Permalink
r82xx: register caching
Browse files Browse the repository at this point in the history
  • Loading branch information
keenerd committed Aug 3, 2014
1 parent a7caaac commit 4198f7d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions include/tuner_r82xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ struct r82xx_priv {
int has_lock;
int init_done;
int disable_dither;
int reg_cache;

/* Store current mode */
uint32_t delsys;
Expand Down
18 changes: 13 additions & 5 deletions src/tuner_r82xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,6 @@ static int r82xx_write(struct r82xx_priv *priv, uint8_t reg, const uint8_t *val,
return 0;
}

static int r82xx_write_reg(struct r82xx_priv *priv, uint8_t reg, uint8_t val)
{
return r82xx_write(priv, reg, &val, 1);
}

static int r82xx_read_cache_reg(struct r82xx_priv *priv, int reg)
{
reg -= REG_SHADOW_START;
Expand All @@ -301,6 +296,13 @@ static int r82xx_read_cache_reg(struct r82xx_priv *priv, int reg)
return -1;
}

static int r82xx_write_reg(struct r82xx_priv *priv, uint8_t reg, uint8_t val)
{
if (priv->reg_cache && r82xx_read_cache_reg(priv, reg) == val)
return 0;
return r82xx_write(priv, reg, &val, 1);
}

static int r82xx_write_reg_mask(struct r82xx_priv *priv, uint8_t reg, uint8_t val,
uint8_t bit_mask)
{
Expand All @@ -311,6 +313,8 @@ static int r82xx_write_reg_mask(struct r82xx_priv *priv, uint8_t reg, uint8_t va

val = (rc & ~bit_mask) | (val & bit_mask);

if (priv->reg_cache && r82xx_read_cache_reg(priv, reg) == val)
return 0;
return r82xx_write(priv, reg, &val, 1);
}

Expand Down Expand Up @@ -1090,6 +1094,7 @@ int r82xx_standby(struct r82xx_priv *priv)
if (!priv->init_done)
return 0;

priv->reg_cache = 0;
rc = r82xx_write_reg(priv, 0x06, 0xb1);
if (rc < 0)
return rc;
Expand Down Expand Up @@ -1125,6 +1130,7 @@ int r82xx_standby(struct r82xx_priv *priv)
/* Force initial calibration */
priv->type = -1;

priv->reg_cache = 1;
return rc;
}

Expand Down Expand Up @@ -1199,6 +1205,7 @@ int r82xx_init(struct r82xx_priv *priv)
priv->xtal_cap_sel = XTAL_HIGH_CAP_0P;

/* Initialize registers */
priv->reg_cache = 0;
rc = r82xx_write(priv, 0x05,
r82xx_init_array, sizeof(r82xx_init_array));

Expand All @@ -1212,6 +1219,7 @@ int r82xx_init(struct r82xx_priv *priv)
rc |= r82xx_sysfreq_sel(priv, 0, TUNER_DIGITAL_TV, SYS_DVBT);

priv->init_done = 1;
priv->reg_cache = 1;

err:
if (rc < 0)
Expand Down

0 comments on commit 4198f7d

Please sign in to comment.