# HG changeset patch # User moel.mich # Date 1302965387 0 # Node ID 037a2d66082f01cce09f8339a2e9fdd57ab30af0 # Parent 8635fa73eaccd94e872a478fe998777d0d128772 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. diff -r 8635fa73eacc -r 037a2d66082f Hardware/CPU/AMD0FCPU.cs --- a/Hardware/CPU/AMD0FCPU.cs Sat Apr 16 13:19:13 2011 +0000 +++ b/Hardware/CPU/AMD0FCPU.cs Sat Apr 16 14:49:47 2011 +0000 @@ -52,9 +52,9 @@ private const byte MISCELLANEOUS_CONTROL_FUNCTION = 3; private const ushort MISCELLANEOUS_CONTROL_DEVICE_ID = 0x1103; private const uint THERMTRIP_STATUS_REGISTER = 0xE4; - private const byte THERM_SENSE_CORE_SEL_CPU0 = 0x4; - private const byte THERM_SENSE_CORE_SEL_CPU1 = 0x0; - + + private readonly byte thermSenseCoreSelCPU0; + private readonly byte thermSenseCoreSelCPU1; private readonly uint miscellaneousControlAddress; public AMD0FCPU(int processorIndex, CPUID[][] cpuid, ISettings settings) @@ -67,6 +67,16 @@ if (model >= 0x69 && model != 0xc1 && model != 0x6c && model != 0x7c) offset += 21; + if (model < 40) { + // AMD Athlon 64 Processors + thermSenseCoreSelCPU0 = 0x0; + thermSenseCoreSelCPU1 = 0x4; + } else { + // AMD NPT Family 0Fh Revision F, G have the core selection swapped + thermSenseCoreSelCPU0 = 0x4; + thermSenseCoreSelCPU1 = 0x0; + } + // check if processor supports a digital thermal sensor if (cpuid[0][0].ExtData.GetLength(0) > 7 && (cpuid[0][0].ExtData[7, 3] & 1) != 0) @@ -122,7 +132,7 @@ for (uint i = 0; i < coreTemperatures.Length; i++) { if (Ring0.WritePciConfig( miscellaneousControlAddress, THERMTRIP_STATUS_REGISTER, - i > 0 ? THERM_SENSE_CORE_SEL_CPU1 : THERM_SENSE_CORE_SEL_CPU0)) { + i > 0 ? thermSenseCoreSelCPU1 : thermSenseCoreSelCPU0)) { uint value; if (Ring0.ReadPciConfig( miscellaneousControlAddress, THERMTRIP_STATUS_REGISTER, diff -r 8635fa73eacc -r 037a2d66082f Hardware/HexStringArray.cs --- a/Hardware/HexStringArray.cs Sat Apr 16 13:19:13 2011 +0000 +++ b/Hardware/HexStringArray.cs Sat Apr 16 14:49:47 2011 +0000 @@ -48,7 +48,8 @@ foreach (string line in lines) { string[] array = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); - + if (array.Length == 0) + continue; if (Convert.ToInt32(array[0], 16) == (address & 0xFFF0)) return Convert.ToByte(array[(address & 0x0F) + 1], 16); } diff -r 8635fa73eacc -r 037a2d66082f Hardware/LPC/IT87XX.cs --- a/Hardware/LPC/IT87XX.cs Sat Apr 16 13:19:13 2011 +0000 +++ b/Hardware/LPC/IT87XX.cs Sat Apr 16 14:49:47 2011 +0000 @@ -56,6 +56,7 @@ private readonly float?[] fans = new float?[0]; private readonly float voltageGain; + private readonly bool has16bitFanCounter; // Consts private const byte ITE_VENDOR_ID = 0x90; @@ -68,7 +69,7 @@ private const byte CONFIGURATION_REGISTER = 0x00; private const byte TEMPERATURE_BASE_REG = 0x29; private const byte VENDOR_ID_REGISTER = 0x58; - private const byte FAN_TACHOMETER_16_BIT_ENABLE_REGISTER = 0x0c; + private const byte FAN_TACHOMETER_DIVISOR_REGISTER = 0x0B; private readonly byte[] FAN_TACHOMETER_REG = new byte[] { 0x0d, 0x0e, 0x0f, 0x80, 0x82 }; private readonly byte[] FAN_TACHOMETER_EXT_REG = @@ -85,8 +86,8 @@ private bool WriteByte(byte register, byte value) { Ring0.WriteIoPort(addressReg, register); Ring0.WriteIoPort(dataReg, value); - return register == Ring0.ReadIoPort(addressReg); - } + return register == Ring0.ReadIoPort(addressReg); + } public byte? ReadGPIO(int index) { if (index >= gpioCount) @@ -103,7 +104,7 @@ } public IT87XX(Chip chip, ushort address, ushort gpioAddress, byte version) { - + this.address = address; this.chip = chip; this.version = version; @@ -131,7 +132,14 @@ if (chip == Chip.IT8721F) { voltageGain = 0.012f; } else { - voltageGain = 0.016f; + voltageGain = 0.016f; + } + + // older IT8721F revision do not have 16-bit fan counters + if (chip == Chip.IT8712F && version < 8) { + has16bitFanCounter = false; + } else { + has16bitFanCounter = true; } // Set the number of GPIO sets @@ -236,19 +244,42 @@ temperatures[i] = null; } - for (int i = 0; i < fans.Length; i++) { - bool valid; - int value = ReadByte(FAN_TACHOMETER_REG[i], out valid); - if (!valid) - continue; - value |= ReadByte(FAN_TACHOMETER_EXT_REG[i], out valid) << 8; - if (!valid) - continue; + if (has16bitFanCounter) { + for (int i = 0; i < fans.Length; i++) { + bool valid; + int value = ReadByte(FAN_TACHOMETER_REG[i], out valid); + if (!valid) + continue; + value |= ReadByte(FAN_TACHOMETER_EXT_REG[i], out valid) << 8; + if (!valid) + continue; - if (value > 0x3f) { - fans[i] = (value < 0xffff) ? 1.35e6f / ((value) * 2) : 0; - } else { - fans[i] = null; + if (value > 0x3f) { + fans[i] = (value < 0xffff) ? 1.35e6f / (value * 2) : 0; + } else { + fans[i] = null; + } + } + } else { + for (int i = 0; i < fans.Length; i++) { + bool valid; + int value = ReadByte(FAN_TACHOMETER_REG[i], out valid); + if (!valid) + continue; + + int divisor = 2; + if (i < 2) { + int divisors = ReadByte(FAN_TACHOMETER_DIVISOR_REGISTER, out valid); + if (!valid) + continue; + divisor = 1 << ((divisors >> (3 * i)) & 0x7); + } + + if (value > 0) { + fans[i] = (value < 0xff) ? 1.35e6f / (value * divisor) : 0; + } else { + fans[i] = null; + } } } diff -r 8635fa73eacc -r 037a2d66082f Properties/AssemblyVersion.cs --- a/Properties/AssemblyVersion.cs Sat Apr 16 13:19:13 2011 +0000 +++ b/Properties/AssemblyVersion.cs Sat Apr 16 14:49:47 2011 +0000 @@ -37,5 +37,5 @@ using System.Reflection; -[assembly: AssemblyVersion("0.2.1.19")] -[assembly: AssemblyInformationalVersion("0.2.1.19 Alpha")] \ No newline at end of file +[assembly: AssemblyVersion("0.2.1.20")] +[assembly: AssemblyInformationalVersion("0.2.1.20 Alpha")] \ No newline at end of file