linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/4] STV0367/DDB DVBv5 signal statistics
@ 2017-06-25 11:26 Daniel Scheller
  2017-06-25 11:26 ` [PATCH v3 1/4] [media] dvb-frontends/stv0367: Improve DVB-C/T frontend status Daniel Scheller
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Daniel Scheller @ 2017-06-25 11:26 UTC (permalink / raw)
  To: linux-media, mchehab, mchehab; +Cc: liplianin, rjkm, crope

From: Daniel Scheller <d.scheller@gmx.net>

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).

>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(-)

-- 
2.13.0

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v3 1/4] [media] dvb-frontends/stv0367: Improve DVB-C/T frontend status
  2017-06-25 11:26 [PATCH v3 0/4] STV0367/DDB DVBv5 signal statistics Daniel Scheller
@ 2017-06-25 11:26 ` Daniel Scheller
  2017-06-25 11:26 ` [PATCH v3 2/4] [media] dvb-frontends/stv0367: SNR DVBv5 statistics for DVB-C and T Daniel Scheller
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Daniel Scheller @ 2017-06-25 11:26 UTC (permalink / raw)
  To: linux-media, mchehab, mchehab; +Cc: liplianin, rjkm, crope

From: Mauro Carvalho Chehab <mchehab@s-opensource.com>

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.

Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Tested-by: Daniel Scheller <d.scheller@gmx.net>
Signed-off-by: Daniel Scheller <d.scheller@gmx.net>
---
 drivers/media/dvb-frontends/stv0367.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/media/dvb-frontends/stv0367.c b/drivers/media/dvb-frontends/stv0367.c
index f266c18c574c..9e5432b761b5 100644
--- a/drivers/media/dvb-frontends/stv0367.c
+++ b/drivers/media/dvb-frontends/stv0367.c
@@ -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;
-- 
2.13.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 2/4] [media] dvb-frontends/stv0367: SNR DVBv5 statistics for DVB-C and T
  2017-06-25 11:26 [PATCH v3 0/4] STV0367/DDB DVBv5 signal statistics Daniel Scheller
  2017-06-25 11:26 ` [PATCH v3 1/4] [media] dvb-frontends/stv0367: Improve DVB-C/T frontend status Daniel Scheller
@ 2017-06-25 11:26 ` Daniel Scheller
  2017-06-25 11:26 ` [PATCH v3 3/4] [media] dvb-frontends/stv0367: DVB-C signal strength statistics Daniel Scheller
  2017-06-25 11:26 ` [PATCH v3 4/4] [media] dvb-frontends/stv0367: update UCB readout condition logic Daniel Scheller
  3 siblings, 0 replies; 5+ messages in thread
From: Daniel Scheller @ 2017-06-25 11:26 UTC (permalink / raw)
  To: linux-media, mchehab, mchehab; +Cc: liplianin, rjkm, crope

From: Daniel Scheller <d.scheller@gmx.net>

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>
---
 drivers/media/dvb-frontends/stv0367.c | 39 +++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/drivers/media/dvb-frontends/stv0367.c b/drivers/media/dvb-frontends/stv0367.c
index 9e5432b761b5..138f859d0f25 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"
@@ -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;
-- 
2.13.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 3/4] [media] dvb-frontends/stv0367: DVB-C signal strength statistics
  2017-06-25 11:26 [PATCH v3 0/4] STV0367/DDB DVBv5 signal statistics Daniel Scheller
  2017-06-25 11:26 ` [PATCH v3 1/4] [media] dvb-frontends/stv0367: Improve DVB-C/T frontend status Daniel Scheller
  2017-06-25 11:26 ` [PATCH v3 2/4] [media] dvb-frontends/stv0367: SNR DVBv5 statistics for DVB-C and T Daniel Scheller
@ 2017-06-25 11:26 ` Daniel Scheller
  2017-06-25 11:26 ` [PATCH v3 4/4] [media] dvb-frontends/stv0367: update UCB readout condition logic Daniel Scheller
  3 siblings, 0 replies; 5+ messages in thread
From: Daniel Scheller @ 2017-06-25 11:26 UTC (permalink / raw)
  To: linux-media, mchehab, mchehab; +Cc: liplianin, rjkm, crope

From: Daniel Scheller <d.scheller@gmx.net>

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.

Signed-off-by: Daniel Scheller <d.scheller@gmx.net>
---
 drivers/media/dvb-frontends/stv0367.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/drivers/media/dvb-frontends/stv0367.c b/drivers/media/dvb-frontends/stv0367.c
index 138f859d0f25..6097752a93bc 100644
--- a/drivers/media/dvb-frontends/stv0367.c
+++ b/drivers/media/dvb-frontends/stv0367.c
@@ -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);
-- 
2.13.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 4/4] [media] dvb-frontends/stv0367: update UCB readout condition logic
  2017-06-25 11:26 [PATCH v3 0/4] STV0367/DDB DVBv5 signal statistics Daniel Scheller
                   ` (2 preceding siblings ...)
  2017-06-25 11:26 ` [PATCH v3 3/4] [media] dvb-frontends/stv0367: DVB-C signal strength statistics Daniel Scheller
@ 2017-06-25 11:26 ` Daniel Scheller
  3 siblings, 0 replies; 5+ messages in thread
From: Daniel Scheller @ 2017-06-25 11:26 UTC (permalink / raw)
  To: linux-media, mchehab, mchehab; +Cc: liplianin, rjkm, crope

From: Daniel Scheller <d.scheller@gmx.net>

Since the other statistics are read when fe_status conditions are TRUE,
change the ucblocks readout logic to match this aswell.

Signed-off-by: Daniel Scheller <d.scheller@gmx.net>
---
 drivers/media/dvb-frontends/stv0367.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/media/dvb-frontends/stv0367.c b/drivers/media/dvb-frontends/stv0367.c
index 6097752a93bc..18ad1488be48 100644
--- a/drivers/media/dvb-frontends/stv0367.c
+++ b/drivers/media/dvb-frontends/stv0367.c
@@ -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;
 }
-- 
2.13.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-06-25 11:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-25 11:26 [PATCH v3 0/4] STV0367/DDB DVBv5 signal statistics Daniel Scheller
2017-06-25 11:26 ` [PATCH v3 1/4] [media] dvb-frontends/stv0367: Improve DVB-C/T frontend status Daniel Scheller
2017-06-25 11:26 ` [PATCH v3 2/4] [media] dvb-frontends/stv0367: SNR DVBv5 statistics for DVB-C and T Daniel Scheller
2017-06-25 11:26 ` [PATCH v3 3/4] [media] dvb-frontends/stv0367: DVB-C signal strength statistics Daniel Scheller
2017-06-25 11:26 ` [PATCH v3 4/4] [media] dvb-frontends/stv0367: update UCB readout condition logic Daniel Scheller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).