Skip to contentSkip to conversation

tda18271_set_analog_params major bugfix

PATCH In review [email protected] 2 participants 7 messages Sep 22, 2009 – Sep 27, 2009 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 tda18271_set_analog_params major bugfix

Multiplication by 62500 causes an overflow in the 32 bits "freq" register when using radio. FM radio reception on a Zolid Hybrid PCI is now working. Other tda18271 configurations may also benefit from this change ;)

Signed-off-by [email protected]
linux/drivers/media/common/tuners/tda18271-fe.c +30 -25
diff -r 29e4ba1a09bc linux/drivers/media/common/tuners/tda18271-fe.c
@@ -1001,38 +1020,43 @@
 	struct tda18271_std_map_item *map;
 	char *mode;
 	int ret;
-	u32 freq = params->frequency * 62500;
+	u32 freq;
 
 	priv->mode = TDA18271_ANALOG;
 
 	if (params->mode == V4L2_TUNER_RADIO) {
-		freq = freq / 1000;
+		freq = params->frequency * 625;
+		freq = freq / 10;
 		map = &std_map->fm_radio;
 		mode = "fm";
-	} else if (params->std & V4L2_STD_MN) {
-		map = &std_map->atv_mn;
-		mode = "MN";
-	} else if (params->std & V4L2_STD_B) {
-		map = &std_map->atv_b;
-		mode = "B";
-	} else if (params->std & V4L2_STD_GH) {
-		map = &std_map->atv_gh;
-		mode = "GH";
-	} else if (params->std & V4L2_STD_PAL_I) {
-		map = &std_map->atv_i;
-		mode = "I";
-	} else if (params->std & V4L2_STD_DK) {
-		map = &std_map->atv_dk;
-		mode = "DK";
-	} else if (params->std & V4L2_STD_SECAM_L) {
-		map = &std_map->atv_l;
-		mode = "L";
-	} else if (params->std & V4L2_STD_SECAM_LC) {
-		map = &std_map->atv_lc;
-		mode = "L'";
 	} else {
-		map = &std_map->atv_i;
-		mode = "xx";
+		freq = params->frequency * 62500;
+	
+		if (params->std & V4L2_STD_MN) {
+			map = &std_map->atv_mn;
+			mode = "MN";
+		} else if (params->std & V4L2_STD_B) {
+			map = &std_map->atv_b;
+			mode = "B";
+		} else if (params->std & V4L2_STD_GH) {
+			map = &std_map->atv_gh;
+			mode = "GH";
+		} else if (params->std & V4L2_STD_PAL_I) {
+			map = &std_map->atv_i;
+			mode = "I";
+		} else if (params->std & V4L2_STD_DK) {
+			map = &std_map->atv_dk;
+			mode = "DK";
+		} else if (params->std & V4L2_STD_SECAM_L) {
+			map = &std_map->atv_l;
+			mode = "L";
+		} else if (params->std & V4L2_STD_SECAM_LC) {
+			map = &std_map->atv_lc;
+			mode = "L'";
+		} else {
+			map = &std_map->atv_i;
+			mode = "xx";
+		}
 	}
 
 	tda_dbg("setting tda18271 to system %s\n", mode);
#1 lore raw
Quoted 70 lines · On Tue, Sep 22, 2009 at 5:05 PM, <[email protected]> wrote:

Multiplication by 62500 causes an overflow in the 32 bits "freq" register when using radio. FM radio reception on a Zolid Hybrid PCI is now working. Other tda18271 configurations may also benefit from this change ;)

Signed-off-by [email protected]

diff -r 29e4ba1a09bc linux/drivers/media/common/tuners/tda18271-fe.c

linux/drivers/media/common/tuners/tda18271-fe.c   Tue Sep 22 22:06:31 2009 +0200 renamed from linux/drivers/media/common/tuners/tda18271-fe.c   Sat Sep 19 09:45:22 2009 -0300 +23 -25
@@ -1001,38 +1020,43 @@
        struct tda18271_std_map_item *map;
        char *mode;
        int ret;
-       u32 freq = params->frequency * 62500;
+       u32 freq;
 
        priv->mode = TDA18271_ANALOG;
 
        if (params->mode == V4L2_TUNER_RADIO) {
-               freq = freq / 1000;
+               freq = params->frequency * 625;
+               freq = freq / 10;
                map = &std_map->fm_radio;
                mode = "fm";
-       } else if (params->std & V4L2_STD_MN) {
-               map = &std_map->atv_mn;
-               mode = "MN";
-       } else if (params->std & V4L2_STD_B) {
-               map = &std_map->atv_b;
-               mode = "B";
-       } else if (params->std & V4L2_STD_GH) {
-               map = &std_map->atv_gh;
-               mode = "GH";
-       } else if (params->std & V4L2_STD_PAL_I) {
-               map = &std_map->atv_i;
-               mode = "I";
-       } else if (params->std & V4L2_STD_DK) {
-               map = &std_map->atv_dk;
-               mode = "DK";
-       } else if (params->std & V4L2_STD_SECAM_L) {
-               map = &std_map->atv_l;
-               mode = "L";
-       } else if (params->std & V4L2_STD_SECAM_LC) {
-               map = &std_map->atv_lc;
-               mode = "L'";
        } else {
-               map = &std_map->atv_i;
-               mode = "xx";
+               freq = params->frequency * 62500;
+
+               if (params->std & V4L2_STD_MN) {
+                       map = &std_map->atv_mn;
+                       mode = "MN";
+               } else if (params->std & V4L2_STD_B) {
+                       map = &std_map->atv_b;
+                       mode = "B";
+               } else if (params->std & V4L2_STD_GH) {
+                       map = &std_map->atv_gh;
+                       mode = "GH";
+               } else if (params->std & V4L2_STD_PAL_I) {
+                       map = &std_map->atv_i;
+                       mode = "I";
+               } else if (params->std & V4L2_STD_DK) {
+                       map = &std_map->atv_dk;
+                       mode = "DK";
+               } else if (params->std & V4L2_STD_SECAM_L) {
+                       map = &std_map->atv_l;
+                       mode = "L";

linux/drivers/media/common/tuners/tda18271-fe.c   Tue Sep 22 22:06:31 2009 +0200 line 1062

Quoted 10 lines
linux/drivers/media/common/tuners/tda18271-fe.c   Tue Sep 22 22:06:31 2009 +0200 renamed from linux/drivers/media/common/tuners/tda18271-fe.c   Sat Sep 19 09:45:22 2009 -0300 +7 -0
+               } else if (params->std & V4L2_STD_SECAM_LC) {
+                       map = &std_map->atv_lc;
+                       mode = "L'";
+               } else {
+                       map = &std_map->atv_i;
+                       mode = "xx";
+               }
        }
 
        tda_dbg("setting tda18271 to system %s\n", mode);

Nice catch, Henk -- Thank you for this fix... I will have this one merged as soon as I can.

Mauro, please do not merge the tda18271 / tda829x patches until I send you a pull request -- there is a patch-order dependency with other pending changes and I would prefer to send this to you in the proper order.

Thanks,

Mike Krufky

#2 lore raw
Quoted 9 lines · Michael Krufky
Quoted 8 lines · On Tue, Sep 22, 2009 at 5:05 PM, <[email protected]> wrote:

Multiplication by 62500 causes an overflow in the 32 bits "freq" register when using radio. FM radio reception on a Zolid Hybrid PCI is now working. Other tda18271 configurations may also benefit from this change ;)

Signed-off-by [email protected]

diff -r 29e4ba1a09bc linux/drivers/media/common/tuners/tda18271-fe.c

...

Quoted 3 lines

linux/drivers/media/common/tuners/tda18271-fe.c line 1029

Quoted 3 lines
linux/drivers/media/common/tuners/tda18271-fe.c +2 -1
-               freq = freq / 1000;
+               freq = params->frequency * 625;
+               freq = freq / 10;

Hmm now that I review my own patch:

-               freq = freq / 1000;
+               freq = params->frequency * 125;
+               freq = freq / 2;

might even be better...

regards
henk

#3 lore raw
Quoted 15 lines · On Thu, Sep 24, 2009 at 5:42 PM, <[email protected]> wrote:
Quoted 9 lines · Michael Krufky
Quoted 8 lines · On Tue, Sep 22, 2009 at 5:05 PM,  <[email protected]> wrote:

Multiplication by 62500 causes an overflow in the 32 bits "freq" register when using radio. FM radio reception on a Zolid Hybrid PCI is now working. Other tda18271 configurations may also benefit from this change ;)

Signed-off-by [email protected]

diff -r 29e4ba1a09bc linux/drivers/media/common/tuners/tda18271-fe.c

...

Quoted 3 lines
Quoted 3 lines

-               freq = freq / 1000;
+               freq = params->frequency * 625;
+               freq = freq / 10;

Quoted 7 lines

Hmm now that I review my own patch:

-               freq = freq / 1000;
+               freq = params->frequency * 125;
+               freq = freq / 2;

might even be better...

Henk,

That certainly is better, but I am going to go with an even simpler & cleaner approach:

diff -r f52640ced9e8 linux/drivers/media/common/tuners/tda18271-fe.c
--- a/linux/drivers/media/common/tuners/tda18271-fe.c Tue Sep 15
01:25:35 2009 -0400
+++ b/linux/drivers/media/common/tuners/tda18271-fe.c Sun Sep 27
12:21:37 2009 -0400
@@ -1001,12 +1001,12 @@
struct tda18271_std_map_item *map;
char *mode;
int ret;
- u32 freq = params->frequency * 62500;
+ u32 freq = params->frequency *
+ ((params->mode == V4L2_TUNER_RADIO) ? 125 / 2 : 62500);

priv->mode = TDA18271_ANALOG;

if (params->mode == V4L2_TUNER_RADIO) {
- freq = freq / 1000;
map = &std_map->fm_radio;
mode = "fm";
} else if (params->std & V4L2_STD_MN) {

You still get the credit for spotting the problem & providing the original fix -- thanks again! I'm going to push this along with the others today.

Cheers,

Mike

#4 lore raw
Quoted 51 lines · Michael Krufky
Quoted 15 lines · On Thu, Sep 24, 2009 at 5:42 PM,  <[email protected]> wrote:
Quoted 9 lines · Michael Krufky
Quoted 8 lines · On Tue, Sep 22, 2009 at 5:05 PM,  <[email protected]> wrote:

Multiplication by 62500 causes an overflow in the 32 bits "freq" register when using radio. FM radio reception on a Zolid Hybrid PCI is now working. Other tda18271 configurations may also benefit from this change ;)

Signed-off-by [email protected]

diff -r 29e4ba1a09bc linux/drivers/media/common/tuners/tda18271-fe.c

...

Quoted 3 lines
Quoted 3 lines

-               freq = freq / 1000;
+               freq = params->frequency * 625;
+               freq = freq / 10;

Quoted 7 lines

Hmm now that I review my own patch:

-               freq = freq / 1000;
+               freq = params->frequency * 125;
+               freq = freq / 2;

might even be better...

Henk,

That certainly is better, but I am going to go with an even simpler & cleaner approach:

diff -r f52640ced9e8 linux/drivers/media/common/tuners/tda18271-fe.c --- a/linux/drivers/media/common/tuners/tda18271-fe.c   Tue Sep 15 01:25:35 2009 -0400
+++ b/linux/drivers/media/common/tuners/tda18271-fe.c   Sun Sep 27 12:21:37 2009 -0400

linux/drivers/media/common/tuners/tda18271-fe.c +2 -2
@@ -1001,12 +1001,12 @@
        struct tda18271_std_map_item *map;
        char *mode;
        int ret;
