1.1 --- a/Hardware/LPC/W83627.cs Sun Feb 07 19:48:32 2010 +0000
1.2 +++ b/Hardware/LPC/W83627.cs Sun Feb 07 19:53:51 2010 +0000
1.3 @@ -41,155 +41,63 @@
1.4 using System.Text;
1.5
1.6 namespace OpenHardwareMonitor.Hardware.LPC {
1.7 - public class W83627DHG : IHardware {
1.8 -
1.9 - private Chip chip;
1.10 - private byte revision;
1.11 -
1.12 - private string name;
1.13 - private Image icon;
1.14 -
1.15 - private bool available = false;
1.16 - private ushort address;
1.17 -
1.18 - private List<ISensor> active = new List<ISensor>();
1.19 -
1.20 + public class W83627 : Winbond, IHardware {
1.21 +
1.22 private Sensor[] temperatures;
1.23 private Sensor[] fans;
1.24 private Sensor[] voltages;
1.25
1.26 private float[] voltageGains;
1.27 -
1.28 - // Consts
1.29 - private const ushort WINBOND_VENDOR_ID = 0x5CA3;
1.30 - private const byte HIGH_BYTE = 0x80;
1.31 -
1.32 - // Hardware Monitor
1.33 - private const byte ADDRESS_REGISTER_OFFSET = 0x05;
1.34 - private const byte DATA_REGISTER_OFFSET = 0x06;
1.35 + private string[] fanNames;
1.36
1.37 // Hardware Monitor Registers
1.38 - private const byte VOLTAGE_BASE_REG = 0x20;
1.39 - private const byte BANK_SELECT_REGISTER = 0x04E;
1.40 - private const byte VENDOR_ID_REGISTER = 0x4F;
1.41 - private const byte FIRST_BANK_REGISTER = 0x50;
1.42 + private const byte VOLTAGE_BASE_REG = 0x20;
1.43 private const byte TEMPERATURE_BASE_REG = 0x50;
1.44 private const byte TEMPERATURE_SYS_REG = 0x27;
1.45
1.46 private byte[] FAN_TACHO_REG = new byte[] { 0x28, 0x29, 0x2A, 0x3F, 0x53 };
1.47 - private byte[] FAN_TACHO_BANK = new byte[] { 0, 0, 0, 0, 5 };
1.48 - private string[] FAN_NAME = new string[]
1.49 - { "System", "CPU #1", "Auxiliary #1", "CPU #2", "Auxiliary #2" };
1.50 + private byte[] FAN_TACHO_BANK = new byte[] { 0, 0, 0, 0, 5 };
1.51 private byte[] FAN_BIT_REG = new byte[] { 0x47, 0x4B, 0x4C, 0x59, 0x5D };
1.52 private byte[] FAN_DIV_BIT0 = new byte[] { 36, 38, 30, 8, 10 };
1.53 private byte[] FAN_DIV_BIT1 = new byte[] { 37, 39, 31, 9, 11 };
1.54 private byte[] FAN_DIV_BIT2 = new byte[] { 5, 6, 7, 23, 15 };
1.55
1.56 - private byte ReadByte(byte bank, byte register) {
1.57 - WinRing0.WriteIoPortByte(
1.58 - (ushort)(address + ADDRESS_REGISTER_OFFSET), BANK_SELECT_REGISTER);
1.59 - WinRing0.WriteIoPortByte(
1.60 - (ushort)(address + DATA_REGISTER_OFFSET), bank);
1.61 - WinRing0.WriteIoPortByte(
1.62 - (ushort)(address + ADDRESS_REGISTER_OFFSET), register);
1.63 - return WinRing0.ReadIoPortByte(
1.64 - (ushort)(address + DATA_REGISTER_OFFSET));
1.65 - }
1.66 -
1.67 - public W83627DHG(Chip chip, byte revision, ushort address) {
1.68 - this.chip = chip;
1.69 - this.revision = revision;
1.70 - this.address = address;
1.71 -
1.72 - // Check vendor id
1.73 - ushort vendorId =
1.74 - (ushort)((ReadByte(HIGH_BYTE, VENDOR_ID_REGISTER) << 8) |
1.75 - ReadByte(0, VENDOR_ID_REGISTER));
1.76 - if (vendorId != WINBOND_VENDOR_ID)
1.77 - return;
1.78 -
1.79 - voltageGains = new float[] { 0.008f, 1, 1, 0.016f, 1, 1, 1, 0.016f };
1.80 - voltages = new Sensor[3];
1.81 - voltages[0] = new Sensor("CPU VCore", 0, SensorType.Voltage, this);
1.82 - voltages[1] = new Sensor("+3.3V", 3, SensorType.Voltage, this);
1.83 - voltages[2] = new Sensor("Battery", 7, SensorType.Voltage, this);
1.84 -
1.85 + public W83627(Chip chip, byte revision, ushort address)
1.86 + : base(chip, revision, address)
1.87 + {
1.88 +
1.89 temperatures = new Sensor[3];
1.90 temperatures[0] = new Sensor("CPU", 0, SensorType.Temperature, this);
1.91 temperatures[1] = new Sensor("Auxiliary", 1, SensorType.Temperature, this);
1.92 temperatures[2] = new Sensor("System", 2, SensorType.Temperature, this);
1.93
1.94 - fans = new Sensor[FAN_NAME.Length];
1.95 - for (int i = 0; i < FAN_NAME.Length; i++)
1.96 - fans[i] = new Sensor(FAN_NAME[i], i, SensorType.Fan, this);
1.97 -
1.98 switch (chip) {
1.99 - case Chip.W83627DHG: name = "Winbond W83627DHG"; break;
1.100 - case Chip.W83627DHGP: name = "Winbond W83627DHG-P"; break;
1.101 - default: return;
1.102 + case Chip.W83627DHG:
1.103 + case Chip.W83627DHGP:
1.104 + fanNames = new string[] { "System", "CPU #1", "Auxiliary #1",
1.105 + "CPU #2", "Auxiliary #2" };
1.106 + voltageGains = new float[] { 0.008f, 1, 1, 0.016f, 1, 1, 1, 0.016f };
1.107 + voltages = new Sensor[3];
1.108 + voltages[0] = new Sensor("CPU VCore", 0, SensorType.Voltage, this);
1.109 + voltages[1] = new Sensor("+3.3V", 3, SensorType.Voltage, this);
1.110 + voltages[2] = new Sensor("Battery", 7, SensorType.Voltage, this);
1.111 + break;
1.112 + case Chip.W83627HF:
1.113 + fanNames = new string[] { "Fan #1", "Fan #2", "Fan #3" };
1.114 + voltageGains = new float[] { 0.016f, 1, 0.016f, 1, 1, 1, 1, 0.016f };
1.115 + voltages = new Sensor[3];
1.116 + voltages[0] = new Sensor("CPU VCore", 0, SensorType.Voltage, this);
1.117 + voltages[1] = new Sensor("+3.3V", 2, SensorType.Voltage, this);
1.118 + voltages[2] = new Sensor("Battery", 7, SensorType.Voltage, this);
1.119 + break;
1.120 + default: fanNames = new string[0];
1.121 + break;
1.122 }
1.123 -
1.124 - this.icon = Utilities.EmbeddedResources.GetImage("chip.png");
1.125 - available = true;
1.126 - }
1.127 -
1.128 - public bool IsAvailable {
1.129 - get { return available; }
1.130 - }
1.131 -
1.132 - public string Name {
1.133 - get { return name; }
1.134 - }
1.135 -
1.136 - public string Identifier {
1.137 - get { return "/lpc/" + chip.ToString().ToLower(); }
1.138 - }
1.139 -
1.140 - public Image Icon {
1.141 - get { return icon; }
1.142 - }
1.143 -
1.144 - public ISensor[] Sensors {
1.145 - get { return active.ToArray(); }
1.146 - }
1.147 -
1.148 - public string GetReport() {
1.149 - StringBuilder r = new StringBuilder();
1.150 -
1.151 - r.AppendLine("LPC W83627DHG");
1.152 - r.AppendLine();
1.153 - r.Append("Chip ID: 0x"); r.AppendLine(chip.ToString("X"));
1.154 - r.Append("Chip revision: 0x"); r.AppendLine(revision.ToString("X"));
1.155 - r.Append("Base Adress: 0x"); r.AppendLine(address.ToString("X4"));
1.156 - r.AppendLine();
1.157 - r.AppendLine("Hardware Monitor Registers");
1.158 - r.AppendLine();
1.159 - r.AppendLine(" 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F");
1.160 - r.AppendLine();
1.161 - for (int i = 0; i < 0x7; i++) {
1.162 - r.Append(" "); r.Append((i << 4).ToString("X2")); r.Append(" ");
1.163 - for (int j = 0; j <= 0xF; j++) {
1.164 - r.Append(" ");
1.165 - r.Append(ReadByte(0, (byte)((i << 4) | j)).ToString("X2"));
1.166 - }
1.167 - r.AppendLine();
1.168 - }
1.169 - for (int k = 1; k <=5; k++) {
1.170 - r.AppendLine("Bank " + k);
1.171 - for (int i = 0x5; i < 0x6; i++) {
1.172 - r.Append(" "); r.Append((i << 4).ToString("X2")); r.Append(" ");
1.173 - for (int j = 0; j <= 0xF; j++) {
1.174 - r.Append(" ");
1.175 - r.Append(ReadByte((byte)(k),
1.176 - (byte)((i << 4) | j)).ToString("X2"));
1.177 - }
1.178 - r.AppendLine();
1.179 - }
1.180 - }
1.181 - r.AppendLine();
1.182 -
1.183 - return r.ToString();
1.184 - }
1.185 +
1.186 + fans = new Sensor[fanNames.Length];
1.187 + for (int i = 0; i < fanNames.Length; i++)
1.188 + fans[i] = new Sensor(fanNames[i], i, SensorType.Fan, this);
1.189 + }
1.190
1.191 public void Update() {
1.192 foreach (Sensor sensor in voltages) {
1.193 @@ -243,24 +151,5 @@
1.194 ActivateSensor(sensor);
1.195 }
1.196 }
1.197 -
1.198 - private void ActivateSensor(Sensor sensor) {
1.199 - if (!active.Contains(sensor)) {
1.200 - active.Add(sensor);
1.201 - if (SensorAdded != null)
1.202 - SensorAdded(sensor);
1.203 - }
1.204 - }
1.205 -
1.206 - private void DeactivateSensor(Sensor sensor) {
1.207 - if (active.Contains(sensor)) {
1.208 - active.Remove(sensor);
1.209 - if (SensorRemoved != null)
1.210 - SensorRemoved(sensor);
1.211 - }
1.212 - }
1.213 -
1.214 - public event SensorEventHandler SensorAdded;
1.215 - public event SensorEventHandler SensorRemoved;
1.216 }
1.217 }