Thanks Manu - I have made the appropriate changes. The original code was GPLd but I have contacted the original Author - Jack Kelliher who has agreed to allow the code to to be LGPLd with the dvb_core library. The comments in dvb_math.c reflect that as well. Let me know if I missed anything with this patch. Rusty
# HG changeset patch # User Rusty Scott <rustys@xxxxxxxx> # Node ID 2f6ec34ab313bebc2a4613428ef28cf710b8fbda # Parent 0a8f56ab07faecab6afb1afa1dbf28f15b4381d0 Create dvb_math.c in dvb_core From: Rusty Scott <rustys@xxxxxxxx> Moved some common logrithm code from or51211 and or51132 frontends into a dvb_math file which is linked into the dvb_core module Signed-off-by: Rusty Scott <rustys@xxxxxxxx> diff -r 0a8f56ab07fa -r 2f6ec34ab313 linux/drivers/media/dvb/dvb-core/Makefile --- a/linux/drivers/media/dvb/dvb-core/Makefile Mon Apr 17 16:44:02 2006 -0300 +++ b/linux/drivers/media/dvb/dvb-core/Makefile Tue Apr 18 23:32:27 2006 -0600 @@ -4,6 +4,6 @@ dvb-core-objs = dvbdev.o dmxdev.o dvb_demux.o dvb_filter.o \ dvb_ca_en50221.o dvb_frontend.o \ - dvb_net.o dvb_ringbuffer.o + dvb_net.o dvb_ringbuffer.o dvb_math.o obj-$(CONFIG_DVB_CORE) += dvb-core.o diff -r 0a8f56ab07fa -r 2f6ec34ab313 linux/drivers/media/dvb/frontends/or51132.c --- a/linux/drivers/media/dvb/frontends/or51132.c Mon Apr 17 16:44:02 2006 -0300 +++ b/linux/drivers/media/dvb/frontends/or51132.c Tue Apr 18 23:32:27 2006 -0600 @@ -43,6 +43,7 @@ #include "dvb_frontend.h" #include "dvb-pll.h" #include "or51132.h" +#include "dvb_math.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 0a8f56ab07fa -r 2f6ec34ab313 linux/drivers/media/dvb/frontends/or51211.c --- a/linux/drivers/media/dvb/frontends/or51211.c Mon Apr 17 16:44:02 2006 -0300 +++ b/linux/drivers/media/dvb/frontends/or51211.c Tue Apr 18 23:32:27 2006 -0600 @@ -41,6 +41,7 @@ #include "dvb_frontend.h" #include "or51211.h" +#include "dvb_math.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 0a8f56ab07fa -r 2f6ec34ab313 linux/drivers/media/dvb/dvb-core/dvb_math.c --- /dev/null Thu Jan 1 00:00:00 1970 +0000 +++ b/linux/drivers/media/dvb/dvb-core/dvb_math.c Tue Apr 18 23:32:27 2006 -0600 @@ -0,0 +1,108 @@ +/* + * dvb_math.c - Integer math functions suitable for DVB driver use + * + * 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 was published under the GNU GPL. + * + * Permission has been granted by the original copyright holder to + * distribute this code in the dvb_core library under the GNU Lesser + * General Public license which is hereafter referenced: + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * 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 "dvb_math.h" + +/* 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; + return rntval; +} +EXPORT_SYMBOL(i10Log10); + +unsigned int i20Log10(u32 val) +{ + return 2*i10Log10(val); +} +EXPORT_SYMBOL(i20Log10); + +/* + * Local variables: + * c-basic-offset: 8 + * End: + */ diff -r 0a8f56ab07fa -r 2f6ec34ab313 linux/drivers/media/dvb/dvb-core/dvb_math.h --- /dev/null Thu Jan 1 00:00:00 1970 +0000 +++ b/linux/drivers/media/dvb/dvb-core/dvb_math.h Tue Apr 18 23:32:27 2006 -0600 @@ -0,0 +1,48 @@ +/* + * dvb_math.h - Integer math functions suitable for DVB driver use + * + * 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 was published under the GNU GPL. + * + * Permission has been granted by the original copyright holder to + * distribute this code in the dvb_core library under the GNU Lesser + * General Public license which is hereafter referenced: + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + */ + +#ifndef _DVB_MATH_H_ +#define _DVB_MATH_H_ + +extern unsigned int i10Log10(u32 val); +extern unsigned int i20Log10(u32 val); + +#endif /* _DVB_MATH_H_ */ + +/* + * Local variables: + * c-basic-offset: 8 + * End: + */
_______________________________________________ linux-dvb@xxxxxxxxxxx http://www.linuxtv.org/cgi-bin/mailman/listinfo/linux-dvb