# HG changeset patch
# User moel.mich
# Date 1267561944 0
# Node ID d706e16a79c03af0c9368922f825db18eb5320d1
# Parent  bb5696abab23ae4257c195720239cc0fc49c84a6
Added support for Fintek F71858 chips. Corrected the number of fans for Fintek.

diff -r bb5696abab23 -r d706e16a79c0 Hardware/LPC/Chip.cs
--- a/Hardware/LPC/Chip.cs	Mon Mar 01 22:12:29 2010 +0000
+++ b/Hardware/LPC/Chip.cs	Tue Mar 02 20:32:24 2010 +0000
@@ -19,6 +19,7 @@
     W83667HG = 0xA510,
     W83667HGB = 0xB350,
     W83687THF = 0x8541,
+    F71858 = 0x0507,
     F71862 = 0x0601, 
     F71869 = 0x0814,
     F71882 = 0x0541,
diff -r bb5696abab23 -r d706e16a79c0 Hardware/LPC/F718XX.cs
--- a/Hardware/LPC/F718XX.cs	Mon Mar 01 22:12:29 2010 +0000
+++ b/Hardware/LPC/F718XX.cs	Tue Mar 02 20:32:24 2010 +0000
@@ -56,7 +56,8 @@
 
     // Hardware Monitor Registers
     private const byte VOLTAGE_BASE_REG = 0x20;
-    private const byte TEMPERATURE_BASE_REG = 0x72;
+    private const byte TEMPERATURE_CONFIG_REG = 0x69;
+    private const byte TEMPERATURE_BASE_REG = 0x70;
     private byte[] FAN_TACHOMETER_REG = new byte[] { 0xA0, 0xB0, 0xC0, 0xD0 };
     
     private byte ReadByte(byte register) {
@@ -75,16 +76,27 @@
             new ParameterDescription("Offset", "Temperature offset.", 0)
           });
 
-      fans = new Sensor[4];
+      fans = new Sensor[chip == Chip.F71882 ? 4 : 3];
       for (int i = 0; i < fans.Length; i++)
         fans[i] = new Sensor("Fan #" + (i + 1), i, SensorType.Fan, this);
 
-      voltageGains = new float[] { 1, 0.5f, 1, 1, 1, 1, 1, 1, 1 };
-      voltages = new Sensor[4];
-      voltages[0] = new Sensor("VCC3V", 0, SensorType.Voltage, this);
-      voltages[1] = new Sensor("CPU VCore", 1, SensorType.Voltage, this);      
-      voltages[2] = new Sensor("VSB3V", 7, SensorType.Voltage, this);
-      voltages[3] = new Sensor("Battery", 8, SensorType.Voltage, this);
+      switch (chip) {
+        case Chip.F71858:
+          voltageGains = new float[] { 1, 1, 1 };
+          voltages = new Sensor[3];
+          voltages[0] = new Sensor("VCC3V", 0, SensorType.Voltage, this);
+          voltages[1] = new Sensor("VSB3V", 1, SensorType.Voltage, this);
+          voltages[2] = new Sensor("Battery", 2, SensorType.Voltage, this);
+          break;
+        default:
+          voltageGains = new float[] { 1, 0.5f, 1, 1, 1, 1, 1, 1, 1 };
+          voltages = new Sensor[4];
+          voltages[0] = new Sensor("VCC3V", 0, SensorType.Voltage, this);
+          voltages[1] = new Sensor("CPU VCore", 1, SensorType.Voltage, this);
+          voltages[2] = new Sensor("VSB3V", 7, SensorType.Voltage, this);
+          voltages[3] = new Sensor("Battery", 8, SensorType.Voltage, this);
+          break;
+      }
     }
 
     public string GetReport() {
@@ -121,15 +133,42 @@
         else
           DeactivateSensor(sensor);
       }
