Skip to contentSkip to conversation

cxd2820r: tweak search algorithm, enable LNA in DVB-T mode

PATCH In review Gianluca Gennari 3 participants 12 messages Mar 15, 2012 – Mar 23, 2012 1 message not in the archive Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

cover cxd2820r: tweak search algorithm, enable LNA in DVB-T mode

The PCTV 290e had several issues on my mipsel-based STB (powered by a Broadcom 7405 SoC), running a Linux 3.1 kernel and the Enigma2 OS.

The most annoying one was that the 290e was able to tune the lone DVB-T2 frequency existing in my area, but was not able to tune any DVB-T channel.

Following a suggestion of the original author of the driver, I tried to tweak the wait time in the lock loop. In fact, increasing the wait time from 50 to 200ms in the tuning loop was enough to get the lock on most channels.
But channel change was quite slow and sometimes, doing an automatic scan, some frequency was not locked.
So instead of playing with the timings I changed the behavior of the search algorithm as explained in the patch 1, with very good results.

With this modification, the automatic scan is 100% reliable and zapping is quite fast (on the STB). There is no noticeable difference when using Kaffeine on the PC.

But there was a further issue: a few weak channels were affected by high BER and badly corrupted pictures. The same channels were working fine on an Avermedia A867 stick (as well as other sticks).

The driver has an option to enable a "Low Noise Amplifier" (LNA) before the demodulator. Enabling it, the reception of weak channels improved a lot, as reported in the description of patch 2.

Finally, patch 3 is a trivial clean-up.

Best regards,
Gianluca Gennari

Gianluca Gennari (3):
cxd2820r: tweak search algorithm behavior
em28xx-dvb: enable LNA for cxd2820r in DVB-T mode
cxd2820r: delete unused function cxd2820r_init_t2

 drivers/media/dvb/frontends/cxd2820r_core.c |    4 ++--
 drivers/media/dvb/frontends/cxd2820r_priv.h |    2 --
 drivers/media/video/em28xx/em28xx-dvb.c     |    3 ++-
 3 files changed, 4 insertions(+), 5 deletions(-)
Signature · 1 line
1.7.5.4
#1 lore raw

PATCH 1/3 cxd2820r: tweak search algorithm behavior

MPIS based STBs running 3.x kernels and the Enigma2 OS are not able to tune DVB-T channels with the PCTV 290e using the current cxd2820r driver. DVB-T2 channels instead work properly.

This patch fixes the problem by changing the condition to break out from the wait lock loop in the "search" function of the cxd2820r demodulator from FE_HAS_SIGNAL to FE_HAS_LOCK.

As a consequence, the "search" function of the demodulator driver now returns DVBFE_ALGO_SEARCH_SUCCESS only if the frequency lock is successfully acquired.

This behavior seems consistent with other demodulator drivers (e.g. stv090x, hd29l2, stv0900, stb0899, mb86a16).

This patch has been successfully tested with DVB-T and DVB-T2 signals, on both PC and the mipsel STB running Enigma2.
No apparent side effect has been observed on PC applications like Kaffeine. DVB-C is not available in my country so it's not tested.

---
 drivers/media/dvb/frontends/cxd2820r_core.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/media/dvb/frontends/cxd2820r_core.c +2 -2
index 5c7c2aa..3bba37d 100644
@@ -526,12 +526,12 @@ static enum dvbfe_search cxd2820r_search(struct dvb_frontend *fe)
 		if (ret)
 			goto error;
 
-		if (status & FE_HAS_SIGNAL)
+		if (status & FE_HAS_LOCK)
 			break;
 	}
 
 	/* check if we have a valid signal */