-       u32 freq = params->frequency * 62500;
+       u32 freq = params->frequency *
+               ((params->mode == V4L2_TUNER_RADIO) ? 125 / 2 : 62500);
 
        priv->mode = TDA18271_ANALOG;
 
        if (params->mode == V4L2_TUNER_RADIO) {
-               freq = freq / 1000;
                map = &std_map->fm_radio;
                mode = "fm";
        } else if (params->std & V4L2_STD_MN) {
Quoted 3 lines

You still get the credit for spotting the problem & providing the original fix -- thanks again!  I'm going to push this along with the others today.

On a second thought, I see that my above patch loses some precision ... this is even better:

diff -r f52640ced9e8 linux/drivers/media/common/tuners/tda18271-fe.c
--- a/linux/drivers/media/common/tuners/tda18271-fe.c Tue Sep 15
01:25:35 2009 -0400
+++ b/linux/drivers/media/common/tuners/tda18271-fe.c Sun Sep 27
12:33:20 2009 -0400
@@ -1001,12 +1001,12 @@
struct tda18271_std_map_item *map;
char *mode;
int ret;
- u32 freq = params->frequency * 62500;
+ u32 freq = params->frequency * 125 *
+ ((params->mode == V4L2_TUNER_RADIO) ? 1 : 1000) / 2;

priv->mode = TDA18271_ANALOG;

if (params->mode == V4L2_TUNER_RADIO) {
- freq = freq / 1000;
map = &std_map->fm_radio;
mode = "fm";
} else if (params->std & V4L2_STD_MN) {

Cheers,

Mike

#5 lore raw
Quoted 26 lines · Michael Krufky

On Sun, Sep 27, 2009 at 12:25 PM, Michael Krufky <[email protected]> wrote:

On a second thought, I see that my above patch loses some precision ... this is even better:

diff -r f52640ced9e8 linux/drivers/media/common/tuners/tda18271-fe.c
--- a/linux/drivers/media/common/tuners/tda18271-fe.c Tue Sep 15
01:25:35 2009 -0400
+++ b/linux/drivers/media/common/tuners/tda18271-fe.c Sun Sep 27
12:33:20 2009 -0400

linux/drivers/media/common/tuners/tda18271-fe.c +2 -2
@@ -1001,12 +1001,12 @@
 	struct tda18271_std_map_item *map;
 	char *mode;
 	int ret;
-	u32 freq = params->frequency * 62500;
+	u32 freq = params->frequency * 125 *
+		((params->mode == V4L2_TUNER_RADIO) ? 1 : 1000) / 2;
 
 	priv->mode = TDA18271_ANALOG;
 
 	if (params->mode == V4L2_TUNER_RADIO) {
-		freq = freq / 1000;
 		map = &std_map->fm_radio;
 		mode = "fm";
 	} else if (params->std & V4L2_STD_MN) {
Quoted 3 lines

Cheers,

Mike

Much better!

Btw. It seems that the tuner is capable of tuning in 1000 Hz steps, is there a reason why we are using 62500 Hz steps?

Regards,
Henk

#6 lore raw
Quoted 27 lines · On Sun, Sep 27, 2009 at 4:24 PM, <[email protected]> wrote:
Quoted 26 lines · Michael Krufky

On Sun, Sep 27, 2009 at 12:25 PM, Michael Krufky <[email protected]> wrote:

On a second thought, I see that my above patch loses some precision ...  this is even better:

diff -r f52640ced9e8 linux/drivers/media/common/tuners/tda18271-fe.c --- a/linux/drivers/media/common/tuners/tda18271-fe.c Tue Sep 15 01:25:35 2009 -0400
+++ b/linux/drivers/media/common/tuners/tda18271-fe.c Sun Sep 27 12:33:20 2009 -0400

linux/drivers/media/common/tuners/tda18271-fe.c +2 -2
@@ -1001,12 +1001,12 @@
       struct tda18271_std_map_item *map;
       char *mode;
       int ret;
-     u32 freq = params->frequency * 62500;
+     u32 freq = params->frequency * 125 *
+             ((params->mode == V4L2_TUNER_RADIO) ? 1 : 1000) / 2;
 
       priv->mode = TDA18271_ANALOG;
 
       if (params->mode == V4L2_TUNER_RADIO) {
-             freq = freq / 1000;
               map = &std_map->fm_radio;
               mode = "fm";
       } else if (params->std & V4L2_STD_MN) {
Quoted 8 lines
Quoted 3 lines

Cheers,

Mike

Much better!

Btw. It seems that the tuner is capable of tuning in 1000 Hz steps, is there a reason why we are using 62500 Hz steps?

That's the v4l2 analog tuner API. It has nothing to do with the tda18271 driver internals. If you look on the digital set_params function, you'll see that this doesnt happen there.

-Mike