-
+     
       foreach (Sensor sensor in temperatures) {
-        sbyte value = (sbyte)ReadByte((byte)(
-          TEMPERATURE_BASE_REG + 2 * sensor.Index));
-        sensor.Value = value + sensor.Parameters[0].Value;
-        if (value < sbyte.MaxValue && value > 0)
-          ActivateSensor(sensor);
-        else
-          DeactivateSensor(sensor);
+        switch (chip) {
+          case Chip.F71858: {
+              int tableMode = 0x3 & ReadByte((byte)(TEMPERATURE_CONFIG_REG));
+              int high = 
+                ReadByte((byte)(TEMPERATURE_BASE_REG + 2 * sensor.Index));
+              int low =
+                ReadByte((byte)(TEMPERATURE_BASE_REG + 2 * sensor.Index + 1));              
+              if (high != 0xbb && high != 0xcc) {
+                int bits = 0;
+                switch (tableMode) {
+                  case 0: bits = 0; break;
+                  case 1: bits = 0; break;
+                  case 2: bits = (high & 0x80) << 8; break;
+                  case 3: bits = (low & 0x01) << 15; break;
+                }
+                bits |= high << 7;
+                bits |= (low & 0xe0) >> 1;
+                short value = (short)(bits & 0xfff0);
+                sensor.Value = value / 128.0f;
+                ActivateSensor(sensor);
+              } else {
+                DeactivateSensor(sensor);
+              }
+          } break;
+          default: {
+            sbyte value = (sbyte)ReadByte((byte)(
+              TEMPERATURE_BASE_REG + 2 * (sensor.Index + 1)));
+            sensor.Value = value + sensor.Parameters[0].Value;
+            if (value < sbyte.MaxValue && value > 0)
+              ActivateSensor(sensor);
+            else
+              DeactivateSensor(sensor);
+          } break;
+        }
       }
 
       foreach (Sensor sensor in fans) {
diff -r bb5696abab23 -r d706e16a79c0 Hardware/LPC/LPCGroup.cs
--- a/Hardware/LPC/LPCGroup.cs	Mon Mar 01 22:12:29 2010 +0000
+++ b/Hardware/LPC/LPCGroup.cs	Tue Mar 02 20:32:24 2010 +0000
@@ -137,6 +137,10 @@
         switch (id) {
           case 0x05:
             switch (revision) {
+              case 0x07:
+                chip = Chip.F71858;
+                logicalDeviceNumber = F71858_HARDWARE_MONITOR_LDN;
+                break;
               case 0x41:
                 chip = Chip.F71882;
                 logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
@@ -235,9 +239,10 @@
           ushort address = ReadWord(BASE_ADDRESS_REGISTER);          
           Thread.Sleep(1);
           ushort verify = ReadWord(BASE_ADDRESS_REGISTER);
-          
-          ushort vendorID = 0;
-          if (chip == Chip.F71862 || chip == Chip.F71882 || chip == Chip.F71889)
+
+          ushort vendorID = FINTEK_VENDOR_ID;
+          if (chip == Chip.F71858 || chip == Chip.F71862 || 
+            chip == Chip.F71882 || chip == Chip.F71889)
             vendorID = ReadWord(FINTEK_VENDOR_ID_REGISTER);
 
           WinbondFintekExit();
@@ -280,12 +285,10 @@
               if (w836XX.IsAvailable)
                 hardware.Add(w836XX);
               break;
+            case Chip.F71858:
             case Chip.F71862:
             case Chip.F71882:
             case Chip.F71889: 
-              if (vendorID == FINTEK_VENDOR_ID)
-                hardware.Add(new F718XX(chip, address));
-              break;
             case Chip.F71869:
               hardware.Add(new F718XX(chip, address));
               break;
diff -r bb5696abab23 -r d706e16a79c0 Hardware/LPC/LPCHardware.cs
--- a/Hardware/LPC/LPCHardware.cs	Mon Mar 01 22:12:29 2010 +0000
+++ b/Hardware/LPC/LPCHardware.cs	Tue Mar 02 20:32:24 2010 +0000
@@ -51,6 +51,7 @@
       this.icon = Utilities.EmbeddedResources.GetImage("chip.png");
 
       switch (chip) {
+        case Chip.F71858: name = "Fintek F71858"; break;
         case Chip.F71862: name = "Fintek F71862"; break;
         case Chip.F71869: name = "Fintek F71869"; break;
         case Chip.F71882: name = "Fintek F71882"; break;