diff mbox

stv6110x: fix r divider calculation

Message ID 4AEF3FB5.9080001@gmx.de (mailing list archive)
State Accepted
Headers show

Commit Message

Andreas Regel Nov. 2, 2009, 8:23 p.m. UTC
None
diff mbox

Patch

diff -r 43878f8dbfb0 linux/drivers/media/dvb/frontends/stv6110x.c
--- a/linux/drivers/media/dvb/frontends/stv6110x.c	Sun Nov 01 07:17:46 2009 -0200
+++ b/linux/drivers/media/dvb/frontends/stv6110x.c	Mon Nov 02 21:02:22 2009 +0100
@@ -95,7 +95,7 @@ 
 {
 	struct stv6110x_state *stv6110x = fe->tuner_priv;
 	u32 rDiv, divider;
-	s32 pVal, pCalc, rDivOpt = 0;
+	s32 pVal, pCalc, rDivOpt = 0, pCalcOpt = 1000;
 	u8 i;
 
 	STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL1], CTRL1_K, (REFCLOCK_MHz - 16));
@@ -121,8 +121,10 @@ 
 	for (rDiv = 0; rDiv <= 3; rDiv++) {
 		pCalc = (REFCLOCK_kHz / 100) / R_DIV(rDiv);
 
-		if ((abs((s32)(pCalc - pVal))) < (abs((s32)(1000 - pVal))))
+		if ((abs((s32)(pCalc - pVal))) < (abs((s32)(pCalcOpt - pVal))))
 			rDivOpt = rDiv;
+
+		pCalcOpt = (REFCLOCK_kHz / 100) / R_DIV(rDivOpt);
 	}
 
 	divider = (frequency * R_DIV(rDivOpt) * pVal) / REFCLOCK_kHz;