Skip to content

Commit a0b6131

Browse files
committed
r82xx: register batching
1 parent 4198f7d commit a0b6131

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

include/tuner_r82xx.h

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ struct r82xx_priv {
8787
int init_done;
8888
int disable_dither;
8989
int reg_cache;
90+
int reg_batch, reg_low, reg_high;
9091

9192
/* Store current mode */
9293
uint32_t delsys;

src/tuner_r82xx.c

+51-3
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,14 @@ static int r82xx_write_reg(struct r82xx_priv *priv, uint8_t reg, uint8_t val)
300300
{
301301
if (priv->reg_cache && r82xx_read_cache_reg(priv, reg) == val)
302302
return 0;
303+
if (priv->reg_batch) {
304+
shadow_store(priv, reg, &val, 1);
305+
if (reg < priv->reg_low)
306+
priv->reg_low = reg;
307+
if (reg > priv->reg_high)
308+
priv->reg_high = reg;
309+
return 0;
310+
}
303311
return r82xx_write(priv, reg, &val, 1);
304312
}
305313

@@ -313,9 +321,34 @@ static int r82xx_write_reg_mask(struct r82xx_priv *priv, uint8_t reg, uint8_t va
313321

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

316-
if (priv->reg_cache && r82xx_read_cache_reg(priv, reg) == val)
317-
return 0;
318-
return r82xx_write(priv, reg, &val, 1);
324+
return r82xx_write_reg(priv, reg, val);
325+
}
326+
327+
static int r82xx_write_batch_init(struct r82xx_priv *priv)
328+
{
329+
priv->reg_batch = 0;
330+
if (priv->reg_cache) {
331+
priv->reg_batch = 1;
332+
priv->reg_low = NUM_REGS;
333+
priv->reg_high = 0;
334+
}
335+
return 0;
336+
}
337+
338+
static int r82xx_write_batch_sync(struct r82xx_priv *priv)
339+
{
340+
int rc, offset, len;
341+
if (!priv->reg_cache)
342+
return -1;
343+
if (!priv->reg_batch)
344+
return -1;
345+
priv->reg_batch = 0;
346+
if (priv->reg_low > priv->reg_high)
347+
return -1;
348+
offset = priv->reg_low - REG_SHADOW_START;
349+
len = priv->reg_high - priv->reg_low + 1;
350+
rc = r82xx_write(priv, priv->reg_low, priv->regs+offset, len);
351+
return rc;
319352
}
320353

321354
static uint8_t r82xx_bitrev(uint8_t byte)
@@ -437,6 +470,8 @@ static int r82xx_set_pll(struct r82xx_priv *priv, uint32_t freq)
437470
uint8_t ni, si, nint, vco_fine_tune, val;
438471
uint8_t data[5];
439472

473+
r82xx_write_batch_init(priv);
474+
440475
/* Frequency in kHz */
441476
freq_khz = (freq + 500) / 1000;
442477
pll_ref = priv->cfg->xtal;
@@ -535,6 +570,14 @@ static int r82xx_set_pll(struct r82xx_priv *priv, uint32_t freq)
535570
if (rc < 0)
536571
return rc;
537572

573+
if (priv->reg_batch) {
574+
rc = r82xx_write_batch_sync(priv);
575+
if (rc < 0) {
576+
fprintf(stderr, "[R82XX] Batch error in PLL for %u Hz!\n", freq);
577+
return rc;
578+
}
579+
}
580+
538581
for (i = 0; i < 2; i++) {
539582
// usleep_range(sleep_time, sleep_time + 1000);
540583

@@ -1026,6 +1069,8 @@ int r82xx_set_freq(struct r82xx_priv *priv, uint32_t freq)
10261069
uint32_t lo_freq = freq + priv->int_freq;
10271070
uint8_t air_cable1_in;
10281071

1072+
r82xx_write_batch_init(priv);
1073+
10291074
rc = r82xx_set_mux(priv, lo_freq);
10301075
if (rc < 0)
10311076
goto err;
@@ -1046,6 +1091,9 @@ int r82xx_set_freq(struct r82xx_priv *priv, uint32_t freq)
10461091
rc = r82xx_write_reg_mask(priv, 0x05, air_cable1_in, 0x60);
10471092
}
10481093

1094+
if (priv->reg_batch) {
1095+
rc = r82xx_write_batch_sync(priv);
1096+
}
10491097
err:
10501098
if (rc < 0)
10511099
fprintf(stderr, "%s: failed=%d\n", __FUNCTION__, rc);

0 commit comments

Comments
 (0)