Skip to content

Commit 29d2c84

Browse files
committed
r82xx: pll tweaks beyond my ken
1 parent d59b178 commit 29d2c84

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

src/tuner_r82xx.c

+13-15
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,6 @@ static int r82xx_set_pll(struct r82xx_priv *priv, uint32_t freq)
460460
uint32_t vco_min = 1770000;
461461
uint32_t vco_max = vco_min * 2;
462462
uint32_t freq_khz, pll_ref, pll_ref_khz;
463-
uint16_t n_sdm = 2;
464463
uint16_t sdm = 0;
465464
uint8_t mix_div = 2;
466465
uint8_t div_buf = 0;
@@ -492,6 +491,8 @@ static int r82xx_set_pll(struct r82xx_priv *priv, uint32_t freq)
492491
return rc;
493492

494493
/* Calculate divider */
494+
if(freq_khz < vco_min/64) vco_min /= 2;
495+
if(freq_khz >= vco_max/2) vco_max *= 2;
495496
while (mix_div <= 64) {
496497
if (((freq_khz * mix_div) >= vco_min) &&
497498
((freq_khz * mix_div) < vco_max)) {
@@ -505,14 +506,16 @@ static int r82xx_set_pll(struct r82xx_priv *priv, uint32_t freq)
505506
mix_div = mix_div << 1;
506507
}
507508

508-
rc = r82xx_read(priv, 0x00, data, sizeof(data));
509-
if (rc < 0)
510-
return rc;
511-
512509
if (priv->cfg->rafael_chip == CHIP_R828D)
513510
vco_power_ref = 1;
514511

512+
/*
513+
rc = r82xx_read(priv, 0x00, data, sizeof(data));
514+
if (rc < 0)
515+
return rc;
515516
vco_fine_tune = (data[4] & 0x30) >> 4;
517+
*/
518+
vco_fine_tune = 2;
516519

517520
if (vco_fine_tune > vco_power_ref)
518521
div_num = div_num - 1;
@@ -527,7 +530,10 @@ static int r82xx_set_pll(struct r82xx_priv *priv, uint32_t freq)
527530
nint = vco_freq / (2 * pll_ref);
528531
vco_fra = (vco_freq - 2 * pll_ref * nint) / 1000;
529532

530-
if (nint > ((128 / vco_power_ref) - 1)) {
533+
if (priv->cfg->rafael_chip == CHIP_R828D && nint > 127) {
534+
fprintf(stderr, "[R828D] No valid PLL values for %u Hz!\n", freq);
535+
return -1;
536+
} else if (nint > 76) {
531537
fprintf(stderr, "[R82XX] No valid PLL values for %u Hz!\n", freq);
532538
return -1;
533539
}
@@ -553,15 +559,7 @@ static int r82xx_set_pll(struct r82xx_priv *priv, uint32_t freq)
553559
return rc;
554560

555561
/* sdm calculator */
556-
while (vco_fra > 1) {
557-
if (vco_fra > (2 * pll_ref_khz / n_sdm)) {
558-
sdm = sdm + 32768 / (n_sdm / 2);
559-
vco_fra = vco_fra - 2 * pll_ref_khz / n_sdm;
560-
if (n_sdm >= 0x8000)
561-
break;
562-
}
563-
n_sdm <<= 1;
564-
}
562+
sdm = (((vco_freq<<16)+pll_ref) / (2*pll_ref)) & 0xFFFF;
565563

566564
rc = r82xx_write_reg(priv, 0x16, sdm >> 8);
567565
if (rc < 0)

0 commit comments

Comments
 (0)