aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb
diff options
context:
space:
mode:
authorAntti Palosaari <crope@iki.fi>2012-05-15 17:32:33 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-05-20 09:23:18 -0400
commiteba672a045d8fbf62b229eac74ef444b6000c4c2 (patch)
tree2247309bf56ecc8b51b07c0c08c8ca61fc2f9e56 /drivers/media/dvb
parentf6f379df6516d6fab27367706fcaafa88df41178 (diff)
[media] rtl2830: implement .read_snr()
Reports value as a 0.1 dB. Signed-off-by: Antti Palosaari <crope@iki.fi> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/dvb')
-rw-r--r--drivers/media/dvb/frontends/rtl2830.c42
-rw-r--r--drivers/media/dvb/frontends/rtl2830_priv.h1
2 files changed, 42 insertions, 1 deletions
diff --git a/drivers/media/dvb/frontends/rtl2830.c b/drivers/media/dvb/frontends/rtl2830.c
index 45196c5b0736..e6d7c501717a 100644
--- a/drivers/media/dvb/frontends/rtl2830.c
+++ b/drivers/media/dvb/frontends/rtl2830.c
@@ -404,8 +404,48 @@ err:
404 404
405static int rtl2830_read_snr(struct dvb_frontend *fe, u16 *snr) 405static int rtl2830_read_snr(struct dvb_frontend *fe, u16 *snr)
406{ 406{
407 *snr = 0; 407 struct rtl2830_priv *priv = fe->demodulator_priv;
408 int ret, hierarchy, constellation;
409 u8 buf[2], tmp;
410 u16 tmp16;
411#define CONSTELLATION_NUM 3
412#define HIERARCHY_NUM 4
413 static const u32 snr_constant[CONSTELLATION_NUM][HIERARCHY_NUM] = {
414 { 70705899, 70705899, 70705899, 70705899 },
415 { 82433173, 82433173, 87483115, 94445660 },
416 { 92888734, 92888734, 95487525, 99770748 },
417 };
418
419 /* reports SNR in resolution of 0.1 dB */
420
421 ret = rtl2830_rd_reg(priv, 0x33c, &tmp);
422 if (ret)
423 goto err;
424
425 constellation = (tmp >> 2) & 0x03; /* [3:2] */
426 if (constellation > CONSTELLATION_NUM - 1)
427 goto err;
428
429 hierarchy = (tmp >> 4) & 0x07; /* [6:4] */
430 if (hierarchy > HIERARCHY_NUM - 1)
431 goto err;
432
433 ret = rtl2830_rd_regs(priv, 0x40c, buf, 2);
434 if (ret)
435 goto err;
436
437 tmp16 = buf[0] << 8 | buf[1];
438
439 if (tmp16)
440 *snr = (snr_constant[constellation][hierarchy] -
441 intlog10(tmp16)) / ((1 << 24) / 100);
442 else
443 *snr = 0;
444
408 return 0; 445 return 0;
446err:
447 dbg("%s: failed=%d", __func__, ret);
448 return ret;
409} 449}
410 450
411static int rtl2830_read_ber(struct dvb_frontend *fe, u32 *ber) 451static int rtl2830_read_ber(struct dvb_frontend *fe, u32 *ber)
diff --git a/drivers/media/dvb/frontends/rtl2830_priv.h b/drivers/media/dvb/frontends/rtl2830_priv.h
index 4a464761b5b8..9b20557ccf6c 100644
--- a/drivers/media/dvb/frontends/rtl2830_priv.h
+++ b/drivers/media/dvb/frontends/rtl2830_priv.h
@@ -22,6 +22,7 @@
22#define RTL2830_PRIV_H 22#define RTL2830_PRIV_H
23 23
24#include "dvb_frontend.h" 24#include "dvb_frontend.h"
25#include "dvb_math.h"
25#include "rtl2830.h" 26#include "rtl2830.h"
26 27
27#define LOG_PREFIX "rtl2830" 28#define LOG_PREFIX "rtl2830"