aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorHans-Frieder Vogt <hfvogt@gmx.net>2012-05-12 04:11:36 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-05-20 09:22:08 -0400
commit4a14db7e61a1aa3ef379eb63ff2c5943218bb8cc (patch)
tree105d3a5b8d1b7a9957d6f6dbccb21df87e55870b /drivers
parente889adc91187de94c0fdfe1c3cb23f6e4da88c2b (diff)
[media] fc0012 ver. 0.6: introduction of get_rf_strength function
Changes compared to version 0.5 of driver (sent 6 May): - Initial implementation of get_rf_strength function. 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')
-rw-r--r--drivers/media/common/tuners/fc0012.c72
1 files changed, 71 insertions, 1 deletions
diff --git a/drivers/media/common/tuners/fc0012.c b/drivers/media/common/tuners/fc0012.c
index cd58f90d7d13..308135abd54c 100644
--- a/drivers/media/common/tuners/fc0012.c
+++ b/drivers/media/common/tuners/fc0012.c
@@ -343,6 +343,74 @@ static int fc0012_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
343 return 0; 343 return 0;
344} 344}
345 345
346#define INPUT_ADC_LEVEL -8
347
348static int fc0012_get_rf_strength(struct dvb_frontend *fe, u16 *strength)
349{
350 struct fc0012_priv *priv = fe->tuner_priv;
351 int ret;
352 unsigned char tmp;
353 int int_temp, lna_gain, int_lna, tot_agc_gain, power;
354 const int fc0012_lna_gain_table[] = {
355 /* low gain */
356 -63, -58, -99, -73,
357 -63, -65, -54, -60,
358 /* middle gain */
359 71, 70, 68, 67,
360 65, 63, 61, 58,
361 /* high gain */
362 197, 191, 188, 186,
363 184, 182, 181, 179,
364 };
365
366 if (fe->ops.i2c_gate_ctrl)
367 fe->ops.i2c_gate_ctrl(fe, 1); /* open I2C-gate */
368
369 ret = fc0012_writereg(priv, 0x12, 0x00);
370 if (ret)
371 goto err;
372
373 ret = fc0012_readreg(priv, 0x12, &tmp);
374 if (ret)
375 goto err;
376 int_temp = tmp;
377
378 ret = fc0012_readreg(priv, 0x13, &tmp);
379 if (ret)
380 goto err;
381 lna_gain = tmp & 0x1f;
382
383 if (fe->ops.i2c_gate_ctrl)
384 fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */
385
386 if (lna_gain < ARRAY_SIZE(fc0012_lna_gain_table)) {
387 int_lna = fc0012_lna_gain_table[lna_gain];
388 tot_agc_gain = (abs((int_temp >> 5) - 7) - 2 +
389 (int_temp & 0x1f)) * 2;
390 power = INPUT_ADC_LEVEL - tot_agc_gain - int_lna / 10;
391
392 if (power >= 45)
393 *strength = 255; /* 100% */
394 else if (power < -95)
395 *strength = 0;
396 else
397 *strength = (power + 95) * 255 / 140;
398
399 *strength |= *strength << 8;
400 } else {
401 ret = -1;
402 }
403
404 goto exit;
405
406err:
407 if (fe->ops.i2c_gate_ctrl)
408 fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */
409exit:
410 if (ret)
411 warn("%s: failed: %d", __func__, ret);
412 return ret;
413}
346 414
347static const struct dvb_tuner_ops fc0012_tuner_ops = { 415static const struct dvb_tuner_ops fc0012_tuner_ops = {
348 .info = { 416 .info = {
@@ -363,6 +431,8 @@ static const struct dvb_tuner_ops fc0012_tuner_ops = {
363 .get_frequency = fc0012_get_frequency, 431 .get_frequency = fc0012_get_frequency,
364 .get_if_frequency = fc0012_get_if_frequency, 432 .get_if_frequency = fc0012_get_if_frequency,
365 .get_bandwidth = fc0012_get_bandwidth, 433 .get_bandwidth = fc0012_get_bandwidth,
434
435 .get_rf_strength = fc0012_get_rf_strength,
366}; 436};
367 437
368struct dvb_frontend *fc0012_attach(struct dvb_frontend *fe, 438struct dvb_frontend *fc0012_attach(struct dvb_frontend *fe,
@@ -394,4 +464,4 @@ EXPORT_SYMBOL(fc0012_attach);
394MODULE_DESCRIPTION("Fitipower FC0012 silicon tuner driver"); 464MODULE_DESCRIPTION("Fitipower FC0012 silicon tuner driver");
395MODULE_AUTHOR("Hans-Frieder Vogt <hfvogt@gmx.net>"); 465MODULE_AUTHOR("Hans-Frieder Vogt <hfvogt@gmx.net>");
396MODULE_LICENSE("GPL"); 466MODULE_LICENSE("GPL");
397MODULE_VERSION("0.5"); 467MODULE_VERSION("0.6");