Skip to contentSkip to conversation

STV0367/DDB DVBv5 signal statistics

PATCH Superseded Daniel Scheller 3 participants 11 messages Jun 20, 2017 – Jun 24, 2017 Media (V4L/DVB)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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.

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.

Daniel Scheller (4):
[media] dvb-frontends/stv0367: initial DDB DVBv5 stats, implement
ucblocks
[media] dvb-frontends/stv0367: split SNR determination into functions [media] dvb-frontends/stv0367: SNR DVBv5 statistics for DVB-C and T [media] dvb-frontends/stv0367: DVB-C signal strength statistics

 drivers/media/dvb-frontends/stv0367.c | 180 ++++++++++++++++++++++++++++------
 1 file changed, 150 insertions(+), 30 deletions(-)
Signature · 1 line
2.13.0
#1 lore raw

PATCH 1/4 dvb-frontends/stv0367: initial DDB DVBv5 stats, implement ucblocks

From: Daniel Scheller <[email protected]>

This adds the basics to stv0367ddb_get_frontend() to be able to properly provide signal statistics in DVBv5 format. Also adds UCB readout and provides those values.

---
 drivers/media/dvb-frontends/stv0367.c | 59 ++++++++++++++++++++++++++++++++---
 1 file changed, 55 insertions(+), 4 deletions(-)
drivers/media/dvb-frontends/stv0367.c +55 -4
index e726c2e00460..5374d4eaabd6 100644
@@ -2997,21 +2997,64 @@ static int stv0367ddb_read_status(struct dvb_frontend *fe,
 	return -EINVAL;
 }
 
+static void stv0367ddb_read_ucblocks(struct dvb_frontend *fe)
+{
+	struct stv0367_state *state = fe->demodulator_priv;
+	struct dtv_frontend_properties *p = &fe->dtv_property_cache;
+	u32 ucblocks = 0;
+
+	switch (state->activedemod) {
+	case demod_ter:
+		stv0367ter_read_ucblocks(fe, &ucblocks);
+		break;
+	case demod_cab:
+		stv0367cab_read_ucblcks(fe, &ucblocks);
+		break;
+	default:
+		p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+		return;
+	}
+
+	p->block_error.stat[0].scale = FE_SCALE_COUNTER;
+	p->block_error.stat[0].uvalue = ucblocks;
+}
+
 static int stv0367ddb_get_frontend(struct dvb_frontend *fe,
 				   struct dtv_frontend_properties *p)
 {
 	struct stv0367_state *state = fe->demodulator_priv;
+	int ret = -EINVAL;
+	enum fe_status status = 0;
 
 	switch (state->activedemod) {
 	case demod_ter:
-		return stv0367ter_get_frontend(fe, p);
+		ret = stv0367ter_get_frontend(fe, p);
+		break;
 	case demod_cab:
-		return stv0367cab_get_frontend(fe, p);
-	default:
+		ret = stv0367cab_get_frontend(fe, p);
 		break;
+	default:
+		p->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+		p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+		p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+		return ret;
 	}
 
-	return -EINVAL;
+	/* read fe lock status */
+	if (!ret)
+		ret = stv0367ddb_read_status(fe, &status);
+
+	/* stop if get_frontend failed or if demod isn't locked */
+	if (ret || !(status & FE_HAS_LOCK)) {
+		p->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+		p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+		p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+		return ret;
+	}
+
+	stv0367ddb_read_ucblocks(fe);
+
+	return 0;
 }
 
 static int stv0367ddb_sleep(struct dvb_frontend *fe)
@@ -3035,6 +3078,7 @@ static int stv0367ddb_sleep(struct dvb_frontend *fe)
 static int stv0367ddb_init(struct stv0367_state *state)
 {
 	struct stv0367ter_state *ter_state = state->ter_state;
+	struct dtv_frontend_properties *p = &state->fe.dtv_property_cache;
 
 	stv0367_writereg(state, R367TER_TOPCTRL, 0x10);
 
@@ -3109,6 +3153,13 @@ static int stv0367ddb_init(struct stv0367_state *state)
 	ter_state->first_lock = 0;
 	ter_state->unlock_counter = 2;
 
+	p->strength.len = 1;
+	p->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+	p->cnr.len = 1;
+	p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+	p->block_error.len = 1;
+	p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+
 	return 0;
 }
 
