diff options
author | Daniel Scheller <d.scheller@gmx.net> | 2017-06-25 08:26:44 -0300 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@s-opensource.com> | 2017-06-25 09:06:32 -0300 |
commit | d394ad12c2e0354a18e34ad803f685b795b01fc4 (patch) | |
tree | b78dcb6bbce6edb81501558aafc2e6929d19e8fd /drivers | |
parent | 8982735f8dd02096b75255e3c0a0df28aeaa9955 (diff) |
media: dvb-frontends/stv0367: SNR DVBv5 statistics for DVB-C and T
Add signal-to-noise-ratio as provided by the demodulator in decibel scale.
QAM/DVB-C needs some intlog calculation to have usable dB values, OFDM/
DVB-T values from the demod look alright already and are provided as-is.
Signed-off-by: Daniel Scheller <d.scheller@gmx.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/media/dvb-frontends/stv0367.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/drivers/media/dvb-frontends/stv0367.c b/drivers/media/dvb-frontends/stv0367.c index f266c18c574c..fee2a1554203 100644 --- a/drivers/media/dvb-frontends/stv0367.c +++ b/drivers/media/dvb-frontends/stv0367.c @@ -25,6 +25,8 @@ #include <linux/slab.h> #include <linux/i2c.h> +#include "dvb_math.h" + #include "stv0367.h" #include "stv0367_defs.h" #include "stv0367_regs.h" @@ -2996,6 +2998,37 @@ static int stv0367ddb_set_frontend(struct dvb_frontend *fe) return -EINVAL; } +static void stv0367ddb_read_snr(struct dvb_frontend *fe) +{ + struct stv0367_state *state = fe->demodulator_priv; + struct dtv_frontend_properties *p = &fe->dtv_property_cache; + int cab_pwr; + u32 regval, tmpval, snrval = 0; + + switch (state->activedemod) { + case demod_ter: + snrval = stv0367ter_snr_readreg(fe); + break; + case demod_cab: + cab_pwr = stv0367cab_snr_power(fe); + regval = stv0367cab_snr_readreg(fe, 0); + + /* prevent division by zero */ + if (!regval) + snrval = 0; + + tmpval = (cab_pwr * 320) / regval; + snrval = ((tmpval != 0) ? (intlog2(tmpval) / 5581) : 0); + break; + default: + p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; + return; + } + + p->cnr.stat[0].scale = FE_SCALE_DECIBEL; + p->cnr.stat[0].uvalue = snrval; +} + static void stv0367ddb_read_ucblocks(struct dvb_frontend *fe) { struct stv0367_state *state = fe->demodulator_priv; @@ -3040,6 +3073,12 @@ static int stv0367ddb_read_status(struct dvb_frontend *fe, if (ret) return ret; + /* read carrier/noise when a carrier is detected */ + if (*status & FE_HAS_CARRIER) + stv0367ddb_read_snr(fe); + else + p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; + /* stop if demod isn't locked */ if (!(*status & FE_HAS_LOCK)) { p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |