Subject: port-i386/35796: it(4) for ASUS M2NPV-VM motherboard
To: None <port-i386-maintainer@netbsd.org, gnats-admin@netbsd.org,>
From: None <fukumoto@mtiichi11.ns.itscom.net>
List: netbsd-bugs
Date: 02/22/2007 22:35:00
>Number:         35796
>Category:       port-i386
>Synopsis:       it(4) for ASUS M2NPV-VM motherboard
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    port-i386-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Feb 22 22:35:00 +0000 2007
>Originator:     fukumoto@imasy.or.jp
>Release:        NetBSD 4.0_BETA2
>Organization:
>Environment:
System: NetBSD kestrel 4.0_BETA2 NetBSD 4.0_BETA2 (Kestrel) #7: Fri Feb 23 03:55:54 JST 2007 fukumoto@kestrel:/usr/src/sys/arch/i386/compile/Kestrel i386
Architecture: i386
Machine: i386
>Description:
ASUS M2NPV-VM motherboard came with IT8716F super-I/O chip.
I tried NetBSD's it(4) driver but the readings were off.
With the following patch, the fan RPM readings seems corrected, but
the voltage values are still off a little (lower than BIOS menu value).
I had to change 3.3V sensor to VIN1 line by adding 
"options IT_SENSORV33=IT_VIN1" in config.


						FUKUMOTO Atsushi
						fukumoto@imasy.or.jp


Index: dev/isa/files.isa
===================================================================
RCS file: /cvsroot/src/sys/dev/isa/files.isa,v
retrieving revision 1.144.12.1
diff -u -r1.144.12.1 files.isa
--- dev/isa/files.isa	12 Jan 2007 23:13:21 -0000	1.144.12.1
+++ dev/isa/files.isa	22 Feb 2007 20:28:31 -0000
@@ -468,6 +468,7 @@
 device	it: sysmon_envsys
 attach	it at isa with it_isa
 file	dev/isa/it.c			it_isa
+defparam opt_it.h IT_SENSORV33
 
 # Abit uGuru hardware monitor
 device ug: sysmon_envsys
Index: dev/isa/it.c
===================================================================
RCS file: /cvsroot/src/sys/dev/isa/it.c,v
retrieving revision 1.6.2.1
diff -u -r1.6.2.1 it.c
--- dev/isa/it.c	9 Jan 2007 14:38:56 -0000	1.6.2.1
+++ dev/isa/it.c	22 Feb 2007 20:28:31 -0000
@@ -34,6 +34,8 @@
 #include <sys/cdefs.h>
 __KERNEL_RCSID(0, "$NetBSD: it.c,v 1.6.2.1 2007/01/09 14:38:56 tron Exp $");
 
+#include "opt_it.h"
+
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/kernel.h>
@@ -155,6 +157,7 @@
 	}
 
 	idr = it_readreg(sc, IT_COREID);
