Added initial support for W83627HF. Some refactoring for IHardware classes.
3 Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 The contents of this file are subject to the Mozilla Public License Version
6 1.1 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
9 http://www.mozilla.org/MPL/
11 Software distributed under the License is distributed on an "AS IS" basis,
12 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 for the specific language governing rights and limitations under the License.
15 The Original Code is the Open Hardware Monitor code.
17 The Initial Developer of the Original Code is
18 Michael Möller <m.moeller@gmx.ch>.
19 Portions created by the Initial Developer are Copyright (C) 2009-2010
20 the Initial Developer. All Rights Reserved.
24 Alternatively, the contents of this file may be used under the terms of
25 either the GNU General Public License Version 2 or later (the "GPL"), or
26 the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 in which case the provisions of the GPL or the LGPL are applicable instead
28 of those above. If you wish to allow use of your version of this file only
29 under the terms of either the GPL or the LGPL, and not to allow others to
30 use your version of this file under the terms of the MPL, indicate your
31 decision by deleting the provisions above and replace them with the notice
32 and other provisions required by the GPL or the LGPL. If you do not delete
33 the provisions above, a recipient may use your version of this file under
34 the terms of any one of the MPL, the GPL or the LGPL.
39 using System.Collections.Generic;
43 namespace OpenHardwareMonitor.Hardware.LPC {
44 public class W83627 : Winbond, IHardware {
46 private Sensor[] temperatures;
47 private Sensor[] fans;
48 private Sensor[] voltages;
50 private float[] voltageGains;
51 private string[] fanNames;
53 // Hardware Monitor Registers
54 private const byte VOLTAGE_BASE_REG = 0x20;
55 private const byte TEMPERATURE_BASE_REG = 0x50;
56 private const byte TEMPERATURE_SYS_REG = 0x27;
58 private byte[] FAN_TACHO_REG = new byte[] { 0x28, 0x29, 0x2A, 0x3F, 0x53 };
59 private byte[] FAN_TACHO_BANK = new byte[] { 0, 0, 0, 0, 5 };
60 private byte[] FAN_BIT_REG = new byte[] { 0x47, 0x4B, 0x4C, 0x59, 0x5D };
61 private byte[] FAN_DIV_BIT0 = new byte[] { 36, 38, 30, 8, 10 };
62 private byte[] FAN_DIV_BIT1 = new byte[] { 37, 39, 31, 9, 11 };
63 private byte[] FAN_DIV_BIT2 = new byte[] { 5, 6, 7, 23, 15 };
65 public W83627(Chip chip, byte revision, ushort address)
66 : base(chip, revision, address)
69 temperatures = new Sensor[3];
70 temperatures[0] = new Sensor("CPU", 0, SensorType.Temperature, this);
71 temperatures[1] = new Sensor("Auxiliary", 1, SensorType.Temperature, this);
72 temperatures[2] = new Sensor("System", 2, SensorType.Temperature, this);
77 fanNames = new string[] { "System", "CPU #1", "Auxiliary #1",
78 "CPU #2", "Auxiliary #2" };
79 voltageGains = new float[] { 0.008f, 1, 1, 0.016f, 1, 1, 1, 0.016f };
80 voltages = new Sensor[3];
81 voltages[0] = new Sensor("CPU VCore", 0, SensorType.Voltage, this);
82 voltages[1] = new Sensor("+3.3V", 3, SensorType.Voltage, this);
83 voltages[2] = new Sensor("Battery", 7, SensorType.Voltage, this);
86 fanNames = new string[] { "Fan #1", "Fan #2", "Fan #3" };
87 voltageGains = new float[] { 0.016f, 1, 0.016f, 1, 1, 1, 1, 0.016f };
88 voltages = new Sensor[3];
89 voltages[0] = new Sensor("CPU VCore", 0, SensorType.Voltage, this);
90 voltages[1] = new Sensor("+3.3V", 2, SensorType.Voltage, this);
91 voltages[2] = new Sensor("Battery", 7, SensorType.Voltage, this);
93 default: fanNames = new string[0];
97 fans = new Sensor[fanNames.Length];
98 for (int i = 0; i < fanNames.Length; i++)
99 fans[i] = new Sensor(fanNames[i], i, SensorType.Fan, this);
102 public void Update() {
103 foreach (Sensor sensor in voltages) {
104 if (sensor.Index < 7) {
105 int value = ReadByte(0, (byte)(VOLTAGE_BASE_REG + sensor.Index));
106 sensor.Value = voltageGains[sensor.Index] * value;
107 if (sensor.Value > 0)
108 ActivateSensor(sensor);
110 DeactivateSensor(sensor);
113 bool valid = (ReadByte(0, 0x5D) & 0x01) > 0;
115 sensor.Value = voltageGains[sensor.Index] *
117 ActivateSensor(sensor);
119 DeactivateSensor(sensor);
123 foreach (Sensor sensor in temperatures) {
125 if (sensor.Index < 2) {
126 value = (sbyte)ReadByte((byte)(sensor.Index + 1), TEMPERATURE_BASE_REG);
127 value = (value << 1) | ReadByte((byte)(sensor.Index + 1),
128 (byte)(TEMPERATURE_BASE_REG + 1)) >> 7;
130 value = (sbyte)ReadByte(0, TEMPERATURE_SYS_REG) << 1;
132 sensor.Value = value / 2.0f;
134 ActivateSensor(sensor);
136 DeactivateSensor(sensor);
140 for (int i = 0; i < FAN_BIT_REG.Length; i++)
141 bits = (bits << 8) | ReadByte(0, FAN_BIT_REG[i]);
142 foreach (Sensor sensor in fans) {
143 int count = ReadByte(FAN_TACHO_BANK[sensor.Index],
144 FAN_TACHO_REG[sensor.Index]);
145 int divisorBits = (int)(
146 (((bits >> FAN_DIV_BIT2[sensor.Index]) & 1) << 2) |
147 (((bits >> FAN_DIV_BIT1[sensor.Index]) & 1) << 1) |
148 ((bits >> FAN_DIV_BIT0[sensor.Index]) & 1));
149 int divisor = 1 << divisorBits;
150 sensor.Value = (count < 0xff) ? 1.35e6f / (count * divisor) : 0;
151 ActivateSensor(sensor);