diff options
author | Hans-Frieder Vogt <hfvogt@gmx.net> | 2012-05-12 05:11:47 -0300 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2012-05-20 10:22:17 -0300 |
commit | b144c98ca0962ee3cbdbbeafe77a1b300be0cb4f (patch) | |
tree | 915f6a0c9904275ad0028afb6336d3fd35702c90 /drivers/media | |
parent | 4a14db7e61a1aa3ef379eb63ff2c5943218bb8cc (diff) | |
download | linux-3.10-b144c98ca0962ee3cbdbbeafe77a1b300be0cb4f.tar.gz linux-3.10-b144c98ca0962ee3cbdbbeafe77a1b300be0cb4f.tar.bz2 linux-3.10-b144c98ca0962ee3cbdbbeafe77a1b300be0cb4f.zip |
[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.c | 74 |
1 files changed, 73 insertions, 1 deletions
diff --git a/drivers/media/common/tuners/fc0013.c b/drivers/media/common/tuners/fc0013.c index 7398d7759e0..bd8f0f1e8f3 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) exit: if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */ + if (ret) + warn("%s: failed: %d", __func__, ret); return ret; } @@ -508,6 +510,74 @@ static int fc0013_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth) return 0; } +#define INPUT_ADC_LEVEL -8 + +static int fc0013_get_rf_strength(struct dvb_frontend *fe, u16 *strength) +{ + struct fc0013_priv *priv = fe->tuner_priv; + int ret; + unsigned char tmp; + int int_temp, lna_gain, int_lna, tot_agc_gain, power; + const int fc0013_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 = fc0013_writereg(priv, 0x13, 0x00); + if (ret) + goto err; + + ret = fc0013_readreg(priv, 0x13, &tmp); + if (ret) + goto err; + int_temp = tmp; + + ret = fc0013_readreg(priv, 0x14, &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(fc0013_lna_gain_table)) { + int_lna = fc0013_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 fc0013_tuner_ops = { .info = { @@ -528,6 +598,8 @@ static const struct dvb_tuner_ops fc0013_tuner_ops = { .get_frequency = fc0013_get_frequency, .get_if_frequency = fc0013_get_if_frequency, .get_bandwidth = fc0013_get_bandwidth, + + .get_rf_strength = fc0013_get_rf_strength, }; struct dvb_frontend *fc0013_attach(struct dvb_frontend *fe, @@ -559,4 +631,4 @@ EXPORT_SYMBOL(fc0013_attach); MODULE_DESCRIPTION("Fitipower FC0013 silicon tuner driver"); MODULE_AUTHOR("Hans-Frieder Vogt <hfvogt@gmx.net>"); MODULE_LICENSE("GPL"); -MODULE_VERSION("0.1"); +MODULE_VERSION("0.2"); |