diff -r 898935080fd6 -r 5cb7eb5bf628 Hardware/LPC/W836XX.cs --- a/Hardware/LPC/W836XX.cs Fri Feb 19 19:50:07 2010 +0000 +++ b/Hardware/LPC/W836XX.cs Sat Feb 20 19:51:10 2010 +0000 @@ -67,8 +67,13 @@ private const byte VOLTAGE_BASE_REG = 0x20; private const byte BANK_SELECT_REGISTER = 0x4E; private const byte VENDOR_ID_REGISTER = 0x4F; - private const byte TEMPERATURE_BASE_REG = 0x50; - private const byte TEMPERATURE_SYS_REG = 0x27; + private const byte TEMPERATURE_SOURCE_SELECT_REG = 0x49; + + private string[] TEMPERATURE_NAME = + new string[] {"CPU", "Auxiliary", "System"}; + private byte[] TEMPERATURE_REG = new byte[] { 0x50, 0x50, 0x27 }; + private byte[] TEMPERATURE_BANK = new byte[] { 1, 2, 0 }; + private byte[] TEMPERATURE_SEL = new byte[] { 1, 2, 0 }; private byte[] FAN_TACHO_REG = new byte[] { 0x28, 0x29, 0x2A, 0x3F, 0x53 }; private byte[] FAN_TACHO_BANK = new byte[] { 0, 0, 0, 0, 5 }; @@ -88,6 +93,17 @@ (ushort)(address + DATA_REGISTER_OFFSET)); } + private void WriteByte(byte bank, byte register, byte value) { + WinRing0.WriteIoPortByte( + (ushort)(address + ADDRESS_REGISTER_OFFSET), BANK_SELECT_REGISTER); + WinRing0.WriteIoPortByte( + (ushort)(address + DATA_REGISTER_OFFSET), bank); + WinRing0.WriteIoPortByte( + (ushort)(address + ADDRESS_REGISTER_OFFSET), register); + WinRing0.WriteIoPortByte( + (ushort)(address + DATA_REGISTER_OFFSET), value); + } + public W836XX(Chip chip, byte revision, ushort address) : base(chip) { @@ -96,10 +112,29 @@ available = IsWinbondVendor(); - temperatures = new Sensor[3]; - temperatures[0] = new Sensor("CPU", 0, SensorType.Temperature, this); - temperatures[1] = new Sensor("Auxiliary", 1, SensorType.Temperature, this); - temperatures[2] = new Sensor("System", 2, SensorType.Temperature, this); + List list = new List(); + switch (chip) { + case Chip.W83627DHG: + // do not add temperature sensor registers that read PECI agents + byte sel = ReadByte(0, TEMPERATURE_SOURCE_SELECT_REG); + if ((sel & 0x07) == 0) + list.Add(new Sensor(TEMPERATURE_NAME[0], 0, + SensorType.Temperature, this)); + if ((sel & 0x70) == 0) + list.Add(new Sensor(TEMPERATURE_NAME[1], 1, + SensorType.Temperature, this)); + list.Add(new Sensor(TEMPERATURE_NAME[2], 2, + SensorType.Temperature, this)); + break; + default: + // no PECI support or extra sensor report register + for (int i = 0; i < TEMPERATURE_NAME.Length; i++) { + list.Add(new Sensor(TEMPERATURE_NAME[i], i, + SensorType.Temperature, this)); + } + break; + } + temperatures = list.ToArray(); switch (chip) { case Chip.W83627DHG: @@ -145,6 +180,7 @@ } public void Update() { + foreach (Sensor sensor in voltages) { if (sensor.Index < 7) { int value = ReadByte(0, (byte)(VOLTAGE_BASE_REG + sensor.Index)); @@ -157,7 +193,7 @@ // Battery voltage bool valid = (ReadByte(0, 0x5D) & 0x01) > 0; if (valid) { - sensor.Value = + sensor.Value = 0.008f * voltageGains[sensor.Index] * ReadByte(5, 0x51); ActivateSensor(sensor); } else @@ -167,18 +203,32 @@ foreach (Sensor sensor in temperatures) { int value; - if (sensor.Index < 2) { - value = (sbyte)ReadByte((byte)(sensor.Index + 1), TEMPERATURE_BASE_REG); - value = (value << 1) | ReadByte((byte)(sensor.Index + 1), - (byte)(TEMPERATURE_BASE_REG + 1)) >> 7; + switch (chip) { + case Chip.W83667HG: + case Chip.W83667HGB: + WriteByte(0, 0x7D, TEMPERATURE_SEL[sensor.Index]); + value = ((sbyte)ReadByte(0, 0x7E)) << 1; + break; + case Chip.W83627DHGP: + WriteByte(0, 0x7C, TEMPERATURE_SEL[sensor.Index]); + value = ((sbyte)ReadByte(0, 0x7D)) << 1; + break; + default: + value = ((sbyte)ReadByte(TEMPERATURE_BANK[sensor.Index], + TEMPERATURE_REG[sensor.Index])) << 1; + if (TEMPERATURE_BANK[sensor.Index] > 0) { + value |= ReadByte(TEMPERATURE_BANK[sensor.Index], + (byte)(TEMPERATURE_REG[sensor.Index] + 1)) >> 7; + } + break; + } + float temperature = value / 2.0f; + if (temperature <= 125 && temperature >= -55) { + sensor.Value = temperature; + ActivateSensor(sensor); } else { - value = (sbyte)ReadByte(0, TEMPERATURE_SYS_REG) << 1; + DeactivateSensor(sensor); } - sensor.Value = value / 2.0f; - if (value < 0xFE) - ActivateSensor(sensor); - else - DeactivateSensor(sensor); } long bits = 0; @@ -212,7 +262,7 @@ r.AppendLine(); r.AppendLine(" 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F"); r.AppendLine(); - for (int i = 0; i < 0x7; i++) { + for (int i = 0; i <= 0x7; i++) { r.Append(" "); r.Append((i << 4).ToString("X2")); r.Append(" "); for (int j = 0; j <= 0xF; j++) { r.Append(" ");