From patchwork Sat May 12 09:11:47 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans-Frieder Vogt X-Patchwork-Id: 11192 Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.72) (envelope-from ) id 1ST8NC-0005M4-UC for patchwork@linuxtv.org; Sat, 12 May 2012 11:12:22 +0200 X-tubIT-Incoming-IP: 209.132.180.67 Received: from vger.kernel.org ([209.132.180.67]) by mail.tu-berlin.de (exim-4.75/mailfrontend-4) with esmtp for id 1ST8NC-0007dc-AV; Sat, 12 May 2012 11:12:22 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753649Ab2ELJMT (ORCPT ); Sat, 12 May 2012 05:12:19 -0400 Received: from mailout-de.gmx.net ([213.165.64.23]:36412 "HELO mailout-de.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1752203Ab2ELJLv (ORCPT ); Sat, 12 May 2012 05:11:51 -0400 Received: (qmail invoked by alias); 12 May 2012 09:11:49 -0000 Received: from p4FC08C81.dip0.t-ipconnect.de (EHLO maximilian.localnet) [79.192.140.129] by mail.gmx.net (mp031) with SMTP; 12 May 2012 11:11:49 +0200 X-Authenticated: #24390674 X-Provags-ID: V01U2FsdGVkX18CytMn+MwCkoENr+Ist67c1824RY4w7ti4F2/zCb j2yq9AWRd6fjqI From: "Hans-Frieder Vogt" To: linux-media@vger.kernel.org, Thomas Mair , Antti Palosaari Subject: [PATCH] fc0013 ver. 0.2: introduction of get_rf_strength function Date: Sat, 12 May 2012 11:11:47 +0200 User-Agent: KMail/1.13.7 (Linux/3.3.4-a64; KDE/4.7.4; x86_64; ; ) MIME-Version: 1.0 Message-Id: <201205121111.47754.hfvogt@gmx.net> X-Y-GMX-Trusted: 0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-PMX-Version: 5.6.1.2065439, Antispam-Engine: 2.7.2.376379, Antispam-Data: 2012.5.12.90317 X-PMX-Spam: Gauge=IIIIIIII, Probability=8%, Report=' HTML_00_01 0.05, HTML_00_10 0.05, BODY_SIZE_3000_3999 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, URI_ENDS_IN_HTML 0, __ANY_URI 0, __CP_URI_IN_BODY 0, __CT 0, __CTE 0, __CT_TEXT_PLAIN 0, __HAS_MSGID 0, __HAS_X_MAILING_LIST 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __SANE_MSGID 0, __STOCK_PHRASE_7 0, __SUBJ_ALPHA_END 0, __TO_MALFORMED_2 0, __TO_NO_NAME 0, __URI_NO_WWW 0, __URI_NS , __USER_AGENT 0' 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 fc0013.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) Hans-Frieder Vogt e-mail: hfvogt gmx .dot. net --- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff -up --new-file --recursive a/drivers/media/common/tuners/fc0013.c b/drivers/media/common/tuners/fc0013.c --- a/drivers/media/common/tuners/fc0013.c 2012-05-12 10:54:01.093352494 +0200 +++ b/drivers/media/common/tuners/fc0013.c 2012-05-12 11:00:29.940455095 +0200 @@ -484,6 +484,8 @@ static int fc0013_set_params(struct dvb_ 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 d 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 .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 "); MODULE_LICENSE("GPL"); -MODULE_VERSION("0.1"); +MODULE_VERSION("0.2");