aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/tuners/r820t.c
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@redhat.com>2013-04-10 14:54:46 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2013-04-16 20:32:27 -0400
commitd75d538899da00bdf8f152c65a99eda1ab59daa3 (patch)
treeac90e2118786afbc380968f56c22f0b2cd27af58 /drivers/media/tuners/r820t.c
parent9cc2570a1dd74c22b4644b325257cf92d4cdb031 (diff)
[media] r820t: proper initialize the PLL register
The rtl-sdr library, from where this driver was initially based, doesn't use half PLL clock, but this is used on the Realtek Kernel driver. So, also do the same here. Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com> Tested-by: Antti Palosaari <crope@iki.fi>
Diffstat (limited to 'drivers/media/tuners/r820t.c')
-rw-r--r--drivers/media/tuners/r820t.c43
1 files changed, 28 insertions, 15 deletions
diff --git a/drivers/media/tuners/r820t.c b/drivers/media/tuners/r820t.c
index 279be4f78e7a..07d032350c1b 100644
--- a/drivers/media/tuners/r820t.c
+++ b/drivers/media/tuners/r820t.c
@@ -522,10 +522,12 @@ static int r820t_set_mux(struct r820t_priv *priv, u32 freq)
522 return rc; 522 return rc;
523} 523}
524 524
525static int r820t_set_pll(struct r820t_priv *priv, u32 freq) 525static int r820t_set_pll(struct r820t_priv *priv, enum v4l2_tuner_type type,
526 u32 freq)
526{ 527{
527 u64 tmp64, vco_freq; 528 u64 tmp64, vco_freq;
528 int rc, i; 529 int rc, i;
530 unsigned sleep_time = 10000;
529 u32 vco_fra; /* VCO contribution by SDM (kHz) */ 531 u32 vco_fra; /* VCO contribution by SDM (kHz) */
530 u32 vco_min = 1770000; 532 u32 vco_min = 1770000;
531 u32 vco_max = vco_min * 2; 533 u32 vco_max = vco_min * 2;
@@ -535,17 +537,34 @@ static int r820t_set_pll(struct r820t_priv *priv, u32 freq)
535 u8 mix_div = 2; 537 u8 mix_div = 2;
536 u8 div_buf = 0; 538 u8 div_buf = 0;
537 u8 div_num = 0; 539 u8 div_num = 0;
540 u8 refdiv2 = 0;
538 u8 ni, si, nint, vco_fine_tune, val; 541 u8 ni, si, nint, vco_fine_tune, val;
539 u8 data[5]; 542 u8 data[5];
540 543
541 freq = freq / 1000; /* Frequency in kHz */ 544 /* Frequency in kHz */
542 545 freq = freq / 1000;
543 pll_ref = priv->cfg->xtal / 1000; 546 pll_ref = priv->cfg->xtal / 1000;
544 547
545 tuner_dbg("set r820t pll for frequency %d kHz = %d\n", freq, pll_ref); 548 if ((priv->cfg->rafael_chip == CHIP_R620D) ||
549 (priv->cfg->rafael_chip == CHIP_R828D) ||
550 (priv->cfg->rafael_chip == CHIP_R828)) {
551 /* ref set refdiv2, reffreq = Xtal/2 on ATV application */
552 if (type != V4L2_TUNER_DIGITAL_TV) {
553 pll_ref /= 2;
554 refdiv2 = 0x10;
555 sleep_time = 20000;
556 }
557 } else {
558 if (priv->cfg->xtal > 24000000) {
559 pll_ref /= 2;
560 refdiv2 = 0x10;
561 }
562 }
546 563
547 /* FIXME: this seems to be a hack - probably it can be removed */ 564 tuner_dbg("set r820t pll for frequency %d kHz = %d%s\n",
548 rc = r820t_write_reg_mask(priv, 0x10, 0x00, 0x00); 565 freq, pll_ref, refdiv2 ? " / 2" : "");
566
567 rc = r820t_write_reg_mask(priv, 0x10, refdiv2, 0x10);
549 if (rc < 0) 568 if (rc < 0)
550 return rc; 569 return rc;
551 570
@@ -598,8 +617,6 @@ static int r820t_set_pll(struct r820t_priv *priv, u32 freq)
598 do_div(tmp64, 1000); 617 do_div(tmp64, 1000);
599 vco_fra = (u16)(tmp64); 618 vco_fra = (u16)(tmp64);
600 619
601 pll_ref /= 1000;
602
603 /* boundary spur prevention */ 620 /* boundary spur prevention */
604 if (vco_fra < pll_ref / 64) { 621 if (vco_fra < pll_ref / 64) {
605 vco_fra = 0; 622 vco_fra = 0;
@@ -653,11 +670,7 @@ static int r820t_set_pll(struct r820t_priv *priv, u32 freq)
653 return rc; 670 return rc;
654 671
655 for (i = 0; i < 2; i++) { 672 for (i = 0; i < 2; i++) {
656 /* 673 usleep_range(sleep_time, sleep_time + 1000);
657 * FIXME: Rafael chips R620D, R828D and R828 seems to
658 * need 20 ms for analog TV
659 */
660 usleep_range(10000, 11000);
661 674
662 /* Check if PLL has locked */ 675 /* Check if PLL has locked */
663 rc = r820t_read(priv, 0x00, data, 3); 676 rc = r820t_read(priv, 0x00, data, 3);
@@ -1040,7 +1053,7 @@ static int r820t_set_tv_standard(struct r820t_priv *priv,
1040 if (rc < 0) 1053 if (rc < 0)
1041 return rc; 1054 return rc;
1042 1055
1043 rc = r820t_set_pll(priv, filt_cal_lo); 1056 rc = r820t_set_pll(priv, type, filt_cal_lo);
1044 if (rc < 0 || !priv->has_lock) 1057 if (rc < 0 || !priv->has_lock)
1045 return rc; 1058 return rc;
1046 1059
@@ -1244,7 +1257,7 @@ static int generic_set_freq(struct dvb_frontend *fe,
1244 if (rc < 0) 1257 if (rc < 0)
1245 goto err; 1258 goto err;
1246 1259
1247 rc = r820t_set_pll(priv, lo_freq); 1260 rc = r820t_set_pll(priv, type, lo_freq);
1248 if (rc < 0 || !priv->has_lock) 1261 if (rc < 0 || !priv->has_lock)
1249 goto err; 1262 goto err;
1250 1263