aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb-frontends/rtl2832.c
diff options
context:
space:
mode:
authorAntti Palosaari <crope@iki.fi>2012-08-21 18:56:21 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-09-15 08:30:29 -0400
commit73983497ff816109e2739ad23ace06fd42c552e9 (patch)
treeb58240a43f7add5df33167272efb7bf6ee83b9b4 /drivers/media/dvb-frontends/rtl2832.c
parent0ce67a2a59b26dd1b087115141c71ddd89514b77 (diff)
[media] rtl2832: implement .read_snr()
Based rtl2830 implementation. Cc: Thomas Mair <thomas.mair86@googlemail.com> Signed-off-by: Antti Palosaari <crope@iki.fi> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/dvb-frontends/rtl2832.c')
-rw-r--r--drivers/media/dvb-frontends/rtl2832.c52
1 files changed, 49 insertions, 3 deletions
diff --git a/drivers/media/dvb-frontends/rtl2832.c b/drivers/media/dvb-frontends/rtl2832.c
index 6e28444d6526..dad8ab5aba8e 100644
--- a/drivers/media/dvb-frontends/rtl2832.c
+++ b/drivers/media/dvb-frontends/rtl2832.c
@@ -19,6 +19,7 @@
19 */ 19 */
20 20
21#include "rtl2832_priv.h" 21#include "rtl2832_priv.h"
22#include "dvb_math.h"
22#include <linux/bitops.h> 23#include <linux/bitops.h>
23 24
24int rtl2832_debug; 25int rtl2832_debug;
@@ -355,7 +356,6 @@ err:
355 356
356} 357}
357 358
358
359static int rtl2832_i2c_gate_ctrl(struct dvb_frontend *fe, int enable) 359static int rtl2832_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
360{ 360{
361 int ret; 361 int ret;
@@ -379,8 +379,6 @@ err:
379 return ret; 379 return ret;
380} 380}
381 381
382
383
384static int rtl2832_init(struct dvb_frontend *fe) 382static int rtl2832_init(struct dvb_frontend *fe)
385{ 383{
386 struct rtl2832_priv *priv = fe->demodulator_priv; 384 struct rtl2832_priv *priv = fe->demodulator_priv;
@@ -780,6 +778,52 @@ err:
780 return ret; 778 return ret;
781} 779}
782 780
781static int rtl2832_read_snr(struct dvb_frontend *fe, u16 *snr)
782{
783 struct rtl2832_priv *priv = fe->demodulator_priv;
784 int ret, hierarchy, constellation;
785 u8 buf[2], tmp;
786 u16 tmp16;
787#define CONSTELLATION_NUM 3
788#define HIERARCHY_NUM 4
789 static const u32 snr_constant[CONSTELLATION_NUM][HIERARCHY_NUM] = {
790 { 85387325, 85387325, 85387325, 85387325 },
791 { 86676178, 86676178, 87167949, 87795660 },
792 { 87659938, 87659938, 87885178, 88241743 },
793 };
794
795 /* reports SNR in resolution of 0.1 dB */
796
797 ret = rtl2832_rd_reg(priv, 0x3c, 3, &tmp);
798 if (ret)
799 goto err;
800
801 constellation = (tmp >> 2) & 0x03; /* [3:2] */
802 if (constellation > CONSTELLATION_NUM - 1)
803 goto err;
804
805 hierarchy = (tmp >> 4) & 0x07; /* [6:4] */
806 if (hierarchy > HIERARCHY_NUM - 1)
807 goto err;
808
809 ret = rtl2832_rd_regs(priv, 0x0c, 4, buf, 2);
810 if (ret)
811 goto err;
812
813 tmp16 = buf[0] << 8 | buf[1];
814
815 if (tmp16)
816 *snr = (snr_constant[constellation][hierarchy] -
817 intlog10(tmp16)) / ((1 << 24) / 100);
818 else
819 *snr = 0;
820
821 return 0;
822err:
823 dbg("%s: failed=%d", __func__, ret);
824 return ret;
825}
826
783static struct dvb_frontend_ops rtl2832_ops; 827static struct dvb_frontend_ops rtl2832_ops;
784 828
785static void rtl2832_release(struct dvb_frontend *fe) 829static void rtl2832_release(struct dvb_frontend *fe)
@@ -864,6 +908,8 @@ static struct dvb_frontend_ops rtl2832_ops = {
864 .get_frontend = rtl2832_get_frontend, 908 .get_frontend = rtl2832_get_frontend,
865 909
866 .read_status = rtl2832_read_status, 910 .read_status = rtl2832_read_status,
911 .read_snr = rtl2832_read_snr,
912
867 .i2c_gate_ctrl = rtl2832_i2c_gate_ctrl, 913 .i2c_gate_ctrl = rtl2832_i2c_gate_ctrl,
868}; 914};
869 915