aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb-frontends/rtl2832.c
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@redhat.com>2013-04-09 21:16:52 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2013-04-16 20:27:19 -0400
commit884655ad2e85ebcd84b10b82fca2ef8e431d4392 (patch)
tree412be7fcdb4f1fabdacd6b1639a8859d274bb4ed /drivers/media/dvb-frontends/rtl2832.c
parenta7dd065f4976b54d0e75d58f8e94066501fede76 (diff)
[media] rtl2832: properly set en_bbin for r820t
DVBT_EN_BBIN should be set on both places where IF is set. So, move it to a function and call it where needed. Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com> Tested-by: Antti Palosaari <crope@iki.fi>
Diffstat (limited to 'drivers/media/dvb-frontends/rtl2832.c')
-rw-r--r--drivers/media/dvb-frontends/rtl2832.c63
1 files changed, 31 insertions, 32 deletions
diff --git a/drivers/media/dvb-frontends/rtl2832.c b/drivers/media/dvb-frontends/rtl2832.c
index b6f50c7a15e6..2f5a2b504932 100644
--- a/drivers/media/dvb-frontends/rtl2832.c
+++ b/drivers/media/dvb-frontends/rtl2832.c
@@ -380,13 +380,37 @@ err:
380 return ret; 380 return ret;
381} 381}
382 382
383static int rtl2832_init(struct dvb_frontend *fe) 383
384static int rtl2832_set_if(struct dvb_frontend *fe, u32 if_freq)
384{ 385{
385 struct rtl2832_priv *priv = fe->demodulator_priv; 386 struct rtl2832_priv *priv = fe->demodulator_priv;
386 int i, ret, len; 387 int ret;
387 u8 en_bbin;
388 u64 pset_iffreq; 388 u64 pset_iffreq;
389 u8 en_bbin = (if_freq == 0 ? 0x1 : 0x0);
390
391 /*
392 * PSET_IFFREQ = - floor((IfFreqHz % CrystalFreqHz) * pow(2, 22)
393 * / CrystalFreqHz)
394 */
395
396 pset_iffreq = if_freq % priv->cfg.xtal;
397 pset_iffreq *= 0x400000;
398 pset_iffreq = div_u64(pset_iffreq, priv->cfg.xtal);
399 pset_iffreq = pset_iffreq & 0x3fffff;
400 ret = rtl2832_wr_demod_reg(priv, DVBT_EN_BBIN, en_bbin);
401 if (ret)
402 return ret;
403
404 ret = rtl2832_wr_demod_reg(priv, DVBT_PSET_IFFREQ, pset_iffreq);
405
406 return (ret);
407}
408
409static int rtl2832_init(struct dvb_frontend *fe)
410{
411 struct rtl2832_priv *priv = fe->demodulator_priv;
389 const struct rtl2832_reg_value *init; 412 const struct rtl2832_reg_value *init;
413 int i, ret, len;
390 414
391 /* initialization values for the demodulator registers */ 415 /* initialization values for the demodulator registers */
392 struct rtl2832_reg_value rtl2832_initial_regs[] = { 416 struct rtl2832_reg_value rtl2832_initial_regs[] = {
@@ -436,8 +460,6 @@ static int rtl2832_init(struct dvb_frontend *fe)
436 460
437 dev_dbg(&priv->i2c->dev, "%s:\n", __func__); 461 dev_dbg(&priv->i2c->dev, "%s:\n", __func__);
438 462
439 en_bbin = (priv->cfg.if_dvbt == 0 ? 0x1 : 0x0);
440
441 for (i = 0; i < ARRAY_SIZE(rtl2832_initial_regs); i++) { 463 for (i = 0; i < ARRAY_SIZE(rtl2832_initial_regs); i++) {
442 ret = rtl2832_wr_demod_reg(priv, rtl2832_initial_regs[i].reg, 464 ret = rtl2832_wr_demod_reg(priv, rtl2832_initial_regs[i].reg,
443 rtl2832_initial_regs[i].value); 465 rtl2832_initial_regs[i].value);
@@ -477,27 +499,10 @@ static int rtl2832_init(struct dvb_frontend *fe)
477 goto err; 499 goto err;
478 } 500 }
479 501
480 /*
481 * if frequency settings
482 * Some tuners (r820t) don't initialize IF here; instead; they do it
483 * at set_params()
484 */
485 if (!fe->ops.tuner_ops.get_if_frequency) { 502 if (!fe->ops.tuner_ops.get_if_frequency) {
486 /* 503 ret = rtl2832_set_if(fe, priv->cfg.if_dvbt);
487 * PSET_IFFREQ = - floor((IfFreqHz % CrystalFreqHz) * pow(2, 22) 504 if (ret)
488 * / CrystalFreqHz) 505 goto err;
489 */
490 pset_iffreq = priv->cfg.if_dvbt % priv->cfg.xtal;
491 pset_iffreq *= 0x400000;
492 pset_iffreq = div_u64(pset_iffreq, priv->cfg.xtal);
493 pset_iffreq = pset_iffreq & 0x3fffff;
494 ret = rtl2832_wr_demod_reg(priv, DVBT_EN_BBIN, en_bbin);
495 if (ret)
496 goto err;
497
498 ret = rtl2832_wr_demod_reg(priv, DVBT_PSET_IFFREQ, pset_iffreq);
499 if (ret)
500 goto err;
501 } 506 }
502 507
503 /* 508 /*
@@ -590,18 +595,12 @@ static int rtl2832_set_frontend(struct dvb_frontend *fe)
590 /* If the frontend has get_if_frequency(), use it */ 595 /* If the frontend has get_if_frequency(), use it */
591 if (fe->ops.tuner_ops.get_if_frequency) { 596 if (fe->ops.tuner_ops.get_if_frequency) {
592 u32 if_freq; 597 u32 if_freq;
593 u64 pset_iffreq;
594 598
595 ret = fe->ops.tuner_ops.get_if_frequency(fe, &if_freq); 599 ret = fe->ops.tuner_ops.get_if_frequency(fe, &if_freq);
596 if (ret) 600 if (ret)
597 goto err; 601 goto err;
598 602
599 pset_iffreq = if_freq % priv->cfg.xtal; 603 ret = rtl2832_set_if(fe, if_freq);
600 pset_iffreq *= 0x400000;
601 pset_iffreq = div_u64(pset_iffreq, priv->cfg.xtal);
602 pset_iffreq = pset_iffreq & 0x3fffff;
603
604 ret = rtl2832_wr_demod_reg(priv, DVBT_PSET_IFFREQ, pset_iffreq);
605 if (ret) 604 if (ret)
606 goto err; 605 goto err;
607 } 606 }