aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
authorHans-Frieder Vogt <hfvogt@gmx.net>2012-05-12 04:11:47 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-05-20 09:22:17 -0400
commitb144c98ca0962ee3cbdbbeafe77a1b300be0cb4f (patch)
tree915f6a0c9904275ad0028afb6336d3fd35702c90 /drivers/media
parent4a14db7e61a1aa3ef379eb63ff2c5943218bb8cc (diff)
[media] fc0013 ver. 0.2: introduction of get_rf_strength function
Changes compared to version 0.1 of driver (sent 6 May): - Initial implementation of get_rf_strength function. - Introduction of a warning message Signed-off-by: Hans-Frieder Vogt <hfvogt@gmx.net> Signed-off-by: Antti Palosaari <crope@iki.fi> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media')
-rw-r--r--drivers/media/common/tuners/fc0013.c74
1 files changed, 73 insertions, 1 deletions
diff --git a/drivers/media/common/tuners/fc0013.c b/drivers/media/common/tuners/fc0013.c
index 7398d7759e08..bd8f0f1e8f3b 100644
--- a/drivers/media/common/tuners/fc0013.c
+++ b/drivers/media/common/tuners/fc0013.c
@@ -484,6 +484,8 @@ static int fc0013_set_params(struct dvb_frontend *fe)
484exit: 484exit:
485 if (fe->ops.i2c_gate_ctrl) 485 if (fe->ops.i2c_gate_ctrl)
486 fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */ 486 fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */
487 if (ret)
488 warn("%s: failed: %d", __func__, ret);
487 return ret; 489 return ret;
488} 490}
489 491
@@ -508,6 +510,74 @@ static int fc0013_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
508 return 0; 510 return 0;
509} 511}
510 512
513#define INPUT_ADC_LEVEL -8
514
515static int fc0013_get_rf_strength(struct dvb_frontend *fe, u16 *strength)
516{
517 struct fc0013_priv *priv = fe->tuner_priv;
518 int ret;
519 unsigned char tmp;
520 int int_temp, lna_gain, int_lna, tot_agc_gain, power;
521 const int fc0013_lna_gain_table[] = {
522 /* low gain */
523 -63, -58, -99, -73,
524 -63, -65, -54, -60,
525 /* middle gain */
526 71, 70, 68, 67,
527 65, 63, 61, 58,
528 /* high gain */
529 197, 191, 188, 186,
530 184, 182, 181, 179,
531 };
532
533 if (fe->ops.i2c_gate_ctrl)
534 fe->ops.i2c_gate_ctrl(fe, 1); /* open I2C-gate */
535
536 ret = fc0013_writereg(priv, 0x13, 0x00);
537 if (ret)
538 goto err;
539
540 ret = fc0013_readreg(priv, 0x13, &tmp);
541 if (ret)
542 goto err;
543 int_temp = tmp;
544
545 ret = fc0013_readreg(priv, 0x14, &tmp);
546 if (ret)
547 goto err;
548 lna_gain = tmp & 0x1f;
549
550 if (fe->ops.i2c_gate_ctrl)
551 fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */
552
553 if (lna_gain < ARRAY_SIZE(fc0013_lna_gain_table)) {
554 int_lna = fc0013_lna_gain_table[lna_gain];
555 tot_agc_gain = (abs((int_temp >> 5) - 7) - 2 +
556 (int_temp & 0x1f)) * 2;
557 power = INPUT_ADC_LEVEL - tot_agc_gain - int_lna / 10;
558
559 if (power >= 45)
560 *strength = 255; /* 100% */
561 else if (power < -95)
562 *strength = 0;
563 else
564 *strength = (power + 95) * 255 / 140;
565
566 *strength |= *strength << 8;
567 } else {
568 ret = -1;
569 }
570
571 goto exit;
572
573err:
574 if (fe->ops.i2c_gate_ctrl)
575 fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */
576exit:
577 if (ret)
578 warn("%s: failed: %d", __func__, ret);
579 return ret;
580}
511 581
512static const struct dvb_tuner_ops fc0013_tuner_ops = { 582static const struct dvb_tuner_ops fc0013_tuner_ops = {
513 .info = { 583 .info = {
@@ -528,6 +598,8 @@ static const struct dvb_tuner_ops fc0013_tuner_ops = {
528 .get_frequency = fc0013_get_frequency, 598 .get_frequency = fc0013_get_frequency,
529 .get_if_frequency = fc0013_get_if_frequency, 599 .get_if_frequency = fc0013_get_if_frequency,
530 .get_bandwidth = fc0013_get_bandwidth, 600 .get_bandwidth = fc0013_get_bandwidth,
601
602 .get_rf_strength = fc0013_get_rf_strength,
531}; 603};
532 604
533struct dvb_frontend *fc0013_attach(struct dvb_frontend *fe, 605struct dvb_frontend *fc0013_attach(struct dvb_frontend *fe,
@@ -559,4 +631,4 @@ EXPORT_SYMBOL(fc0013_attach);
559MODULE_DESCRIPTION("Fitipower FC0013 silicon tuner driver"); 631MODULE_DESCRIPTION("Fitipower FC0013 silicon tuner driver");
560MODULE_AUTHOR("Hans-Frieder Vogt <hfvogt@gmx.net>"); 632MODULE_AUTHOR("Hans-Frieder Vogt <hfvogt@gmx.net>");
561MODULE_LICENSE("GPL"); 633MODULE_LICENSE("GPL");
562MODULE_VERSION("0.1"); 634MODULE_VERSION("0.2");