-	if (status) {
+	if (status & FE_HAS_LOCK) {
 		priv->last_tune_failed = 0;
 		return DVBFE_ALGO_SEARCH_SUCCESS;
 	} else {
Signature · 1 line
1.7.5.4
#3 lore raw

PATCH 2/3 em28xx-dvb: enable LNA for cxd2820r in DVB-T mode

In reply to Gianluca Gennari

Enable the LNA amplifier also for DVB-T (like for DVB-T2 and DVB-C); this greatly improves reception of weak signals without affecting the reception of the strong ones.

Experimental data (collected with the mipsel STB) on the weakest frequencies available in my area:

LNA OFF:

MUX level BER picture

RAI mux 4    72%     32000   corrupted
TIMB 2       75%     14      OK
TVA Vicenza  68%     32000   corrupted
RAI mux 2    78%     14      OK

LNA ON:

MUX level BER picture

RAI mux 4    73%     1500    OK
TIMB 2       76%     0       OK
TVA Vicenza  69%     0       OK
RAI mux 2    79%     0       OK

Moreover, with LNA enabled, the PCTV 290e was able to pick up 2 new frequencies matching the integrated tuner of my Panasonic G20 TV, which is really good.

---
 drivers/media/video/em28xx/em28xx-dvb.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/media/video/em28xx/em28xx-dvb.c +2 -1
index fbd9010..4917b71 100644
@@ -502,7 +502,8 @@ static struct cxd2820r_config em28xx_cxd2820r_config = {
 	.i2c_address = (0xd8 >> 1),
 	.ts_mode = CXD2820R_TS_SERIAL,
 
-	/* enable LNA for DVB-T2 and DVB-C */
+	/* enable LNA for DVB-T, DVB-T2 and DVB-C */
+	.gpio_dvbt[0] = CXD2820R_GPIO_E | CXD2820R_GPIO_O | CXD2820R_GPIO_L,
 	.gpio_dvbt2[0] = CXD2820R_GPIO_E | CXD2820R_GPIO_O | CXD2820R_GPIO_L,
 	.gpio_dvbc[0] = CXD2820R_GPIO_E | CXD2820R_GPIO_O | CXD2820R_GPIO_L,
 };
Signature · 1 line
1.7.5.4
#7 lore raw

PATCH 3/3 cxd2820r: delete unused function cxd2820r_init_t2

In reply to Gianluca Gennari

Deleted unused declaration of function "cxd2820r_init_t2".

---
 drivers/media/dvb/frontends/cxd2820r_priv.h |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
drivers/media/dvb/frontends/cxd2820r_priv.h +0 -2
index 9a9822c..568b996 100644
@@ -146,8 +146,6 @@ int cxd2820r_read_snr_t2(struct dvb_frontend *fe, u16 *snr);
 
 int cxd2820r_read_ucblocks_t2(struct dvb_frontend *fe, u32 *ucblocks);
 
-int cxd2820r_init_t2(struct dvb_frontend *fe);
-
 int cxd2820r_sleep_t2(struct dvb_frontend *fe);
 
 int cxd2820r_get_tune_settings_t2(struct dvb_frontend *fe,
Signature · 1 line
1.7.5.4
#9 lore raw
In reply to Gianluca Gennari

Em 15-03-2012 14:33, Gianluca Gennari escreveu:

Quoted 19 lines

The PCTV 290e had several issues on my mipsel-based STB (powered by a Broadcom 7405 SoC), running a Linux 3.1 kernel and the Enigma2 OS.

The most annoying one was that the 290e was able to tune the lone DVB-T2 frequency existing in my area, but was not able to tune any DVB-T channel.

Following a suggestion of the original author of the driver, I tried to tweak the wait time in the lock loop. In fact, increasing the wait time from 50 to 200ms in the tuning loop was enough to get the lock on most channels.
But channel change was quite slow and sometimes, doing an automatic scan, some frequency was not locked.
So instead of playing with the timings I changed the behavior of the search algorithm as explained in the patch 1, with very good results.

With this modification, the automatic scan is 100% reliable and zapping is quite fast (on the STB). There is no noticeable difference when using Kaffeine on the PC.

Quoted 7 lines

But there was a further issue: a few weak channels were affected by high BER and badly corrupted pictures. The same channels were working fine on an Avermedia A867 stick (as well as other sticks).

The driver has an option to enable a "Low Noise Amplifier" (LNA) before the demodulator. Enabling it, the reception of weak channels improved a lot, as reported in the description of patch 2.

Hi Gianluca,

With regards to LNA, the better is to add a DVBv5 property for it.

The LNA is generally located at the antenna, and not at the device.

As you know, more than one device may be connected to the same antenna, and it is generally not a good idea to have two devices sending power to the LNA.

So, it is better to have a way to turn it on via the usespace API.

Also, as this consumes power, the better is to do it only when the device is actually used.

Regards,
Mauro

Quoted 16 lines

Finally, patch 3 is a trivial clean-up.

Best regards,
Gianluca Gennari

Gianluca Gennari (3):
cxd2820r: tweak search algorithm behavior
em28xx-dvb: enable LNA for cxd2820r in DVB-T mode
cxd2820r: delete unused function cxd2820r_init_t2

 drivers/media/dvb/frontends/cxd2820r_core.c |    4 ++--
 drivers/media/dvb/frontends/cxd2820r_priv.h |    2 --
 drivers/media/video/em28xx/em28xx-dvb.c     |    3 ++-
 3 files changed, 4 insertions(+), 5 deletions(-)
#10 lore raw
Quoted 28 lines · Mauro Carvalho Chehab

Em 15-03-2012 14:33, Gianluca Gennari escreveu:

Quoted 19 lines

The PCTV 290e had several issues on my mipsel-based STB (powered by a Broadcom 7405 SoC), running a Linux 3.1 kernel and the Enigma2 OS.

The most annoying one was that the 290e was able to tune the lone DVB-T2 frequency existing in my area, but was not able to tune any DVB-T channel.

Following a suggestion of the original author of the driver, I tried to tweak the wait time in the lock loop. In fact, increasing the wait time from 50 to 200ms in the tuning loop was enough to get the lock on most channels.
But channel change was quite slow and sometimes, doing an automatic scan, some frequency was not locked.
So instead of playing with the timings I changed the behavior of the search algorithm as explained in the patch 1, with very good results.

With this modification, the automatic scan is 100% reliable and zapping is quite fast (on the STB). There is no noticeable difference when using Kaffeine on the PC.

Quoted 7 lines

But there was a further issue: a few weak channels were affected by high BER and badly corrupted pictures. The same channels were working fine on an Avermedia A867 stick (as well as other sticks).

The driver has an option to enable a "Low Noise Amplifier" (LNA) before the demodulator. Enabling it, the reception of weak channels improved a lot, as reported in the description of patch 2.

Quoted 5 lines

Hi Gianluca,

With regards to LNA, the better is to add a DVBv5 property for it.

The LNA is generally located at the antenna, and not at the device.

LNA inside antenna, or near antenna, is called amplifier. Power to that amplifier is feed by device or power supply using antenna cable.

I see LNA more likely amplifier that is inside device. It could be external chip between tuner IC and antenna connector or more usually logical part inside tuner IC.

Thus I see two different use cases here. 1) LNA, 2) power supply to amplifier.

Quoted 8 lines

As you know, more than one device may be connected to the same antenna, and it is generally not a good idea to have two devices sending power to the LNA.

So, it is better to have a way to turn it on via the usespace API.

Also, as this consumes power, the better is to do it only when the device is actually used.

I think we need API support for LNA/amp + internal API support for AUTO LNA.

Originally I added LNA support as a module param for em28xx-dvb but Mauro NACKed it thus it is hard coded. Anyhow, some method switching LNA on/off is better than no method at all.

regards
Antti

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

Em 15-03-2012 14:49, Antti Palosaari escreveu:

Quoted 33 lines · Mauro Carvalho Chehab
Quoted 32 lines

Em 15-03-2012 14:33, Gianluca Gennari escreveu:

Quoted 19 lines

The PCTV 290e had several issues on my mipsel-based STB (powered by a Broadcom 7405 SoC), running a Linux 3.1 kernel and the Enigma2 OS.

The most annoying one was that the 290e was able to tune the lone DVB-T2 frequency existing in my area, but was not able to tune any DVB-T channel.

Following a suggestion of the original author of the driver, I tried to tweak the wait time in the lock loop. In fact, increasing the wait time from 50 to 200ms in the tuning loop was enough to get the lock on most channels.
But channel change was quite slow and sometimes, doing an automatic scan, some frequency was not locked.
So instead of playing with the timings I changed the behavior of the search algorithm as explained in the patch 1, with very good results.

With this modification, the automatic scan is 100% reliable and zapping is quite fast (on the STB). There is no noticeable difference when using Kaffeine on the PC.

Quoted 7 lines

But there was a further issue: a few weak channels were affected by high BER and badly corrupted pictures. The same channels were working fine on an Avermedia A867 stick (as well as other sticks).

The driver has an option to enable a "Low Noise Amplifier" (LNA) before the demodulator. Enabling it, the reception of weak channels improved a lot, as reported in the description of patch 2.

Hi Gianluca,

With regards to LNA, the better is to add a DVBv5 property for it.

Quoted 7 lines
Quoted 1 line

The LNA is generally located at the antenna, and not at the device.

LNA inside antenna, or near antenna, is called amplifier. Power to that amplifier is feed by device or power supply using antenna cable.

I see LNA more likely amplifier that is inside device. It could be external chip between tuner IC and antenna connector or more usually logical part inside tuner IC.

Thus I see two different use cases here. 1) LNA, 2) power supply to amplifier.

