Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 306524
b: refs/heads/master
c: 4a14db7
h: refs/heads/master
v: v3
  • Loading branch information
Hans-Frieder Vogt authored and Mauro Carvalho Chehab committed May 20, 2012
1 parent 82ebcae commit d0b2a0a
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: e889adc91187de94c0fdfe1c3cb23f6e4da88c2b
refs/heads/master: 4a14db7e61a1aa3ef379eb63ff2c5943218bb8cc
72 changes: 71 additions & 1 deletion trunk/drivers/media/common/tuners/fc0012.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,74 @@ static int fc0012_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
return 0;
}

#define INPUT_ADC_LEVEL -8

static int fc0012_get_rf_strength(struct dvb_frontend *fe, u16 *strength)
{
struct fc0012_priv *priv = fe->tuner_priv;
int ret;
unsigned char tmp;
int int_temp, lna_gain, int_lna, tot_agc_gain, power;
const int fc0012_lna_gain_table[] = {
/* low gain */
-63, -58, -99, -73,
-63, -65, -54, -60,
/* middle gain */
71, 70, 68, 67,
65, 63, 61, 58,
/* high gain */
197, 191, 188, 186,
184, 182, 181, 179,
};

if (fe->ops.i2c_gate_ctrl)
fe->ops.i2c_gate_ctrl(fe, 1); /* open I2C-gate */

ret = fc0012_writereg(priv, 0x12, 0x00);
if (ret)
goto err;

ret = fc0012_readreg(priv, 0x12, &tmp);
if (ret)
goto err;
int_temp = tmp;

ret = fc0012_readreg(priv, 0x13, &tmp);
if (ret)
goto err;
lna_gain = tmp & 0x1f;

if (fe->ops.i2c_gate_ctrl)
fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */

if (lna_gain < ARRAY_SIZE(fc0012_lna_gain_table)) {
int_lna = fc0012_lna_gain_table[lna_gain];
tot_agc_gain = (abs((int_temp >> 5) - 7) - 2 +
(int_temp & 0x1f)) * 2;
power = INPUT_ADC_LEVEL - tot_agc_gain - int_lna / 10;

if (power >= 45)
*strength = 255; /* 100% */
else if (power < -95)
*strength = 0;
else
*strength = (power + 95) * 255 / 140;

*strength |= *strength << 8;
} else {
ret = -1;
}

goto exit;

err:
if (fe->ops.i2c_gate_ctrl)
fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */
exit:
if (ret)
warn("%s: failed: %d", __func__, ret);
return ret;
}

static const struct dvb_tuner_ops fc0012_tuner_ops = {
.info = {
Expand All @@ -363,6 +431,8 @@ static const struct dvb_tuner_ops fc0012_tuner_ops = {
.get_frequency = fc0012_get_frequency,
.get_if_frequency = fc0012_get_if_frequency,
.get_bandwidth = fc0012_get_bandwidth,

.get_rf_strength = fc0012_get_rf_strength,
};

struct dvb_frontend *fc0012_attach(struct dvb_frontend *fe,
Expand Down Expand Up @@ -394,4 +464,4 @@ EXPORT_SYMBOL(fc0012_attach);
MODULE_DESCRIPTION("Fitipower FC0012 silicon tuner driver");
MODULE_AUTHOR("Hans-Frieder Vogt <hfvogt@gmx.net>");
MODULE_LICENSE("GPL");
MODULE_VERSION("0.5");
MODULE_VERSION("0.6");

0 comments on commit d0b2a0a

Please sign in to comment.