[PATCH]Frontends or51132, or51211 move common code to module

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




The attached patch moves the common logarithm code found in the or51211 and or
51132 frontends into a module that can be accessed by other frontends as well.
This patch is in anticipation of using the logarithm code in the lgdt330x module
to calculate a signal strength which is currently not done.

Rusty
# HG changeset patch
# User Rusty Scott <rustys@xxxxxxxx>
# Node ID 319445f861a083ffdc310cde4e6642595791f11f
# Parent  436e56df57d3d5fe2f073129eb894bf452b9375b
Moved duplicated code to common module

From: Rusty Scott <rustys@xxxxxxxx>

Moved code which was duplicated in or51211 and or51132 modules into a single
module that is shared in common.  This code can now be accessed by other 
modules as well.
Fix algorithmic problems in log function

Signed-off-by: Rusty Scott <rustys@xxxxxxxx>

diff -r 436e56df57d3 -r 319445f861a0 linux/drivers/media/dvb/frontends/Makefile
--- a/linux/drivers/media/dvb/frontends/Makefile	Thu Apr 13 18:50:22 2006 -0300
+++ b/linux/drivers/media/dvb/frontends/Makefile	Thu Apr 13 21:59:51 2006 -0600
@@ -5,6 +5,7 @@ EXTRA_CFLAGS = -Idrivers/media/dvb/dvb-c
 EXTRA_CFLAGS = -Idrivers/media/dvb/dvb-core/
 
 obj-$(CONFIG_DVB_CORE) += dvb-pll.o
+obj-$(CONFIG_DVB_CORE) += ilog10.o
 obj-$(CONFIG_DVB_STV0299) += stv0299.o
 obj-$(CONFIG_DVB_SP8870) += sp8870.o
 obj-$(CONFIG_DVB_CX22700) += cx22700.o
diff -r 436e56df57d3 -r 319445f861a0 linux/drivers/media/dvb/frontends/or51132.c
--- a/linux/drivers/media/dvb/frontends/or51132.c	Thu Apr 13 18:50:22 2006 -0300
+++ b/linux/drivers/media/dvb/frontends/or51132.c	Thu Apr 13 21:59:51 2006 -0600
@@ -43,6 +43,7 @@
 #include "dvb_frontend.h"
 #include "dvb-pll.h"
 #include "or51132.h"
+#include "ilog10.h"
 
 static int debug;
 #define dprintk(args...) \
@@ -470,47 +471,6 @@ static int or51132_read_status(struct dv
 	return 0;
 }
 