+	sc->id = idr;
 	if (idr == IT_REV_8712)
 		aprint_normal(": IT8712F Hardware monitor\n");
 	else {
@@ -312,27 +315,44 @@
 static void
 it_refresh_fans(struct it_softc *sc)
 {
+	int mode;
 	int i, sdata, divisor, odivisor, ndivisor;
 
-	odivisor = ndivisor = divisor = it_readreg(sc, IT_FAN);
-	for (i = 0; i < 2; i++, divisor >>= 3) {
-		if ((sdata = it_readreg(sc, IT_SENSORFANBASE + i)) == 0xff) {
-			if (i == 2)
-				ndivisor ^= 0x40;
-			else {
-				ndivisor &= ~(7 << (i * 3));
-				ndivisor |= ((divisor + 1) & 7) << (i * 3);
+	mode = it_readreg(sc, IT_FAN16);
+	if (sc->id == IT_REV_8705) {
+		odivisor = ndivisor = divisor = it_readreg(sc, IT_FAN);
+		for (i = 0; i < 2; i++, divisor >>= 3) {
+			sdata = it_readreg(sc, IT_SENSORFANBASE + i);
+			if (mode & (1 << i))
+				sdata += (it_readreg(sc, IT_SENSORFANEXTBASE + i) << 8);
+			if (!(mode & (1 << i)) && sdata == 0xff) {
+				if (i == 2)
+					ndivisor |= 0x40;
+				else if ((divisor & 7) != 7) {
+					ndivisor &= ~(7 << (i * 3));
+					ndivisor |= ((divisor + 1) & 7) << (i * 3);
+				}
+			} else {
+				if (i == 2)
+					divisor = divisor & 1 ? 3 : 1;
+				sc->sc_data[7 + i].cur.data_us =
+				    1350000 / (sdata << (divisor & 7));
 			}
-		} else {
-			if (i == 2)
-				divisor = divisor & 1 ? 3 : 1;
+			DPRINTF(("sdata[fan%d] 0x%x div: 0x%x\n", i, sdata, divisor));
+		}
+		if (ndivisor != odivisor)
+			it_writereg(sc, IT_FAN, ndivisor);
+	} else {
+		/* IT8712F, IT8716F */
+		for (i = 0; i < 2; i++) {
+			sdata = it_readreg(sc, IT_SENSORFANBASE + i);
+			if (mode & (1 << i)) /* 16-bit mode enabled */
+				sdata += (it_readreg(sc, IT_SENSORFANEXTBASE + i) << 8);
 			sc->sc_data[7 + i].cur.data_us =
-			    1350000 / (sdata << (divisor & 7));
+			    1350000 / 2 / sdata;
+			DPRINTF(("sdata[fan%d] 0x%x\n", i, sdata));
 		}
-		DPRINTF(("sdata[fan%d] 0x%x div: 0x%x\n", i, sdata, divisor));
 	}
-	if (ndivisor != odivisor)
-		it_writereg(sc, IT_FAN, ndivisor);
 }
 
 static int              
Index: dev/isa/itvar.h
===================================================================
RCS file: /cvsroot/src/sys/dev/isa/itvar.h,v
retrieving revision 1.2.14.1
diff -u -r1.2.14.1 itvar.h
--- dev/isa/itvar.h	9 Jan 2007 14:38:56 -0000	1.2.14.1
+++ dev/isa/itvar.h	22 Feb 2007 20:28:31 -0000
@@ -55,6 +55,7 @@
 #define IT_IMR3 	0x09
 #define IT_VID 		0x0a
 #define IT_FAN 		0x0b
+#define	IT_FAN16	0x0c
 
 #define IT_VOLTENABLE 	0x50
 #define IT_TEMPENABLE 	0x51
@@ -63,13 +64,25 @@
 #define IT_FANENABLE	0x13
 
 #define IT_SENSORFANBASE	0x0d	/* Fan from 0x0d to 0x0f */
-#define IT_SENSORVOLTBASE	0x20	/* Fan from 0x20 to 0x28 */
-#define IT_SENSORTEMPBASE	0x29	/* Fan from 0x29 to 0x2b */
-
-#define IT_SENSORVCORE0		0x20
-#define IT_SENSORV33		0x22
-#define IT_SENSORV5		0x23
-#define IT_SENSORV12		0x24
+#define	IT_SENSORFANEXTBASE	0x18	/* Fan (MSB) from 0x18 to 0x1A */
+#define IT_SENSORVOLTBASE	0x20	/* Voltage from 0x20 to 0x28 */
+#define IT_SENSORTEMPBASE	0x29	/* Temperature from 0x29 to 0x2b */
+
+#define	IT_VIN0			0x20
+#define	IT_VIN1			0x21
+#define	IT_VIN2			0x22
+#define	IT_VIN3			0x23
+#define	IT_VIN4			0x24
+#define	IT_VIN5			0x25
+#define	IT_VIN6			0x26
+#define	IT_VIN7			0x27
+
+#define IT_SENSORVCORE0		IT_VIN0
+#ifndef IT_SENSORV33
+# define IT_SENSORV33		IT_VIN2
+#endif
+#define IT_SENSORV5		IT_VIN3
+#define IT_SENSORV12		IT_VIN4
 #define IT_SENSORVBAT		0x28
 
 #define IT_VOLTMAXBASE		0x30
@@ -105,6 +118,8 @@
 	struct sysmon_envsys sc_sysmon;
 	envsys_tre_data_t sc_data[IT_NUM_SENSORS];
 	envsys_basic_info_t sc_info[IT_NUM_SENSORS];
+
+	uint8_t	id;
 };
 
 #endif /* _DEV_ISA_ITVAR_H_ */
>How-To-Repeat:
	
>Fix: