A small correction for AMD K8 (family 0Fh) core temperature reading, and fan reading on older revision of IT8712F chips. This should fix Issue 42 and Issue 194.
authormoel.mich
Sat, 16 Apr 2011 14:49:47 +0000
changeset 272037a2d66082f
parent 271 8635fa73eacc
child 273 2054d5dcb680
A small correction for AMD K8 (family 0Fh) core temperature reading, and fan reading on older revision of IT8712F chips. This should fix Issue 42 and Issue 194.
Hardware/CPU/AMD0FCPU.cs
Hardware/HexStringArray.cs
Hardware/LPC/IT87XX.cs
Properties/AssemblyVersion.cs
     1.1 --- a/Hardware/CPU/AMD0FCPU.cs	Sat Apr 16 13:19:13 2011 +0000
     1.2 +++ b/Hardware/CPU/AMD0FCPU.cs	Sat Apr 16 14:49:47 2011 +0000
     1.3 @@ -52,9 +52,9 @@
     1.4      private const byte MISCELLANEOUS_CONTROL_FUNCTION = 3;
     1.5      private const ushort MISCELLANEOUS_CONTROL_DEVICE_ID = 0x1103;
     1.6      private const uint THERMTRIP_STATUS_REGISTER = 0xE4;
     1.7 -    private const byte THERM_SENSE_CORE_SEL_CPU0 = 0x4;
     1.8 -    private const byte THERM_SENSE_CORE_SEL_CPU1 = 0x0;
     1.9 -
    1.10 +    
    1.11 +    private readonly byte thermSenseCoreSelCPU0;
    1.12 +    private readonly byte thermSenseCoreSelCPU1;
    1.13      private readonly uint miscellaneousControlAddress;
    1.14  
    1.15      public AMD0FCPU(int processorIndex, CPUID[][] cpuid, ISettings settings)
    1.16 @@ -67,6 +67,16 @@
    1.17        if (model >= 0x69 && model != 0xc1 && model != 0x6c && model != 0x7c) 
    1.18          offset += 21;
    1.19  
    1.20 +      if (model < 40) {
    1.21 +        // AMD Athlon 64 Processors
    1.22 +        thermSenseCoreSelCPU0 = 0x0;
    1.23 +        thermSenseCoreSelCPU1 = 0x4;
    1.24 +      } else {
    1.25 +        // AMD NPT Family 0Fh Revision F, G have the core selection swapped
    1.26 +        thermSenseCoreSelCPU0 = 0x4;
    1.27 +        thermSenseCoreSelCPU1 = 0x0;
    1.28 +      }
    1.29 +
    1.30        // check if processor supports a digital thermal sensor 
    1.31        if (cpuid[0][0].ExtData.GetLength(0) > 7 && 
    1.32          (cpuid[0][0].ExtData[7, 3] & 1) != 0) 
    1.33 @@ -122,7 +132,7 @@
    1.34          for (uint i = 0; i < coreTemperatures.Length; i++) {
    1.35            if (Ring0.WritePciConfig(
    1.36              miscellaneousControlAddress, THERMTRIP_STATUS_REGISTER,
    1.37 -            i > 0 ? THERM_SENSE_CORE_SEL_CPU1 : THERM_SENSE_CORE_SEL_CPU0)) {
    1.38 +            i > 0 ? thermSenseCoreSelCPU1 : thermSenseCoreSelCPU0)) {
    1.39              uint value;
    1.40              if (Ring0.ReadPciConfig(
    1.41                miscellaneousControlAddress, THERMTRIP_STATUS_REGISTER, 
     2.1 --- a/Hardware/HexStringArray.cs	Sat Apr 16 13:19:13 2011 +0000
     2.2 +++ b/Hardware/HexStringArray.cs	Sat Apr 16 14:49:47 2011 +0000
     2.3 @@ -48,7 +48,8 @@
     2.4        foreach (string line in lines) {
     2.5          string[] array = line.Split(new[] { ' ' }, 
     2.6            StringSplitOptions.RemoveEmptyEntries);
     2.7 -
     2.8 +        if (array.Length == 0)
     2.9 +          continue; 
    2.10          if (Convert.ToInt32(array[0], 16) == (address & 0xFFF0)) 
    2.11            return Convert.ToByte(array[(address & 0x0F) + 1], 16);
    2.12        }
     3.1 --- a/Hardware/LPC/IT87XX.cs	Sat Apr 16 13:19:13 2011 +0000
     3.2 +++ b/Hardware/LPC/IT87XX.cs	Sat Apr 16 14:49:47 2011 +0000
     3.3 @@ -56,6 +56,7 @@
     3.4      private readonly float?[] fans = new float?[0];
     3.5  
     3.6      private readonly float voltageGain;
     3.7 +    private readonly bool has16bitFanCounter;
     3.8     
     3.9      // Consts
    3.10      private const byte ITE_VENDOR_ID = 0x90;
    3.11 @@ -68,7 +69,7 @@
    3.12      private const byte CONFIGURATION_REGISTER = 0x00;
    3.13      private const byte TEMPERATURE_BASE_REG = 0x29;
    3.14      private const byte VENDOR_ID_REGISTER = 0x58;
    3.15 -    private const byte FAN_TACHOMETER_16_BIT_ENABLE_REGISTER = 0x0c;
    3.16 +    private const byte FAN_TACHOMETER_DIVISOR_REGISTER = 0x0B;
    3.17      private readonly byte[] FAN_TACHOMETER_REG = 
    3.18        new byte[] { 0x0d, 0x0e, 0x0f, 0x80, 0x82 };
    3.19      private readonly byte[] FAN_TACHOMETER_EXT_REG =
    3.20 @@ -85,8 +86,8 @@
    3.21      private bool WriteByte(byte register, byte value) {
    3.22        Ring0.WriteIoPort(addressReg, register);
    3.23        Ring0.WriteIoPort(dataReg, value);
    3.24 -      return register == Ring0.ReadIoPort(addressReg);
    3.25 -    }
    3.26 +      return register == Ring0.ReadIoPort(addressReg); 
    3.27 +    } 
    3.28  
    3.29      public byte? ReadGPIO(int index) {
    3.30        if (index >= gpioCount)
    3.31 @@ -103,7 +104,7 @@
    3.32      }
    3.33  
    3.34      public IT87XX(Chip chip, ushort address, ushort gpioAddress, byte version) {
    3.35 -      
    3.36 +
    3.37        this.address = address;
    3.38        this.chip = chip;
    3.39        this.version = version;
    3.40 @@ -131,7 +132,14 @@
    3.41        if (chip == Chip.IT8721F) {
    3.42          voltageGain = 0.012f;
    3.43        } else {
    3.44 -        voltageGain = 0.016f;
    3.45 +        voltageGain = 0.016f;        
    3.46 +      }
    3.47 +
    3.48 +      // older IT8721F revision do not have 16-bit fan counters
    3.49 +      if (chip == Chip.IT8712F && version < 8) {
    3.50 +        has16bitFanCounter = false;
    3.51 +      } else {
    3.52 +        has16bitFanCounter = true;
    3.53        }
    3.54  
    3.55        // Set the number of GPIO sets
    3.56 @@ -236,19 +244,42 @@
    3.57            temperatures[i] = null;       
    3.58        }
    3.59  
    3.60 -      for (int i = 0; i < fans.Length; i++) {
    3.61 -        bool valid;
    3.62 -        int value = ReadByte(FAN_TACHOMETER_REG[i], out valid);
    3.63 -        if (!valid) 
    3.64 -          continue;
    3.65 -        value |= ReadByte(FAN_TACHOMETER_EXT_REG[i], out valid) << 8;
    3.66 -        if (!valid)
    3.67 -          continue;
    3.68 +      if (has16bitFanCounter) {
    3.69 +        for (int i = 0; i < fans.Length; i++) {
    3.70 +          bool valid;
    3.71 +          int value = ReadByte(FAN_TACHOMETER_REG[i], out valid);
    3.72 +          if (!valid)
    3.73 +            continue;
    3.74 +          value |= ReadByte(FAN_TACHOMETER_EXT_REG[i], out valid) << 8;
    3.75 +          if (!valid)
    3.76 +            continue;
    3.77  
    3.78 -        if (value > 0x3f) {
    3.79 -          fans[i] = (value < 0xffff) ? 1.35e6f / ((value) * 2) : 0;
    3.80 -        } else {
    3.81 -          fans[i] = null;
    3.82 +          if (value > 0x3f) {
    3.83 +            fans[i] = (value < 0xffff) ? 1.35e6f / (value * 2) : 0;
    3.84 +          } else {
    3.85 +            fans[i] = null;
    3.86 +          }
    3.87 +        }
    3.88 +      } else {
    3.89 +        for (int i = 0; i < fans.Length; i++) {
    3.90 +          bool valid;
    3.91 +          int value = ReadByte(FAN_TACHOMETER_REG[i], out valid);
    3.92 +          if (!valid)
    3.93 +            continue;
    3.94 +
    3.95 +          int divisor = 2;
    3.96 +          if (i < 2) {
    3.97 +            int divisors = ReadByte(FAN_TACHOMETER_DIVISOR_REGISTER, out valid);
    3.98 +            if (!valid)
    3.99 +              continue;
   3.100 +            divisor = 1 << ((divisors >> (3 * i)) & 0x7);
   3.101 +          }
   3.102 +
   3.103 +          if (value > 0) {
   3.104 +            fans[i] = (value < 0xff) ? 1.35e6f / (value * divisor) : 0;
   3.105 +          } else {
   3.106 +            fans[i] = null;
   3.107 +          }
   3.108          }
   3.109        }
   3.110  
     4.1 --- a/Properties/AssemblyVersion.cs	Sat Apr 16 13:19:13 2011 +0000
     4.2 +++ b/Properties/AssemblyVersion.cs	Sat Apr 16 14:49:47 2011 +0000
     4.3 @@ -37,5 +37,5 @@
     4.4  
     4.5  using System.Reflection;
     4.6  
     4.7 -[assembly: AssemblyVersion("0.2.1.19")]
     4.8 -[assembly: AssemblyInformationalVersion("0.2.1.19 Alpha")]
     4.9 \ No newline at end of file
    4.10 +[assembly: AssemblyVersion("0.2.1.20")]
    4.11 +[assembly: AssemblyInformationalVersion("0.2.1.20 Alpha")]
    4.12 \ No newline at end of file