-/* log10-1 table at .5 increments from 1 to 100.5 */
-static unsigned int i100x20log10[] = {
-     0,  352,  602,  795,  954, 1088, 1204, 1306, 1397, 1480,
-  1556, 1625, 1690, 1750, 1806, 1858, 1908, 1955, 2000, 2042,
-  2082, 2121, 2158, 2193, 2227, 2260, 2292, 2322, 2352, 2380,
-  2408, 2434, 2460, 2486, 2510, 2534, 2557, 2580, 2602, 2623,
-  2644, 2664, 2684, 2704, 2723, 2742, 2760, 2778, 2795, 2813,
-  2829, 2846, 2862, 2878, 2894, 2909, 2924, 2939, 2954, 2968,
-  2982, 2996, 3010, 3023, 3037, 3050, 3062, 3075, 3088, 3100,
-  3112, 3124, 3136, 3148, 3159, 3170, 3182, 3193, 3204, 3214,
-  3225, 3236, 3246, 3256, 3266, 3276, 3286, 3296, 3306, 3316,
-  3325, 3334, 3344, 3353, 3362, 3371, 3380, 3389, 3397, 3406,
-  3415, 3423, 3432, 3440, 3448, 3456, 3464, 3472, 3480, 3488,
-  3496, 3504, 3511, 3519, 3526, 3534, 3541, 3549, 3556, 3563,
-  3570, 3577, 3584, 3591, 3598, 3605, 3612, 3619, 3625, 3632,
-  3639, 3645, 3652, 3658, 3665, 3671, 3677, 3683, 3690, 3696,
-  3702, 3708, 3714, 3720, 3726, 3732, 3738, 3744, 3750, 3755,
-  3761, 3767, 3772, 3778, 3784, 3789, 3795, 3800, 3806, 3811,
-  3816, 3822, 3827, 3832, 3838, 3843, 3848, 3853, 3858, 3863,
-  3868, 3874, 3879, 3884, 3888, 3893, 3898, 3903, 3908, 3913,
-  3918, 3922, 3927, 3932, 3936, 3941, 3946, 3950, 3955, 3960,
-  3964, 3969, 3973, 3978, 3982, 3986, 3991, 3995, 4000, 4004,
-};
-
-static unsigned int denom[] = {1,1,100,1000,10000,100000,1000000,10000000,100000000};
-
-static unsigned int i20Log10(unsigned short val)
-{
-	unsigned int rntval = 100;
-	unsigned int tmp = val;
-	unsigned int exp = 1;
-
-	while(tmp > 100) {tmp /= 100; exp++;}
-
-	val = (2 * val)/denom[exp];
-	if (exp > 1) rntval = 2000*exp;
-
-	rntval += i100x20log10[val];
-	return rntval;
-}
-
 static int or51132_read_signal_strength(struct dvb_frontend* fe, u16* strength)
 {
 	struct or51132_state* state = fe->demodulator_priv;
diff -r 436e56df57d3 -r 319445f861a0 linux/drivers/media/dvb/frontends/or51211.c
--- a/linux/drivers/media/dvb/frontends/or51211.c	Thu Apr 13 18:50:22 2006 -0300
+++ b/linux/drivers/media/dvb/frontends/or51211.c	Thu Apr 13 21:59:51 2006 -0600
@@ -41,6 +41,7 @@
 
 #include "dvb_frontend.h"
 #include "or51211.h"
+#include "ilog10.h"
 
 static int debug;
 #define dprintk(args...) \
@@ -291,47 +292,6 @@ static int or51211_read_status(struct dv
 		*status |= FE_HAS_LOCK;
 	}
 	return 0;
-}
-
-/* log10-1 table at .5 increments from 1 to 100.5 */
-static unsigned int i100x20log10[] = {
-		0,  352,  602,  795,  954, 1088, 1204, 1306, 1397, 1480,
-	 1556, 1625, 1690, 1750, 1806, 1858, 1908, 1955, 2000, 2042,
-	 2082, 2121, 2158, 2193, 2227, 2260, 2292, 2322, 2352, 2380,
-	 2408, 2434, 2460, 2486, 2510, 2534, 2557, 2580, 2602, 2623,
-	 2644, 2664, 2684, 2704, 2723, 2742, 2760, 2778, 2795, 2813,
-	 2829, 2846, 2862, 2878, 2894, 2909, 2924, 2939, 2954, 2968,
-	 2982, 2996, 3010, 3023, 3037, 3050, 3062, 3075, 3088, 3100,
-	 3112, 3124, 3136, 3148, 3159, 3170, 3182, 3193, 3204, 3214,
-	 3225, 3236, 3246, 3256, 3266, 3276, 3286, 3296, 3306, 3316,
-	 3325, 3334, 3344, 3353, 3362, 3371, 3380, 3389, 3397, 3406,
-	 3415, 3423, 3432, 3440, 3448, 3456, 3464, 3472, 3480, 3488,
-	 3496, 3504, 3511, 3519, 3526, 3534, 3541, 3549, 3556, 3563,
-	 3570, 3577, 3584, 3591, 3598, 3605, 3612, 3619, 3625, 3632,
-	 3639, 3645, 3652, 3658, 3665, 3671, 3677, 3683, 3690, 3696,
-	 3702, 3708, 3714, 3720, 3726, 3732, 3738, 3744, 3750, 3755,
-	 3761, 3767, 3772, 3778, 3784, 3789, 3795, 3800, 3806, 3811,
-	 3816, 3822, 3827, 3832, 3838, 3843, 3848, 3853, 3858, 3863,
-	 3868, 3874, 3879, 3884, 3888, 3893, 3898, 3903, 3908, 3913,
-	 3918, 3922, 3927, 3932, 3936, 3941, 3946, 3950, 3955, 3960,
-	 3964, 3969, 3973, 3978, 3982, 3986, 3991, 3995, 4000, 4004,
-};
-
-static unsigned int denom[] = {1,1,100,1000,10000,100000,1000000,10000000,100000000};
-
-static unsigned int i20Log10(unsigned short val)
-{
-	unsigned int rntval = 100;
-	unsigned int tmp = val;
-	unsigned int exp = 1;
-
-	while(tmp > 100) {tmp /= 100; exp++;}
-
-	val = (2 * val)/denom[exp];
-	if (exp > 1) rntval = 2000*exp;
-
-	rntval += i100x20log10[val];
-	return rntval;
 }
 
 static int or51211_read_signal_strength(struct dvb_frontend* fe, u16* strength)