Yes, there are those two types of amplifiers. Some vendors ship hardware with a power amplify inside their antenna, and call it as LNA (as it is a low noise amplifier).

Quoted 10 lines
Quoted 8 lines

As you know, more than one device may be connected to the same antenna, and it is generally not a good idea to have two devices sending power to the LNA.

So, it is better to have a way to turn it on via the usespace API.

Also, as this consumes power, the better is to do it only when the device is actually used.

I think we need API support for LNA/amp + internal API support for AUTO LNA.

Yes.

Quoted 1 line

Originally I added LNA support as a module param for em28xx-dvb but Mauro NACKed it thus it is hard coded. Anyhow, some method switching LNA on/off is better than no method at all

Well, adding one or two DVBv5 properties to enable/disable the LNA is very easy.

So, instead of adding hacks, let's just do the right thing.

Quoted 4 lines

regards
Antti

Regards,
Mauro

#12 lore raw
In reply to Mauro Carvalho Chehab

Il 15/03/2012 18:41, Mauro Carvalho Chehab ha scritto:

Quoted 11 lines

Hi Gianluca,

With regards to LNA, the better is to add a DVBv5 property for it.

The LNA is generally located at the antenna, and not at the device.

As you know, more than one device may be connected to the same antenna, and it is generally not a good idea to have two devices sending power to the LNA.

