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

RPM calculation fix for it(4) driver



this diff (by form_(_at_)_pdp-11_(_dot_)_org_(_dot_)_ru) fixes some problems in RPM values
calculation in the it(4) driver. if you use this driver and notice some
strange RPM values please try it and mail me the results. if you're
satisfied with the current driver please try this diff as well to check
for any regressions.

thanks.

-- 
   Alexander Yurchenko (aka grange)

Index: dev/isa/it.c
===================================================================
RCS file: /cvs/src/sys/dev/isa/it.c,v
retrieving revision 1.14
diff -d -u -r1.14 it.c
--- dev/isa/it.c	2005/04/29 17:13:54	1.14
+++ dev/isa/it.c	2005/06/29 16:57:37
@@ -283,31 +283,29 @@
 void
 it_generic_fanrpm(struct it_softc *sc, struct sensor *sensors)
 {
-	int i, sdata, divisor;
-
-	divisor = it_readreg(sc, ITD_FAN);
-	for (i = 0; i < 3; i++) {
-		sdata = it_readreg(sc, ITD_SENSORFANBASE + i);
-		switch (i) {
-			case 2:
-				divisor = (divisor & 0x40) ? 3 : 1;
-				break;
-			case 1:
-				divisor = (divisor >> 3) & 0x7;
-				break;
-			case 0:
-				divisor = divisor & 0x7;
-				break;
-		}
+	int i, sdata, divisor, odivisor, ndivisor;
 
-		if (sdata == 0xff) {
+	odivisor = ndivisor = divisor = it_readreg(sc, ITD_FAN);
+	for (i = 0; i < 3; i++, divisor >>= 3) {
+		sensors[i].flags &= ~SENSOR_FINVALID;
+		if ((sdata = it_readreg(sc, ITD_SENSORFANBASE + i)) == 0xff) {
 			sensors[i].flags |= SENSOR_FINVALID;
+			if (i == 2)
+				ndivisor ^= 0x40;
+			else {
+				ndivisor &= ~(7 << (i * 3));
+				ndivisor |= ((divisor + 1) & 7) << (i * 3);
+			}
 		} else if (sdata == 0) {
 			sensors[i].value = 0;
 		} else {
-			sensors[i].value = 1350000 / (sdata << divisor);
+			if (i == 2)
+				divisor = divisor & 1 ? 3 : 1;
+			sensors[i].value = 1350000 / (sdata << (divisor & 7));
 		}
 	}
+	if (ndivisor != odivisor)
+		it_writereg(sc, ITD_FAN, ndivisor);
 }
 
 /*