diff -r 436e56df57d3 -r 319445f861a0 linux/drivers/media/dvb/frontends/ilog10.c
--- /dev/null	Thu Jan  1 00:00:00 1970 +0000
+++ b/linux/drivers/media/dvb/frontends/ilog10.c	Thu Apr 13 21:59:51 2006 -0600
@@ -0,0 +1,116 @@
+/*
+ *    Integer math logarithm (base 10) for calculating dB
+ *
+ *    Copyright (C) 2006 Rusty Scott <rustys@xxxxxxxx>
+ *
+ *    Taken from or51134 and or51211 front end modules which are
+ *    Copyright (C) 2005 Kirk Lapray <kirk_lapray@xxxxxxxxxxx>
+ *
+ *    which lifted the integer logarithm code, without modification, directly
+ *    from pcHDTV code which is
+ *    Copyright (C) 2002 pcHDTV,Inc. & Jack Kelliher <jkelliher@xxxxxxxxxxxx>
+ *
+ *    All of which is published under the GNU GPL which is hereafter cited:
+ *
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+/*
+ *    Notes:
+ *    There are several frontends in the DVB set that attempt to give a
+ *    real value for the SNR in dB.  This module pulls that code into a single
+ *    place for maintenance and fixes the algorithmic problems of the code
+ *    found in the OR51132 and 51211 frontends.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/string.h>
+#include <linux/slab.h>
+#include <asm/byteorder.h>
+
+#include "ilog10.h"
+
+static int debug = 0;
+module_param(debug, int, 0644);
+MODULE_PARM_DESC(debug,"Turn on/off logarithm debugging (default:off).");
+#define dprintk(args...) \
+do { \
+if (debug) printk(KERN_DEBUG "ilog10: " args); \
+} while (0)
+
+/* log10-1 table at .5 increments from 1 to 100.5 */
+static unsigned int i100x20log10[] = {0, 0,
+     0,  352,  602,  795,  954, 1088, 1204, 1306, 1397, 1480,
+  1556, 1625, 1690, 1750, 1806, 1858, 1908, 1955, 2000, 2042,
+  2082, 2121, 2158, 2193, 2227, 2260, 2292, 2322, 2352, 2380,
+  2408, 2434, 2460, 2486, 2510, 2534, 2557, 2580, 2602, 2623,
+  2644, 2664, 2684, 2704, 2723, 2742, 2760, 2778, 2795, 2813,
+  2829, 2846, 2862, 2878, 2894, 2909, 2924, 2939, 2954, 2968,
+  2982, 2996, 3010, 3023, 3037, 3050, 3062, 3075, 3088, 3100,
+  3112, 3124, 3136, 3148, 3159, 3170, 3182, 3193, 3204, 3214,
+  3225, 3236, 3246, 3256, 3266, 3276, 3286, 3296, 3306, 3316,
+  3325, 3334, 3344, 3353, 3362, 3371, 3380, 3389, 3397, 3406,
+  3415, 3423, 3432, 3440, 3448, 3456, 3464, 3472, 3480, 3488,
+  3496, 3504, 3511, 3519, 3526, 3534, 3541, 3549, 3556, 3563,
+  3570, 3577, 3584, 3591, 3598, 3605, 3612, 3619, 3625, 3632,
+  3639, 3645, 3652, 3658, 3665, 3671, 3677, 3683, 3690, 3696,
+  3702, 3708, 3714, 3720, 3726, 3732, 3738, 3744, 3750, 3755,
+  3761, 3767, 3772, 3778, 3784, 3789, 3795, 3800, 3806, 3811,
+  3816, 3822, 3827, 3832, 3838, 3843, 3848, 3853, 3858, 3863,
+  3868, 3874, 3879, 3884, 3888, 3893, 3898, 3903, 3908, 3913,
+  3918, 3922, 3927, 3932, 3936, 3941, 3946, 3950, 3955, 3960,
+  3964, 3969, 3973, 3978, 3982, 3986, 3991, 3995, 4000, 4004,
+};
+
+static unsigned int denom[] = {1,10,100,1000,10000,100000,1000000,10000000,100000000};
+
+unsigned int i10Log10(u32 val)
+{
+	unsigned int rntval = 0;
+	u32 tmp = val;
+	unsigned int exp = 0;
+
+	while(tmp > 100) {tmp /= 10; exp++;}
+
+	val = (2 * val)/denom[exp];
+	rntval = 1000*exp;
+
+	rntval += i100x20log10[val]/2;
+	dprintk("%s: exp=%d, val=%d\n",__FUNCTION__, exp, val);
+	return rntval;
+}
+EXPORT_SYMBOL(i10Log10);
+
+unsigned int i20Log10(u32 val)
+{
+	return 2*i10Log10(val);
+}
+EXPORT_SYMBOL(i20Log10);
+
+MODULE_DESCRIPTION("Integer based logarithm (base 10) for dB calculations");
+MODULE_AUTHOR("Rusty Scott");
+MODULE_LICENSE("GPL");
+
+/*
+ * Local variables:
+ * c-basic-offset: 8
+ * End:
+ */
diff -r 436e56df57d3 -r 319445f861a0 linux/drivers/media/dvb/frontends/ilog10.h
--- /dev/null	Thu Jan  1 00:00:00 1970 +0000
+++ b/linux/drivers/media/dvb/frontends/ilog10.h	Thu Apr 13 21:59:51 2006 -0600
@@ -0,0 +1,43 @@
+/*
+ *    Integer math logarithm (base 10) for calculating dB
+ *
+ *    Copyright (C) 2006 Rusty Scott <rustys@xxxxxxxx>
+ *
+ *    Taken from or51134 and or51211 front end modules which are
+ *    Copyright (C) 2005 Kirk Lapray <kirk_lapray@xxxxxxxxxxx>
+ *
+ *    which lifted the integer logarithm code, without modification, directly
+ *    from pcHDTV code which is
+ *    Copyright (C) 2002 pcHDTV,Inc. & Jack Kelliher <jkelliher@xxxxxxxxxxxx>
+ *
+ *    All of which is published under the GNU GPL which is hereafter cited:
+ *
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#ifndef ILOG10_H
+#define ILOG10_H
+
+extern unsigned int i10Log10(u32 val);
+extern unsigned int i20Log10(u32 val);
+
+#endif /* ILOG10_H */
+
+/*
+ * Local variables:
+ * c-basic-offset: 8
+ * End:
+ */
_______________________________________________

linux-dvb@xxxxxxxxxxx
http://www.linuxtv.org/cgi-bin/mailman/listinfo/linux-dvb

[Index of Archives]     [Linux Media]     [Video 4 Linux]     [Asterisk]     [Samba]     [Xorg]     [Xfree86]     [Linux USB]

  Powered by Linux