Quoted 7 lines

So, it is better to have a way to turn it on via the usespace API.

Also, as this consumes power, the better is to do it only when the device is actually used.

Regards,
Mauro

Hi Mauro, I believe this "LNA" is just an internal amplifier that is embedded in the cxd2820r demodulator itself.
I have a "condo" antenna so there is no way I can control the power from my apartment as everything is centralized.

Many DTT receivers have a "5v power" option to drive the antenna amplifiers on the roof. But almost every antenna (at least here in Italy) has a dedicated power supply, in order to make things simpler for the user.
Anyway, a DVBv5 property to control this "power switch" is a good idea.

Regards,
Gianluca

Acked-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] cxd2820r: tweak search algorithm behavior

In reply to Gianluca Gennari

Still I am little bit sceptical about that since dvb_frontend.h comments are speaking signal search - not for full LOCK. Maybe there is room for improvement somewhere else. Anyhow, better to merge that as now.

regards
Antti

Quoted 43 lines · Gianluca Gennari

MPIS based STBs running 3.x kernels and the Enigma2 OS are not able to tune DVB-T channels with the PCTV 290e using the current cxd2820r driver. DVB-T2 channels instead work properly.

This patch fixes the problem by changing the condition to break out from the wait lock loop in the "search" function of the cxd2820r demodulator from FE_HAS_SIGNAL to FE_HAS_LOCK.

As a consequence, the "search" function of the demodulator driver now returns DVBFE_ALGO_SEARCH_SUCCESS only if the frequency lock is successfully acquired.

This behavior seems consistent with other demodulator drivers (e.g. stv090x, hd29l2, stv0900, stb0899, mb86a16).

This patch has been successfully tested with DVB-T and DVB-T2 signals, on both PC and the mipsel STB running Enigma2.
No apparent side effect has been observed on PC applications like Kaffeine. DVB-C is not available in my country so it's not tested.

---
  drivers/media/dvb/frontends/cxd2820r_core.c |    4 ++--
  1 files changed, 2 insertions(+), 2 deletions(-)
drivers/media/dvb/frontends/cxd2820r_core.c +2 -2
index 5c7c2aa..3bba37d 100644
@@ -526,12 +526,12 @@ static enum dvbfe_search cxd2820r_search(struct dvb_frontend *fe)
  		if (ret)
  			goto error;
 
-		if (status&  FE_HAS_SIGNAL)
+		if (status&  FE_HAS_LOCK)
  			break;
  	}
 
  	/* check if we have a valid signal */
