Hardware/LPC/IT87XX.cs
changeset 272 037a2d66082f
parent 247 6dc755f1970e
child 277 5c80f37c0330
     1.1 --- a/Hardware/LPC/IT87XX.cs	Sat Apr 16 13:19:13 2011 +0000
     1.2 +++ b/Hardware/LPC/IT87XX.cs	Sat Apr 16 14:49:47 2011 +0000
     1.3 @@ -56,6 +56,7 @@
     1.4      private readonly float?[] fans = new float?[0];
     1.5  
     1.6      private readonly float voltageGain;
     1.7 +    private readonly bool has16bitFanCounter;
     1.8     
     1.9      // Consts
    1.10      private const byte ITE_VENDOR_ID = 0x90;
    1.11 @@ -68,7 +69,7 @@
    1.12      private const byte CONFIGURATION_REGISTER = 0x00;
    1.13      private const byte TEMPERATURE_BASE_REG = 0x29;
    1.14      private const byte VENDOR_ID_REGISTER = 0x58;
    1.15 -    private const byte FAN_TACHOMETER_16_BIT_ENABLE_REGISTER = 0x0c;
    1.16 +    private const byte FAN_TACHOMETER_DIVISOR_REGISTER = 0x0B;
    1.17      private readonly byte[] FAN_TACHOMETER_REG = 
    1.18        new byte[] { 0x0d, 0x0e, 0x0f, 0x80, 0x82 };
    1.19      private readonly byte[] FAN_TACHOMETER_EXT_REG =
    1.20 @@ -85,8 +86,8 @@
    1.21      private bool WriteByte(byte register, byte value) {
    1.22        Ring0.WriteIoPort(addressReg, register);
    1.23        Ring0.WriteIoPort(dataReg, value);
    1.24 -      return register == Ring0.ReadIoPort(addressReg);
    1.25 -    }
    1.26 +      return register == Ring0.ReadIoPort(addressReg); 
    1.27 +    } 
    1.28  
    1.29      public byte? ReadGPIO(int index) {
    1.30        if (index >= gpioCount)
    1.31 @@ -103,7 +104,7 @@
    1.32      }
    1.33  
    1.34      public IT87XX(Chip chip, ushort address, ushort gpioAddress, byte version) {
    1.35 -      
    1.36 +
    1.37        this.address = address;
    1.38        this.chip = chip;
    1.39        this.version = version;
    1.40 @@ -131,7 +132,14 @@
    1.41        if (chip == Chip.IT8721F) {
    1.42          voltageGain = 0.012f;
    1.43        } else {
    1.44 -        voltageGain = 0.016f;
    1.45 +        voltageGain = 0.016f;        
    1.46 +      }
    1.47 +
    1.48 +      // older IT8721F revision do not have 16-bit fan counters
    1.49 +      if (chip == Chip.IT8712F && version < 8) {
    1.50 +        has16bitFanCounter = false;
    1.51 +      } else {
    1.52 +        has16bitFanCounter = true;
    1.53        }
    1.54  
    1.55        // Set the number of GPIO sets
    1.56 @@ -236,19 +244,42 @@
    1.57            temperatures[i] = null;       
    1.58        }
    1.59  
    1.60 -      for (int i = 0; i < fans.Length; i++) {
    1.61 -        bool valid;
    1.62 -        int value = ReadByte(FAN_TACHOMETER_REG[i], out valid);
    1.63 -        if (!valid) 
    1.64 -          continue;
    1.65 -        value |= ReadByte(FAN_TACHOMETER_EXT_REG[i], out valid) << 8;
    1.66 -        if (!valid)
    1.67 -          continue;
    1.68 +      if (has16bitFanCounter) {
    1.69 +        for (int i = 0; i < fans.Length; i++) {
    1.70 +          bool valid;
    1.71 +          int value = ReadByte(FAN_TACHOMETER_REG[i], out valid);
    1.72 +          if (!valid)
    1.73 +            continue;
    1.74 +          value |= ReadByte(FAN_TACHOMETER_EXT_REG[i], out valid) << 8;
    1.75 +          if (!valid)
    1.76 +            continue;
    1.77  
    1.78 -        if (value > 0x3f) {
    1.79 -          fans[i] = (value < 0xffff) ? 1.35e6f / ((value) * 2) : 0;
    1.80 -        } else {
    1.81 -          fans[i] = null;
    1.82 +          if (value > 0x3f) {
    1.83 +            fans[i] = (value < 0xffff) ? 1.35e6f / (value * 2) : 0;
    1.84 +          } else {
    1.85 +            fans[i] = null;
    1.86 +          }
    1.87 +        }
    1.88 +      } else {
    1.89 +        for (int i = 0; i < fans.Length; i++) {
    1.90 +          bool valid;
    1.91 +          int value = ReadByte(FAN_TACHOMETER_REG[i], out valid);
    1.92 +          if (!valid)
    1.93 +            continue;
    1.94 +
    1.95 +          int divisor = 2;
    1.96 +          if (i < 2) {
    1.97 +            int divisors = ReadByte(FAN_TACHOMETER_DIVISOR_REGISTER, out valid);
    1.98 +            if (!valid)
    1.99 +              continue;
   1.100 +            divisor = 1 << ((divisors >> (3 * i)) & 0x7);
   1.101 +          }
   1.102 +
   1.103 +          if (value > 0) {
   1.104 +            fans[i] = (value < 0xff) ? 1.35e6f / (value * divisor) : 0;
   1.105 +          } else {
   1.106 +            fans[i] = null;
   1.107 +          }
   1.108          }
   1.109        }
   1.110