You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
136 lines
3.9 KiB
136 lines
3.9 KiB
5 years ago
|
cxd2820r: by default SNR output is scaled to full 0-65535 range;
|
||
|
output in dBx10 can be enabled through a module parameter;
|
||
|
|
||
|
Signed-off-by: Gianluca Gennari <gennarone@gmail.com>
|
||
|
---
|
||
|
drivers/media/dvb-frontends/cxd2820r_core.c | 4 ++++
|
||
|
drivers/media/dvb-frontends/cxd2820r_priv.h | 1 +
|
||
|
drivers/media/dvb-frontends/cxd2820r_t.c | 27 ++++++++++++++++++++++-
|
||
|
drivers/media/dvb-frontends/cxd2820r_t2.c | 31 ++++++++++++++++++++++++++-
|
||
|
4 files changed, 61 insertions(+), 2 deletions(-)
|
||
|
|
||
|
diff --git a/drivers/media/dvb-frontends/cxd2820r_core.c b/drivers/media/dvb-frontends/cxd2820r_core.c
|
||
|
index 9b658c1..35477aa 100644
|
||
|
--- a/drivers/media/dvb-frontends/cxd2820r_core.c
|
||
|
+++ b/drivers/media/dvb-frontends/cxd2820r_core.c
|
||
|
@@ -21,6 +21,10 @@
|
||
|
|
||
|
#include "cxd2820r_priv.h"
|
||
|
|
||
|
+int cxd2820r_snrdb;
|
||
|
+module_param_named(snrdb,cxd2820r_snrdb, int, 0644);
|
||
|
+MODULE_PARM_DESC(snrdb, "Turn on/off SNR output in dBx10 (default:off).");
|
||
|
+
|
||
|
/* write multiple registers */
|
||
|
static int cxd2820r_wr_regs_i2c(struct cxd2820r_priv *priv, u8 i2c, u8 reg,
|
||
|
u8 *val, int len)
|
||
|
diff --git a/drivers/media/dvb-frontends/cxd2820r_priv.h b/drivers/media/dvb-frontends/cxd2820r_priv.h
|
||
|
index 7ff5f60..f742169 100644
|
||
|
--- a/drivers/media/dvb-frontends/cxd2820r_priv.h
|
||
|
+++ b/drivers/media/dvb-frontends/cxd2820r_priv.h
|
||
|
@@ -55,6 +55,7 @@ struct cxd2820r_priv {
|
||
|
/* cxd2820r_core.c */
|
||
|
|
||
|
extern int cxd2820r_debug;
|
||
|
+extern int cxd2820r_snrdb;
|
||
|
|
||
|
int cxd2820r_gpio(struct dvb_frontend *fe, u8 *gpio);
|
||
|
|
||
|
diff --git a/drivers/media/dvb-frontends/cxd2820r_t.c b/drivers/media/dvb-frontends/cxd2820r_t.c
|
||
|
index fa184ca..4268c53 100644
|
||
|
--- a/drivers/media/dvb-frontends/cxd2820r_t.c
|
||
|
+++ b/drivers/media/dvb-frontends/cxd2820r_t.c
|
||
|
@@ -317,7 +317,7 @@ int cxd2820r_read_snr_t(struct dvb_frontend *fe, u16 *snr)
|
||
|
struct cxd2820r_priv *priv = fe->demodulator_priv;
|
||
|
int ret;
|
||
|
u8 buf[2];
|
||
|
- u16 tmp;
|
||
|
+ u16 tmp, max_snr;
|
||
|
/* report SNR in dB * 10 */
|
||
|
|
||
|
ret = cxd2820r_rd_regs(priv, 0x00028, buf, sizeof(buf));
|
||
|
@@ -332,6 +332,31 @@ int cxd2820r_read_snr_t(struct dvb_frontend *fe, u16 *snr)
|
||
|
else
|
||
|
*snr = 0;
|
||
|
|
||
|
+ if (cxd2820r_snrdb)
|
||
|
+ goto db_out;
|
||
|
+
|
||
|
+ /* scale SNR to full range */
|
||
|
+ ret = cxd2820r_rd_regs(priv, 0x0002f, buf, 1);
|
||
|
+ if (ret)
|
||
|
+ goto error;
|
||
|
+
|
||
|
+ switch ((buf[0] >> 6) & 0x03) {
|
||
|
+ case 0: /* QPSK */
|
||
|
+ max_snr = 230;
|
||
|
+ break;
|
||
|
+ case 1: /* QAM_16 */
|
||
|
+ max_snr = 260;
|
||
|
+ break;
|
||
|
+ case 2: /* QAM_64 */
|
||
|
+ default:
|
||
|
+ max_snr = 290;
|
||
|
+ break;
|
||
|
+ }
|
||
|
+
|
||
|
+ *snr = (*snr >= max_snr) ? 0xffff : (0xffff / max_snr) * *snr;
|
||
|
+ dev_dbg(&priv->i2c->dev, "%s: SNR=%d val=%04x", __func__, *snr, tmp);
|
||
|
+ return ret;
|
||
|
+db_out:
|
||
|
dev_dbg(&priv->i2c->dev, "%s: dBx10=%d val=%04x\n", __func__, *snr,
|
||
|
tmp);
|
||
|
|
||
|
diff --git a/drivers/media/dvb-frontends/cxd2820r_t2.c b/drivers/media/dvb-frontends/cxd2820r_t2.c
|
||
|
index e82d82a..69945cc 100644
|
||
|
--- a/drivers/media/dvb-frontends/cxd2820r_t2.c
|
||
|
+++ b/drivers/media/dvb-frontends/cxd2820r_t2.c
|
||
|
@@ -351,7 +351,7 @@ int cxd2820r_read_snr_t2(struct dvb_frontend *fe, u16 *snr)
|
||
|
struct cxd2820r_priv *priv = fe->demodulator_priv;
|
||
|
int ret;
|
||
|
u8 buf[2];
|
||
|
- u16 tmp;
|
||
|
+ u16 tmp, max_snr;
|
||
|
/* report SNR in dB * 10 */
|
||
|
|
||
|
ret = cxd2820r_rd_regs(priv, 0x02028, buf, sizeof(buf));
|
||
|
@@ -366,6 +366,35 @@ int cxd2820r_read_snr_t2(struct dvb_frontend *fe, u16 *snr)
|
||
|
else
|
||
|
*snr = 0;
|
||
|
|
||
|
+ if (cxd2820r_snrdb)
|
||
|
+ goto db_out;
|
||
|
+
|
||
|
+ /* scale SNR to full range */
|
||
|
+ ret = cxd2820r_rd_regs(priv, 0x0205d, buf, 1);
|
||
|
+ if (ret)
|
||
|
+ goto error;
|
||
|
+
|
||
|
+ switch (buf[0] & 0x07) {
|
||
|
+ /* FIXME: check the values */
|
||
|
+ case 0: /* QPSK */
|
||
|
+ max_snr = 170;
|
||
|
+ break;
|
||
|
+ case 1: /* QAM_16 */
|
||
|
+ max_snr = 200;
|
||
|
+ break;
|
||
|
+ case 2: /* QAM_64 */
|
||
|
+ max_snr = 230;
|
||
|
+ break;
|
||
|
+ case 3: /* QAM_256 */
|
||
|
+ default:
|
||
|
+ max_snr = 260;
|
||
|
+ break;
|
||
|
+ }
|
||
|
+
|
||
|
+ *snr = (*snr >= max_snr) ? 0xffff : (0xffff / max_snr) * *snr;
|
||
|
+ dev_dbg(&priv->i2c->dev, "%s: SNR=%d val=%04x", __func__, *snr, tmp);
|
||
|
+ return ret;
|
||
|
+db_out:
|
||
|
dev_dbg(&priv->i2c->dev, "%s: dBx10=%d val=%04x\n", __func__, *snr,
|
||
|
tmp);
|
||
|
|
||
|
--
|
||
|
1.7.9.5
|
||
|
|