-	if (status) {
+	if (status&  FE_HAS_LOCK) {
  		priv->last_tune_failed = 0;
  		return DVBFE_ALGO_SEARCH_SUCCESS;
  	} else {
Signature · 1 line
http://palosaari.fi/
Acked-by on v1 3/3
#8 lore raw

Re: [PATCH 3/3] cxd2820r: delete unused function cxd2820r_init_t2

In reply to Gianluca Gennari
Quoted 20 lines · Gianluca Gennari

Deleted unused declaration of function "cxd2820r_init_t2".

---
  drivers/media/dvb/frontends/cxd2820r_priv.h |    2 --
  1 files changed, 0 insertions(+), 2 deletions(-)
drivers/media/dvb/frontends/cxd2820r_priv.h +0 -2
index 9a9822c..568b996 100644
@@ -146,8 +146,6 @@ int cxd2820r_read_snr_t2(struct dvb_frontend *fe, u16 *snr);
 
  int cxd2820r_read_ucblocks_t2(struct dvb_frontend *fe, u32 *ucblocks);
 
-int cxd2820r_init_t2(struct dvb_frontend *fe);
-
  int cxd2820r_sleep_t2(struct dvb_frontend *fe);
 
  int cxd2820r_get_tune_settings_t2(struct dvb_frontend *fe,
Signature · 1 line
http://palosaari.fi/
#4 lore raw

Re: [PATCH 2/3] em28xx-dvb: enable LNA for cxd2820r in DVB-T mode

In reply to Gianluca Gennari

As we speak earlier LNA support is not implemented at all as our API / framework. My personal opinion LNA should be always disabled by default since it still makes some noise. Current hard coded values are just selected what gives better signal for me and thus are not optimal nor correct. Anyhow, I would not like to change those as for some user it could cause problems. And if I would change those I will disable all :)

So better to left as those are currently until API/DVB core is fixed to support LNA.

regards
Antti

Quoted 47 lines · Gianluca Gennari

Enable the LNA amplifier also for DVB-T (like for DVB-T2 and DVB-C); this greatly improves reception of weak signals without affecting the reception of the strong ones.

Experimental data (collected with the mipsel STB) on the weakest frequencies available in my area:

LNA OFF:

MUX level BER picture

RAI mux 4    72%     32000   corrupted
TIMB 2       75%     14      OK
TVA Vicenza  68%     32000   corrupted
RAI mux 2    78%     14      OK

LNA ON:

MUX level BER picture

RAI mux 4    73%     1500    OK
TIMB 2       76%     0       OK
TVA Vicenza  69%     0       OK
RAI mux 2    79%     0       OK

Moreover, with LNA enabled, the PCTV 290e was able to pick up 2 new frequencies matching the integrated tuner of my Panasonic G20 TV, which is really good.

---
  drivers/media/video/em28xx/em28xx-dvb.c |    3 ++-
  1 files changed, 2 insertions(+), 1 deletions(-)
drivers/media/video/em28xx/em28xx-dvb.c +2 -1
index fbd9010..4917b71 100644
@@ -502,7 +502,8 @@ static struct cxd2820r_config em28xx_cxd2820r_config = {
  	.i2c_address = (0xd8>>  1),
  	.ts_mode = CXD2820R_TS_SERIAL,
 
-	/* enable LNA for DVB-T2 and DVB-C */
+	/* enable LNA for DVB-T, DVB-T2 and DVB-C */
+	.gpio_dvbt[0] = CXD2820R_GPIO_E | CXD2820R_GPIO_O | CXD2820R_GPIO_L,
  	.gpio_dvbt2[0] = CXD2820R_GPIO_E | CXD2820R_GPIO_O | CXD2820R_GPIO_L,
  	.gpio_dvbc[0] = CXD2820R_GPIO_E | CXD2820R_GPIO_O | CXD2820R_GPIO_L,
  };
Signature · 1 line
http://palosaari.fi/
#6 lore raw

Re: [PATCH 2/3] em28xx-dvb: enable LNA for cxd2820r in DVB-T mode

In reply to a message not in the archive

Em 23-03-2012 11:30, Gianluca Gennari escreveu:

Quoted 8 lines · On Fri, Mar 23, 2012 at 1:55 PM, Antti Palosaari <[email protected]…

As we speak earlier LNA support is not implemented at all as our API / framework. My personal opinion LNA should be always disabled by default since it still makes some noise. Current hard coded values are just selected what gives better signal for me and thus are not optimal nor correct. Anyhow, I would not like to change those as for some user it could cause problems. And if I would change those I will disable all :)

So better to left as those are currently until API/DVB core is fixed to support LNA.

Quoted 7 lines

regards
Antti

Hi Antti,
my opinion is that, if we have to choose between LNA always ON or always OFF (until we have proper API support), the best option is always ON.

Just add an API for it. It is simple and clean: all you need to do is to add a new DVBv5 props. Please don't forget to update the DocBook when doing that.

Quoted 11 lines

For sure, an amplifier adds some noise (so it makes SNR a little worse). On the other hand, it make signals stronger and every demodulator needs a minimum signal strength to lock the channel.

So LNA is helping weak signals with good SNR, while it's damaging strong signals with poor SNR. I believe the first category of signals is far more common (especially if you want to use USB devices with portable antennas).

A secondary reason to disable LNA could be to reduce power consumption, but i believe this embedded LNA devices consume just a few mA (but I don't have exact figures) so I don't see this as a major issue.

The cxd2820r itself is a power hog so I think LNA does not make a substantial difference on power consumption.

Best regards,
Gianluca