STV0367/DDB DVBv5 signal statistics
v3 cover STV0367/DDB DVBv5 signal statistics
From: Daniel Scheller <[email protected]>
This series adds DVBv5 statistics support to the new DDB codepath of the stv0367 demodulator driver.
The changes utilise already existing functionality (in form of register readouts), but wraps the reads in separate functions so the existing relative scale reporting can be kept as-is, while adding the v5 stats in dB scale where appropriate.
The {ter,cab}_read_status() additionally have been enhanced to provide a more detailed status from the values the logic already provides (at least for DVB-C, DVB-T isn't as detailed, so all flags are set upon lock instead).
Quoted 1 line
From my own testing: Reported values look approx. the same as those
reported by the cxd2841er driver for both -C and -T.
Testing for v3: The enhanced status works good for DVB-C - signal almost instantly goes to FE_HAS_LOCK with good signal strength with the cabling plugged in. When antenna is pulled, fe_status goes away, cnr goes to unavailable and signal strength to the lowest the driver can provide. Statistics come back after cable is plugged back in. Re DVB-T, unfortunately I cannot do anymore testing with this, since over here in germany DVB-T was replaced by DVB-T2, which the demod cannot handle. Since it worked before and the logic didn't really change, I strongly assume things are still good.
Mauro, re your patch (thanks again!), I slightly changed the commit title and description but kept you as the author, added t-b and signoff. Also, thank you for writing up the DVBv5 statistics document/howto, which was very helpful in fixing this!
Hope everything's good to go now :-)
Changes from v2 to v3:
- ucblocks reporting and register read out splitting are already merged, thus not part of the series anymore
- enhanced {ter,cab}_read_status(), thank you Mauro for pointing this out and providing the (untested) patch!
- always read signal strength, read cnr on FE_HAS_CARRIER, and ucblocks on FE_HAS_LOCK
- adjust if-status-logic for ucblock to match the rest
Changes from v1 to v2:
- INTLOG10X100() macro for QAM SNR calculation removed and replaced by directly utilising intlog2 plus a div
- factored statistics collection into *_read_status()
- prevent a possible division by zero (though requires ridiculously good SNR to trigger)
- _read_status() doesn't return -EINVAL anymore if no demod state is set, prevents falsely reported errors from inquiries of userspace tools
Daniel Scheller (3):
[media] dvb-frontends/stv0367: SNR DVBv5 statistics for DVB-C and T [media] dvb-frontends/stv0367: DVB-C signal strength statistics [media] dvb-frontends/stv0367: make UCB readout logic more clear
Mauro Carvalho Chehab (1):
[media] dvb-frontends/stv0367: Improve DVB-C/T frontend status
drivers/media/dvb-frontends/stv0367.c | 85 ++++++++++++++++++++++++++++++++--- 1 file changed, 78 insertions(+), 7 deletions(-)
Signature · 1 line
2.13.0
PATCH v3 1/4 dvb-frontends/stv0367: Improve DVB-C/T frontend status
From: Mauro Carvalho Chehab <[email protected]>
The stv0367 driver provide a lot of status on its state machine. Change the logic to provide more information about frontend locking status. Also, while any detailed status isn't available, provide a more complete FE_STATUS for DVB-T.
--- drivers/media/dvb-frontends/stv0367.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/media/dvb-frontends/stv0367.c +14 -1
@@ -1507,7 +1507,8 @@ static int stv0367ter_read_status(struct dvb_frontend *fe, *status =0 ;if (stv0367_readbits (state,F367TER_LK )) { - *status |=FE_HAS_LOCK ; + *status =FE_HAS_SIGNAL |FE_HAS_CARRIER |FE_HAS_VITERBI + |FE_HAS_SYNC |FE_HAS_LOCK ;dprintk ("%s: stv0367 has locked\n" , __func__); }
@@ -2155,6 +2156,18 @@ static int stv0367cab_read_status(struct dvb_frontend *fe, *status =0 ; +if (state->cab_state->state >FE_CAB_NOSIGNAL ) + *status |=FE_HAS_SIGNAL ; + +if (state->cab_state->state >FE_CAB_NOCARRIER ) + *status |=FE_HAS_CARRIER ; + +if (state->cab_state->state >=FE_CAB_DEMODOK ) + *status |=FE_HAS_VITERBI ; + +if (state->cab_state->state >=FE_CAB_DATAOK ) + *status |=FE_HAS_SYNC ; +if (stv0367_readbits (state, (state->cab_state->qamfec_status_reg ? state->cab_state->qamfec_status_reg :F367CAB_QAMFEC_LOCK ))) { *status |=FE_HAS_LOCK ;
Signature · 1 line
2.13.0
PATCH v3 2/4 dvb-frontends/stv0367: SNR DVBv5 statistics for DVB-C and T
In reply to Daniel SchellerFrom: Daniel Scheller <[email protected]>
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.
--- drivers/media/dvb-frontends/stv0367.c | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
drivers/media/dvb-frontends/stv0367.c +39 -0
@@ -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"
@@ -3009,6 +3011,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;
@@ -3053,6 +3086,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 ;
Signature · 1 line
2.13.0
PATCH v3 3/4 dvb-frontends/stv0367: DVB-C signal strength statistics
In reply to Daniel SchellerFrom: Daniel Scheller <[email protected]>
Provide QAM/DVB-C signal strength in decibel scale. Values returned from stv0367cab_get_rf_lvl() are good but need to be multiplied as they're in 1dBm precision.
--- drivers/media/dvb-frontends/stv0367.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
drivers/media/dvb-frontends/stv0367.c +21 -0
@@ -3011,6 +3011,25 @@ static int stv0367ddb_set_frontend(struct dvb_frontend *fe)return -EINVAL ; } +static void stv0367ddb_read_signal_strength (struct dvb_frontend *fe) +{ +struct stv0367_state *state = fe->demodulator_priv; +struct dtv_frontend_properties *p = &fe->dtv_property_cache; +s32 signalstrength; + +switch (state->activedemod) { +case demod_cab: + signalstrength =stv0367cab_get_rf_lvl (state) *1000 ; +break ; +default : + p->strength.stat[0 ].scale =FE_SCALE_NOT_AVAILABLE ; +return ; + } + + p->strength.stat[0 ].scale =FE_SCALE_DECIBEL ; + p->strength.stat[0 ].uvalue = signalstrength; +} +static void stv0367ddb_read_snr (struct dvb_frontend *fe) {struct stv0367_state *state = fe->demodulator_priv;
@@ -3086,6 +3105,8 @@ static int stv0367ddb_read_status(struct dvb_frontend *fe,if (ret)return ret; +stv0367ddb_read_signal_strength (fe); +/* read carrier/noise when a carrier is detected */ if (*status &FE_HAS_CARRIER )stv0367ddb_read_snr (fe);
Signature · 1 line
2.13.0
PATCH v3 4/4 dvb-frontends/stv0367: update UCB readout condition logic
In reply to Daniel SchellerFrom: Daniel Scheller <[email protected]>
Since the other statistics are read when fe_status conditions are TRUE, change the ucblocks readout logic to match this aswell.
--- drivers/media/dvb-frontends/stv0367.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/media/dvb-frontends/stv0367.c +4 -6
@@ -3113,13 +3113,11 @@ static int stv0367ddb_read_status(struct dvb_frontend *fe,else p->cnr.stat[0 ].scale =FE_SCALE_NOT_AVAILABLE ; -/* stop if demod isn't locked */ -if (!(*status &FE_HAS_LOCK )) { +/* read uncorrected blocks on FE_HAS_LOCK */ +if (*status &FE_HAS_LOCK ) +stv0367ddb_read_ucblocks (fe); +else p->block_error.stat[0 ].scale =FE_SCALE_NOT_AVAILABLE ; -return ret; - } - -stv0367ddb_read_ucblocks (fe);return 0 ; }
Signature · 1 line
2.13.0