Signature · 1 line
2.13.0
#2 lore raw

Re: [PATCH 1/4] [media] dvb-frontends/stv0367: initial DDB DVBv5 stats, implement ucblocks

Quoted 67 lines · Daniel Scheller

From: Daniel Scheller <[email protected]>

This adds the basics to stv0367ddb_get_frontend() to be able to properly provide signal statistics in DVBv5 format. Also adds UCB readout and provides those values.

---
  drivers/media/dvb-frontends/stv0367.c | 59 ++++++++++++++++++++++++++++++++---
  1 file changed, 55 insertions(+), 4 deletions(-)
drivers/media/dvb-frontends/stv0367.c +33 -4
index e726c2e00460..5374d4eaabd6 100644
@@ -2997,21 +2997,64 @@ static int stv0367ddb_read_status(struct dvb_frontend *fe,
  	return -EINVAL;
  }
 
+static void stv0367ddb_read_ucblocks(struct dvb_frontend *fe)
+{
+	struct stv0367_state *state = fe->demodulator_priv;
+	struct dtv_frontend_properties *p = &fe->dtv_property_cache;
+	u32 ucblocks = 0;
+
+	switch (state->activedemod) {
+	case demod_ter:
+		stv0367ter_read_ucblocks(fe, &ucblocks);
+		break;
+	case demod_cab:
+		stv0367cab_read_ucblcks(fe, &ucblocks);
+		break;
+	default:
+		p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+		return;
+	}
+
+	p->block_error.stat[0].scale = FE_SCALE_COUNTER;
+	p->block_error.stat[0].uvalue = ucblocks;
+}
+
  static int stv0367ddb_get_frontend(struct dvb_frontend *fe,
  				   struct dtv_frontend_properties *p)
  {
  	struct stv0367_state *state = fe->demodulator_priv;
+	int ret = -EINVAL;
+	enum fe_status status = 0;
 
  	switch (state->activedemod) {
  	case demod_ter:
-		return stv0367ter_get_frontend(fe, p);
+		ret = stv0367ter_get_frontend(fe, p);
+		break;
  	case demod_cab:
-		return stv0367cab_get_frontend(fe, p);
-	default:
+		ret = stv0367cab_get_frontend(fe, p);
  		break;
+	default:
+		p->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+		p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+		p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+		return ret;
  	}
 
-	return -EINVAL;
+	/* read fe lock status */

drivers/media/dvb-frontends/stv0367.c static int stv0367ddb_read_status(struct dvb_frontend *fe, · line 3053

Quoted 10 lines
drivers/media/dvb-frontends/stv0367.c +10 -0
+	if (!ret)
+		ret = stv0367ddb_read_status(fe, &status);
+
+	/* stop if get_frontend failed or if demod isn't locked */
+	if (ret || !(status & FE_HAS_LOCK)) {
+		p->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+		p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+		p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+		return ret;
+	}

Requiring LOCK for strength and cnr sounds wrong. Demod usually calculates strength from IF and RF AGC and those are available even there is no signal at all (demod set those gains to max on that case). CNR is pretty often available when inner FEC (viterbi, LDPC) is on sync.

And for ber and per you need outer fec (reed-solomon, bch) too which is FE_HAS_SYNC flag on api. ber is error bit and count after inner fec, per is error packet and count after outer fec. Usually ber is counted as a bits and per is counted as a 204 ts packets.

Also having that statistics stuff updated inside a get_frontend() sounds wrong. I think that callback is optional and is not called unless userspace polls it.

Quoted 20 lines
drivers/media/dvb-frontends/stv0367.c +5 -0
+
+	stv0367ddb_read_ucblocks(fe);
+
+	return 0;
  }
 
  static int stv0367ddb_sleep(struct dvb_frontend *fe)
@@ -3035,6 +3078,7 @@ static int stv0367ddb_sleep(struct dvb_frontend *fe)
  static int stv0367ddb_init(struct stv0367_state *state)
  {
  	struct stv0367ter_state *ter_state = state->ter_state;
+	struct dtv_frontend_properties *p = &state->fe.dtv_property_cache;
 
  	stv0367_writereg(state, R367TER_TOPCTRL, 0x10);
 
@@ -3109,6 +3153,13 @@ static int stv0367ddb_init(struct stv0367_state *state)
  	ter_state->first_lock = 0;
  	ter_state->unlock_counter = 2;
 

drivers/media/dvb-frontends/stv0367.c static int stv0367ddb_init(struct stv0367_state *state) · line 3165

Quoted 10 lines
drivers/media/dvb-frontends/stv0367.c +7 -0
+	p->strength.len = 1;
+	p->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+	p->cnr.len = 1;
+	p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+	p->block_error.len = 1;
+	p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+
  	return 0;
  }
 

regards
Antti

Signature · 1 line
http://palosaari.fi/
#3 lore raw

Re: [PATCH 1/4] [media] dvb-frontends/stv0367: initial DDB DVBv5 stats, implement ucblocks

Am Wed, 21 Jun 2017 09:06:22 +0300
schrieb Antti Palosaari <[email protected]>:

Quoted 84 lines · Daniel Scheller
Quoted 67 lines

From: Daniel Scheller <[email protected]>

This adds the basics to stv0367ddb_get_frontend() to be able to properly provide signal statistics in DVBv5 format. Also adds UCB readout and provides those values.

---
  drivers/media/dvb-frontends/stv0367.c | 59 ++++++++++++++++++++++++++++++++---
  1 file changed, 55 insertions(+), 4 deletions(-)
drivers/media/dvb-frontends/stv0367.c +33 -4
index e726c2e00460..5374d4eaabd6 100644
@@ -2997,21 +2997,64 @@ static int stv0367ddb_read_status(struct dvb_frontend *fe,
  	return -EINVAL;
  }
 
+static void stv0367ddb_read_ucblocks(struct dvb_frontend *fe)
+{
+	struct stv0367_state *state = fe->demodulator_priv;
+	struct dtv_frontend_properties *p = &fe->dtv_property_cache;
+	u32 ucblocks = 0;
+
+	switch (state->activedemod) {
+	case demod_ter:
+		stv0367ter_read_ucblocks(fe, &ucblocks);
+		break;
+	case demod_cab:
+		stv0367cab_read_ucblcks(fe, &ucblocks);
+		break;
+	default:
+		p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+		return;
+	}
+
+	p->block_error.stat[0].scale = FE_SCALE_COUNTER;
+	p->block_error.stat[0].uvalue = ucblocks;
+}
+
  static int stv0367ddb_get_frontend(struct dvb_frontend *fe,
  				   struct dtv_frontend_properties *p)
  {
  	struct stv0367_state *state = fe->demodulator_priv;
+	int ret = -EINVAL;
+	enum fe_status status = 0;
 
  	switch (state->activedemod) {
  	case demod_ter:
-		return stv0367ter_get_frontend(fe, p);
+		ret = stv0367ter_get_frontend(fe, p);
+		break;
  	case demod_cab:
-		return stv0367cab_get_frontend(fe, p);
-	default:
+		ret = stv0367cab_get_frontend(fe, p);
  		break;
+	default:
+		p->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+		p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+		p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+		return ret;
  	}
 
-	return -EINVAL;
+	/* read fe lock status */

drivers/media/dvb-frontends/stv0367.c static int stv0367ddb_read_status(struct dvb_frontend *fe, · line 3053

Quoted 10 lines
drivers/media/dvb-frontends/stv0367.c +10 -0
+	if (!ret)
+		ret = stv0367ddb_read_status(fe, &status);
+
+	/* stop if get_frontend failed or if demod isn't locked */
+	if (ret || !(status & FE_HAS_LOCK)) {
+		p->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+		p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+		p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+		return ret;
+	}  

Requiring LOCK for strength and cnr sounds wrong. Demod usually calculates strength from IF and RF AGC and those are available even there is no signal at all (demod set those gains to max on that case). CNR is pretty often available when inner FEC (viterbi, LDPC) is on sync.

Quoted 4 lines

And for ber and per you need outer fec (reed-solomon, bch) too which is FE_HAS_SYNC flag on api. ber is error bit and count after inner fec, per is error packet and count after outer fec. Usually ber is counted as a bits and per is counted as a 204 ts packets.

Re ber/per, note that I don't have any register documentation available, everything has been gathered from this and from DD's stv0367dd driver. That said, the same applies to FE_HAS_SYNC. This driver currently only reports FE_HAS_LOCK for both OFDM and QAM operation modes, see L1503 (OFDM) and L2152. In stv0367dd, lock state acquisition is a bit more detailed. For the ddb-parts though, I even had to implement a var which carries the register which tells us in QAM mode where to acquire the lockstate from, so I don't want to blindly carry over that code since this will risk breakage of all other consumers of the stv0367 demod driver and thus the card support, neither do I want to additionally port over the read_status code since this will result in unneeded duplication of things. So atm things won't improve unless someone with some other hardware using this demod pops up, willing to experiment.

Of course I can do snr/cnr readout regardless of FE_HAS_LOCK - no strong opinion on this (needs a quick test though). Depending on if you make this a strong change requirement - please elaborate.

Quoted 3 lines

Also having that statistics stuff updated inside a get_frontend() sounds wrong. I think that callback is optional and is not called unless userspace polls it.

I oriented myself on other drivers (cxd2841er for example also does this stuff in get_frontend). In your af9033 I saw you're doing this in read_status though. Would that be preferred?

Signature · 4 lines
Best regards,
Daniel Scheller
-- 
https://github.com/herrnst
#4 lore raw

Re: [PATCH 1/4] [media] dvb-frontends/stv0367: initial DDB DVBv5 stats, implement ucblocks

Em Wed, 21 Jun 2017 17:45:04 +0200
Daniel Scheller <[email protected]> escreveu:

Quoted 87 lines

Am Wed, 21 Jun 2017 09:06:22 +0300
schrieb Antti Palosaari <[email protected]>:

Quoted 84 lines · Daniel Scheller
Quoted 67 lines

From: Daniel Scheller <[email protected]>

This adds the basics to stv0367ddb_get_frontend() to be able to properly provide signal statistics in DVBv5 format. Also adds UCB readout and provides those values.

---
  drivers/media/dvb-frontends/stv0367.c | 59 ++++++++++++++++++++++++++++++++---
  1 file changed, 55 insertions(+), 4 deletions(-)
drivers/media/dvb-frontends/stv0367.c +33 -4
index e726c2e00460..5374d4eaabd6 100644
@@ -2997,21 +2997,64 @@ static int stv0367ddb_read_status(struct dvb_frontend *fe,
  	return -EINVAL;
  }
 
+static void stv0367ddb_read_ucblocks(struct dvb_frontend *fe)
+{
+	struct stv0367_state *state = fe->demodulator_priv;
+	struct dtv_frontend_properties *p = &fe->dtv_property_cache;
+	u32 ucblocks = 0;
+
+	switch (state->activedemod) {
+	case demod_ter:
+		stv0367ter_read_ucblocks(fe, &ucblocks);
+		break;
+	case demod_cab:
+		stv0367cab_read_ucblcks(fe, &ucblocks);
+		break;
+	default:
+		p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+		return;
+	}
+
+	p->block_error.stat[0].scale = FE_SCALE_COUNTER;
+	p->block_error.stat[0].uvalue = ucblocks;
+}
+
  static int stv0367ddb_get_frontend(struct dvb_frontend *fe,
  				   struct dtv_frontend_properties *p)
  {
  	struct stv0367_state *state = fe->demodulator_priv;
+	int ret = -EINVAL;
+	enum fe_status status = 0;
 
  	switch (state->activedemod) {
  	case demod_ter:
-		return stv0367ter_get_frontend(fe, p);
+		ret = stv0367ter_get_frontend(fe, p);
+		break;
  	case demod_cab:
-		return stv0367cab_get_frontend(fe, p);
-	default:
+		ret = stv0367cab_get_frontend(fe, p);
  		break;
+	default:
+		p->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+		p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+		p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+		return ret;
  	}
 
-	return -EINVAL;
+	/* read fe lock status */

drivers/media/dvb-frontends/stv0367.c static int stv0367ddb_read_status(struct dvb_frontend *fe, · line 3053

Quoted 10 lines
drivers/media/dvb-frontends/stv0367.c +10 -0
+	if (!ret)
+		ret = stv0367ddb_read_status(fe, &status);
+
+	/* stop if get_frontend failed or if demod isn't locked */
+	if (ret || !(status & FE_HAS_LOCK)) {
+		p->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+		p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+		p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+		return ret;
+	}    

Requiring LOCK for strength and cnr sounds wrong. Demod usually calculates strength from IF and RF AGC and those are available even there is no signal at all (demod set those gains to max on that case). CNR is pretty often available when inner FEC (viterbi, LDPC) is on sync.

Quoted 8 lines
Quoted 4 lines

And for ber and per you need outer fec (reed-solomon, bch) too which is FE_HAS_SYNC flag on api. ber is error bit and count after inner fec, per is error packet and count after outer fec. Usually ber is counted as a bits and per is counted as a 204 ts packets.

Re ber/per, note that I don't have any register documentation available, everything has been gathered from this and from DD's stv0367dd driver. That said, the same applies to FE_HAS_SYNC. This driver currently only reports FE_HAS_LOCK for both OFDM and QAM operation modes, see L1503 (OFDM) and L2152. In stv0367dd, lock state acquisition is a bit more detailed. For the ddb-parts though, I even had to implement a var which carries the register which tells us in QAM mode where to acquire the lockstate from, so I don't want to blindly carry over that code since this will risk breakage of all other consumers of the stv0367 demod driver and thus the card support, neither do I want to additionally port over the read_status code since this will result in unneeded duplication of things. So atm things won't improve unless someone with some other hardware using this demod pops up, willing to experiment.

Of course I can do snr/cnr readout regardless of FE_HAS_LOCK - no strong opinion on this (needs a quick test though). Depending on if you make this a strong change requirement - please elaborate.

Daniel,

You don't need register documentation to know that UCB stats won't be available before locks.

As this is the second time this week a different developer is having issues to implement it the right way, I'm, assuming a \mea culpa\, as we have almost no documentation about that.

So, I decided to write a patch for the DVB documentation, explaining how we expect it to be done and why:

	https://patchwork.linuxtv.org/patch/42081/
Quoted 7 lines

Of course I can do snr/cnr readout regardless of FE_HAS_LOCK - no strong opinion on this (needs a quick test though). Depending on if you make this a strong change requirement - please elaborate.

Quoted 3 lines

Also having that statistics stuff updated inside a get_frontend() sounds wrong. I think that callback is optional and is not called unless userspace polls it.

I oriented myself on other drivers (cxd2841er for example also does this stuff in get_frontend). In your af9033 I saw you're doing this in read_status though. Would that be preferred?

I guess we pointed this issue to Abylay when I reviewed his patchset adding the cxd2841 driver. I guess I ended merging without this fix.

Thanks,
Mauro

#5 lore raw

PATCH 2/4 dvb-frontends/stv0367: split SNR determination into functions

In reply to Daniel Scheller

From: Daniel Scheller <[email protected]>

The read_snr() functions currently do some magic to return relative scale values when called. Split out register readouts into separate functions so the functionality can be reused in some other way.

---
 drivers/media/dvb-frontends/stv0367.c | 68 +++++++++++++++++++++--------------
 1 file changed, 42 insertions(+), 26 deletions(-)
drivers/media/dvb-frontends/stv0367.c +42 -26
index 5374d4eaabd6..bb498f942ebd 100644
@@ -1437,7 +1437,7 @@ static int stv0367ter_get_frontend(struct dvb_frontend *fe,
 	return 0;
 }
 
-static int stv0367ter_read_snr(struct dvb_frontend *fe, u16 *snr)
+static u32 stv0367ter_snr_readreg(struct dvb_frontend *fe)
 {
 	struct stv0367_state *state = fe->demodulator_priv;
 	u32 snru32 = 0;
@@ -1453,10 +1453,16 @@ static int stv0367ter_read_snr(struct dvb_frontend *fe, u16 *snr)
 
 		cpt++;
 	}
-
 	snru32 /= 10;/*average on 10 values*/
 
-	*snr = snru32 / 1000;
+	return snru32;
+}
+
+static int stv0367ter_read_snr(struct dvb_frontend *fe, u16 *snr)
+{
+	u32 snrval = stv0367ter_snr_readreg(fe);
+
+	*snr = snrval / 1000;
 
 	return 0;
 }
@@ -2702,51 +2708,61 @@ static int stv0367cab_read_strength(struct dvb_frontend *fe, u16 *strength)
 	return 0;
 }
 
-static int stv0367cab_read_snr(struct dvb_frontend *fe, u16 *snr)
+static int stv0367cab_snr_power(struct dvb_frontend *fe)
 {
 	struct stv0367_state *state = fe->demodulator_priv;
-	u32 noisepercentage;
 	enum stv0367cab_mod QAMSize;
-	u32 regval = 0, temp = 0;
-	int power, i;
 
 	QAMSize = stv0367_readbits(state, F367CAB_QAM_MODE);
 	switch (QAMSize) {
 	case FE_CAB_MOD_QAM4:
-		power = 21904;
-		break;
+		return 21904;
 	case FE_CAB_MOD_QAM16:
-		power = 20480;
-		break;
+		return 20480;
 	case FE_CAB_MOD_QAM32:
-		power = 23040;
-		break;
+		return 23040;
 	case FE_CAB_MOD_QAM64:
-		power = 21504;
-		break;
+		return 21504;
 	case FE_CAB_MOD_QAM128:
-		power = 23616;
-		break;
+		return 23616;
 	case FE_CAB_MOD_QAM256:
-		power = 21760;
-		break;
-	case FE_CAB_MOD_QAM512:
-		power = 1;
-		break;
+		return 21760;
 	case FE_CAB_MOD_QAM1024:
-		power = 21280;
-		break;
+		return 21280;
 	default:
-		power = 1;
 		break;
 	}
 
+	return 1;
+}
+
+static int stv0367cab_snr_readreg(struct dvb_frontend *fe, int avgdiv)
+{
+	struct stv0367_state *state = fe->demodulator_priv;
+	u32 regval = 0;
+	int i;
+
 	for (i = 0; i < 10; i++) {
 		regval += (stv0367_readbits(state, F367CAB_SNR_LO)
 			+ 256 * stv0367_readbits(state, F367CAB_SNR_HI));
 	}
 
-	regval /= 10; /*for average over 10 times in for loop above*/
+	if (avgdiv)
+		regval /= 10;
+
+	return regval;
+}
+
+static int stv0367cab_read_snr(struct dvb_frontend *fe, u16 *snr)
+{
+	struct stv0367_state *state = fe->demodulator_priv;
+	u32 noisepercentage;
+	u32 regval = 0, temp = 0;
+	int power;
+
+	power = stv0367cab_snr_power(fe);
+	regval = stv0367cab_snr_readreg(fe, 1);
+
 	if (regval != 0) {
 		temp = power
 			* (1 << (3 + stv0367_readbits(state, F367CAB_SNR_PER)));
Signature · 1 line
2.13.0
#6 lore raw

PATCH 3/4 dvb-frontends/stv0367: SNR DVBv5 statistics for DVB-C and T

In reply to Daniel Scheller

From: 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 | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
drivers/media/dvb-frontends/stv0367.c +33 -0
index bb498f942ebd..0b13a407df23 100644
@@ -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"
@@ -33,6 +35,9 @@
 /* Max transfer size done by I2C transfer functions */
 #define MAX_XFER_SIZE  64
 
+/* snr logarithmic calc */
+#define INTLOG10X100(x) ((u32) (((u64) intlog10(x) * 100) >> 24))
+
 static int stvdebug;
 module_param_named(debug, stvdebug, int, 0644);
 
@@ -3013,6 +3018,33 @@ static int stv0367ddb_read_status(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);
+
+		tmpval = (cab_pwr * 320) / regval;
+		snrval = ((tmpval != 0) ? INTLOG10X100(tmpval) : 0) * 100;
+		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;
@@ -3069,6 +3101,7 @@ static int stv0367ddb_get_frontend(struct dvb_frontend *fe,
 	}
 
 	stv0367ddb_read_ucblocks(fe);
+	stv0367ddb_read_snr(fe);
 
 	return 0;
 }
Signature · 1 line
2.13.0
#7 lore raw

Re: [PATCH 3/4] [media] dvb-frontends/stv0367: SNR DVBv5 statistics for DVB-C and T

Quoted 45 lines · Daniel Scheller

From: 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 | 33 +++++++++++++++++++++++++++++++++
  1 file changed, 33 insertions(+)
drivers/media/dvb-frontends/stv0367.c +12 -0
index bb498f942ebd..0b13a407df23 100644
@@ -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"
@@ -33,6 +35,9 @@
  /* Max transfer size done by I2C transfer functions */
  #define MAX_XFER_SIZE  64
 
+/* snr logarithmic calc */
+#define INTLOG10X100(x) ((u32) (((u64) intlog10(x) * 100) >> 24))
+
  static int stvdebug;
  module_param_named(debug, stvdebug, int, 0644);
 
@@ -3013,6 +3018,33 @@ static int stv0367ddb_read_status(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;
+

drivers/media/dvb-frontends/stv0367.c static int stv0367ddb_read_status(struct dvb_frontend *fe, · line 3037

Quoted 10 lines
drivers/media/dvb-frontends/stv0367.c +10 -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);
+
+		tmpval = (cab_pwr * 320) / regval;
+		snrval = ((tmpval != 0) ? INTLOG10X100(tmpval) : 0) * 100;

How much there will be rounding errors due to that signal/noise division? I would convert it to calculation of sums (tip logarithm calculation rules).

Also, that INTLOG10X100 is pretty much useless. Use just what intlog10/intlog2 offers without yet again another conversion.

Quoted 15 lines
drivers/media/dvb-frontends/stv0367.c +10 -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;

drivers/media/dvb-frontends/stv0367.c static int stv0367ddb_get_frontend(struct dvb_frontend *fe, · line 3107

Quoted 7 lines
drivers/media/dvb-frontends/stv0367.c +1 -0
@@ -3069,6 +3101,7 @@ static int stv0367ddb_get_frontend(struct dvb_frontend *fe,
  	}
 
  	stv0367ddb_read_ucblocks(fe);
+	stv0367ddb_read_snr(fe);
 
  	return 0;
  }

regards
Antti

Signature · 1 line
http://palosaari.fi/
#8 lore raw

Re: [PATCH 3/4] [media] dvb-frontends/stv0367: SNR DVBv5 statistics for DVB-C and T

Am Wed, 21 Jun 2017 09:30:27 +0300
schrieb Antti Palosaari <[email protected]>:

Quoted 52 lines · Daniel Scheller
Quoted 51 lines

From: 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 | 33 +++++++++++++++++++++++++++++++++
  1 file changed, 33 insertions(+)
drivers/media/dvb-frontends/stv0367.c +18 -0
index bb498f942ebd..0b13a407df23 100644
@@ -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"
@@ -33,6 +35,9 @@
  /* Max transfer size done by I2C transfer functions */
  #define MAX_XFER_SIZE  64
 
+/* snr logarithmic calc */
+#define INTLOG10X100(x) ((u32) (((u64) intlog10(x) * 100) >> 24))
+
  static int stvdebug;
  module_param_named(debug, stvdebug, int, 0644);
 
@@ -3013,6 +3018,33 @@ static int stv0367ddb_read_status(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);
Quoted 8 lines

drivers/media/dvb-frontends/stv0367.c static int stv0367ddb_read_status(struct dvb_frontend *fe, · line 3037

Quoted 4 lines
drivers/media/dvb-frontends/stv0367.c +4 -0
+		regval = stv0367cab_snr_readreg(fe, 0);
+
+		tmpval = (cab_pwr * 320) / regval;
+		snrval = ((tmpval != 0) ? INTLOG10X100(tmpval) : 0) * 100;  

How much there will be rounding errors due to that signal/noise division? I would convert it to calculation of sums (tip logarithm calculation rules).

This is taken from stv0367dd aswell, the reported and calculated values are in 0.1dB precision. This and to not diverge any more from the "source" driver, I'd prefer to keep it how it is. These are just simple tuner cards anyway and by no means professional measurement gear, and should only give a more or less rough estimate on reception quality. E.g. my stv0367 cards report around 36dB SNR, whereas the cxd2841er reports ~37dB, compared to my DOCSIS modem, which reports 34dB on DOCSIS channels (another variant I had earlier even reported 39dB on the same channels), so... Even, we get way more precision than on the relative scale calc on the cab_read_snr functions which is in 10%-steps...

Quoted 2 lines

Also, that INTLOG10X100 is pretty much useless. Use just what intlog10/intlog2 offers without yet again another conversion.

Will check and experiment. Again, taken from stv0367dd :-)

Signature · 4 lines
Best regards,
Daniel Scheller
-- 
https://github.com/herrnst
#9 lore raw

Re: [PATCH 3/4] [media] dvb-frontends/stv0367: SNR DVBv5 statistics for DVB-C and T

Quoted 64 lines · Daniel Scheller

Am Wed, 21 Jun 2017 09:30:27 +0300
schrieb Antti Palosaari <[email protected]>:

Quoted 52 lines · Daniel Scheller
Quoted 51 lines

From: 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 | 33 +++++++++++++++++++++++++++++++++
   1 file changed, 33 insertions(+)
drivers/media/dvb-frontends/stv0367.c +18 -0
index bb498f942ebd..0b13a407df23 100644
@@ -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"
@@ -33,6 +35,9 @@
   /* Max transfer size done by I2C transfer functions */
   #define MAX_XFER_SIZE  64
 
+/* snr logarithmic calc */
+#define INTLOG10X100(x) ((u32) (((u64) intlog10(x) * 100) >> 24))
+
   static int stvdebug;
   module_param_named(debug, stvdebug, int, 0644);
 
@@ -3013,6 +3018,33 @@ static int stv0367ddb_read_status(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);
Quoted 8 lines

drivers/media/dvb-frontends/stv0367.c static int stv0367ddb_read_status(struct dvb_frontend *fe, · line 3037

Quoted 4 lines
drivers/media/dvb-frontends/stv0367.c +4 -0
+		regval = stv0367cab_snr_readreg(fe, 0);
+
+		tmpval = (cab_pwr * 320) / regval;
+		snrval = ((tmpval != 0) ? INTLOG10X100(tmpval) : 0) * 100;

How much there will be rounding errors due to that signal/noise division? I would convert it to calculation of sums (tip logarithm calculation rules).

Quoted 6 lines

This is taken from stv0367dd aswell, the reported and calculated values are in 0.1dB precision. This and to not diverge any more from the "source" driver, I'd prefer to keep it how it is. These are just simple tuner cards anyway and by no means professional measurement gear, and should only give a more or less rough estimate on reception quality. E.g. my stv0367 cards report around 36dB SNR, whereas the cxd2841er reports ~37dB, compared to my DOCSIS modem, which reports 34dB on DOCSIS channels (another variant I had earlier even reported 39dB on the same channels), so... Even, we get way more precision than on the relative scale calc on the cab_read_snr functions which is in 10%-steps...

Quoted 2 lines

Also, that INTLOG10X100 is pretty much useless. Use just what intlog10/intlog2 offers without yet again another conversion.

Will check and experiment. Again, taken from stv0367dd :-)

You should understand that there is no floating points on kernel, thus that kind of divisions needs special attention. It should be written log10(signal) - log10(noise) in order to minimize rounding errors. Lets say as example if you divide 2 by 3 you will get 0, not 0.666... So depending on actual numbers used on calculation, there is more or less rounding errors which are easily avoidable.

Antti

Signature · 1 line
http://palosaari.fi/
#10 lore raw

PATCH 4/4 dvb-frontends/stv0367: DVB-C signal strength statistics

In reply to Daniel Scheller

From: 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 | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/media/dvb-frontends/stv0367.c +20 -0
index 0b13a407df23..cf684ba70a3f 100644
@@ -3018,6 +3018,25 @@ static int stv0367ddb_read_status(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;
@@ -3102,6 +3121,7 @@ static int stv0367ddb_get_frontend(struct dvb_frontend *fe,
 
 	stv0367ddb_read_ucblocks(fe);
 	stv0367ddb_read_snr(fe);
+	stv0367ddb_read_signal_strength(fe);
 
 	return 0;
 }
Signature · 1 line
2.13.0