1 From a57c1dcb93e43357ed3f666e5a2b5d5071dd3930 Mon Sep 17 00:00:00 2001
2 From: Seth Barry <seth@cyberseth.com>
3 Date: Sun, 27 Sep 2009 16:42:29 -0300
4 Subject: V4L/DVB (13109): tda18271: fix signedness issue in tda18271_rf_tracking_filters_init
6 From: Seth Barry <seth@cyberseth.com>
8 commit a57c1dcb93e43357ed3f666e5a2b5d5071dd3930 upstream.
10 While having tda18271 module set with debug=17 (cal & info prints) and
11 cal=0 (delay calibration process until first use) - I discovered that
12 during the calibration process, if the frequency test for 69750000
13 returned a bcal of 0 (see tda18721-fe.c in tda18271_powerscan func) that
14 the tuner wouldn't be able to pickup any of the frequencies in the range
15 (all the other frequencies bands returned bcal=1). I spent some time
16 going over the code and the NXP's tda18271 spec (ver.4 of it i think) and
17 adding a lot of debug prints and walking/stepping through the calibration
18 process. I found that when the powerscan fails to find a frequency, the
19 rf calibration is not run and the default value is supposed to be used in
20 its place (pulled from the RF_CAL_map table) - but something was getting
23 Now, my c coding skills are very rusty, but i think root of the problem is
24 a signedness issue with the math operation for calculating the rf_a1 and
25 rf_a2 values in tda18271_rf_tracking_filters_init func, which results in
26 values like 20648 for rf_a1 (when it should probably have a value like 0,
27 or so slightly negative that it should be zero - this bad value for rf_a1
28 would in turn makes the approx calc within
29 tda18271c2_rf_tracking_filters_correction go out of whack). The simplest
30 solution i found was to explicitly convert the signedness of the
31 denominator to avoid the implicit conversion. The values placed into the
32 u32 rf_freq array should never exceed about 900mhz, so i think the s32 max
33 value shouldn't be an issue in this case.
35 I've tested it out a little, and even when i get a bcal=0 with the
36 modified code, the default calibration value gets used, rf_a1 is zero, and
37 the tuner seems to lock on the stream and mythtv seems to play it fine.
39 Signed-off-by: Seth Barry <seth@cyberseth.com>
40 Signed-off-by: Michael Krufky <mkrufky@kernellabs.com>
41 Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
42 Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
45 drivers/media/common/tuners/tda18271-fe.c | 4 ++--
46 1 file changed, 2 insertions(+), 2 deletions(-)
48 --- a/drivers/media/common/tuners/tda18271-fe.c
49 +++ b/drivers/media/common/tuners/tda18271-fe.c
50 @@ -595,13 +595,13 @@ static int tda18271_rf_tracking_filters_
52 map[i].rf_a1 = (prog_cal[RF2] - prog_tab[RF2] -
53 prog_cal[RF1] + prog_tab[RF1]) /
54 - ((rf_freq[RF2] - rf_freq[RF1]) / 1000);
55 + (s32)((rf_freq[RF2] - rf_freq[RF1]) / 1000);
56 map[i].rf2 = rf_freq[RF2] / 1000;
59 map[i].rf_a2 = (prog_cal[RF3] - prog_tab[RF3] -
60 prog_cal[RF2] + prog_tab[RF2]) /
61 - ((rf_freq[RF3] - rf_freq[RF2]) / 1000);
62 + (s32)((rf_freq[RF3] - rf_freq[RF2]) / 1000);
63 map[i].rf_b2 = prog_cal[RF2] - prog_tab[RF2];
64 map[i].rf3 = rf_freq[RF3] / 1000;