From 971e541a4924db380c290cb784f30f9d141ff1d4 Mon Sep 17 00:00:00 2001 From: Antti Palosaari Date: Tue, 21 Aug 2012 19:56:21 -0300 Subject: [PATCH] --- yaml --- r: 330983 b: refs/heads/master c: 73983497ff816109e2739ad23ace06fd42c552e9 h: refs/heads/master i: 330981: 7fa83344d7535409d10f1e1032c044ac6b1c3114 330979: 953a1704a47630e654134d1d72b697842c309311 330975: 5820be86e5057ce5c5bf633ed0539ee167165baa v: v3 --- [refs] | 2 +- trunk/drivers/media/dvb-frontends/rtl2832.c | 52 +++++++++++++++++++-- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/[refs] b/[refs] index c4c2dec79162..5a36b4e820c9 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 0ce67a2a59b26dd1b087115141c71ddd89514b77 +refs/heads/master: 73983497ff816109e2739ad23ace06fd42c552e9 diff --git a/trunk/drivers/media/dvb-frontends/rtl2832.c b/trunk/drivers/media/dvb-frontends/rtl2832.c index 6e28444d6526..dad8ab5aba8e 100644 --- a/trunk/drivers/media/dvb-frontends/rtl2832.c +++ b/trunk/drivers/media/dvb-frontends/rtl2832.c @@ -19,6 +19,7 @@ */ #include "rtl2832_priv.h" +#include "dvb_math.h" #include int rtl2832_debug; @@ -355,7 +356,6 @@ int rtl2832_wr_demod_reg(struct rtl2832_priv *priv, int reg, u32 val) } - static int rtl2832_i2c_gate_ctrl(struct dvb_frontend *fe, int enable) { int ret; @@ -379,8 +379,6 @@ static int rtl2832_i2c_gate_ctrl(struct dvb_frontend *fe, int enable) return ret; } - - static int rtl2832_init(struct dvb_frontend *fe) { struct rtl2832_priv *priv = fe->demodulator_priv; @@ -780,6 +778,52 @@ static int rtl2832_read_status(struct dvb_frontend *fe, fe_status_t *status) return ret; } +static int rtl2832_read_snr(struct dvb_frontend *fe, u16 *snr) +{ + struct rtl2832_priv *priv = fe->demodulator_priv; + int ret, hierarchy, constellation; + u8 buf[2], tmp; + u16 tmp16; +#define CONSTELLATION_NUM 3 +#define HIERARCHY_NUM 4 + static const u32 snr_constant[CONSTELLATION_NUM][HIERARCHY_NUM] = { + { 85387325, 85387325, 85387325, 85387325 }, + { 86676178, 86676178, 87167949, 87795660 }, + { 87659938, 87659938, 87885178, 88241743 }, + }; + + /* reports SNR in resolution of 0.1 dB */ + + ret = rtl2832_rd_reg(priv, 0x3c, 3, &tmp); + if (ret) + goto err; + + constellation = (tmp >> 2) & 0x03; /* [3:2] */ + if (constellation > CONSTELLATION_NUM - 1) + goto err; + + hierarchy = (tmp >> 4) & 0x07; /* [6:4] */ + if (hierarchy > HIERARCHY_NUM - 1) + goto err; + + ret = rtl2832_rd_regs(priv, 0x0c, 4, buf, 2); + if (ret) + goto err; + + tmp16 = buf[0] << 8 | buf[1]; + + if (tmp16) + *snr = (snr_constant[constellation][hierarchy] - + intlog10(tmp16)) / ((1 << 24) / 100); + else + *snr = 0; + + return 0; +err: + dbg("%s: failed=%d", __func__, ret); + return ret; +} + static struct dvb_frontend_ops rtl2832_ops; static void rtl2832_release(struct dvb_frontend *fe) @@ -864,6 +908,8 @@ static struct dvb_frontend_ops rtl2832_ops = { .get_frontend = rtl2832_get_frontend, .read_status = rtl2832_read_status, + .read_snr = rtl2832_read_snr, + .i2c_gate_ctrl = rtl2832_i2c_gate_ctrl, };