moel@1
|
1 |
/*
|
moel@1
|
2 |
|
moel@1
|
3 |
Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
moel@1
|
4 |
|
moel@1
|
5 |
The contents of this file are subject to the Mozilla Public License Version
|
moel@1
|
6 |
1.1 (the "License"); you may not use this file except in compliance with
|
moel@1
|
7 |
the License. You may obtain a copy of the License at
|
moel@1
|
8 |
|
moel@1
|
9 |
http://www.mozilla.org/MPL/
|
moel@1
|
10 |
|
moel@1
|
11 |
Software distributed under the License is distributed on an "AS IS" basis,
|
moel@1
|
12 |
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
moel@1
|
13 |
for the specific language governing rights and limitations under the License.
|
moel@1
|
14 |
|
moel@1
|
15 |
The Original Code is the Open Hardware Monitor code.
|
moel@1
|
16 |
|
moel@1
|
17 |
The Initial Developer of the Original Code is
|
moel@1
|
18 |
Michael Möller <m.moeller@gmx.ch>.
|
moel@1
|
19 |
Portions created by the Initial Developer are Copyright (C) 2009-2010
|
moel@1
|
20 |
the Initial Developer. All Rights Reserved.
|
moel@1
|
21 |
|
moel@1
|
22 |
Contributor(s):
|
moel@1
|
23 |
|
moel@1
|
24 |
Alternatively, the contents of this file may be used under the terms of
|
moel@1
|
25 |
either the GNU General Public License Version 2 or later (the "GPL"), or
|
moel@1
|
26 |
the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
moel@1
|
27 |
in which case the provisions of the GPL or the LGPL are applicable instead
|
moel@1
|
28 |
of those above. If you wish to allow use of your version of this file only
|
moel@1
|
29 |
under the terms of either the GPL or the LGPL, and not to allow others to
|
moel@1
|
30 |
use your version of this file under the terms of the MPL, indicate your
|
moel@1
|
31 |
decision by deleting the provisions above and replace them with the notice
|
moel@1
|
32 |
and other provisions required by the GPL or the LGPL. If you do not delete
|
moel@1
|
33 |
the provisions above, a recipient may use your version of this file under
|
moel@1
|
34 |
the terms of any one of the MPL, the GPL or the LGPL.
|
moel@1
|
35 |
|
moel@1
|
36 |
*/
|
moel@1
|
37 |
|
moel@1
|
38 |
using System;
|
moel@1
|
39 |
using System.Collections.Generic;
|
moel@1
|
40 |
using System.Drawing;
|
moel@1
|
41 |
using System.Text;
|
moel@1
|
42 |
|
moel@1
|
43 |
namespace OpenHardwareMonitor.Hardware.LPC {
|
moel@1
|
44 |
public class IT87 : IHardware {
|
moel@1
|
45 |
|
moel@1
|
46 |
private string name;
|
moel@1
|
47 |
private Image icon;
|
moel@1
|
48 |
|
moel@1
|
49 |
private bool available = false;
|
moel@1
|
50 |
private Chip chip;
|
moel@1
|
51 |
private ushort address;
|
moel@1
|
52 |
|
moel@1
|
53 |
private Sensor[] temperatures;
|
moel@1
|
54 |
private Sensor[] fans;
|
moel@1
|
55 |
private Sensor[] voltages;
|
moel@1
|
56 |
private List<ISensor> active = new List<ISensor>();
|
moel@1
|
57 |
private float[] voltageGains;
|
moel@1
|
58 |
|
moel@1
|
59 |
// Consts
|
moel@1
|
60 |
private const byte ITE_VENDOR_ID = 0x90;
|
moel@1
|
61 |
|
moel@1
|
62 |
// Environment Controller
|
moel@1
|
63 |
private const byte ADDRESS_REGISTER_OFFSET = 0x05;
|
moel@1
|
64 |
private const byte DATA_REGISTER_OFFSET = 0x06;
|
moel@1
|
65 |
|
moel@1
|
66 |
// Environment Controller Registers
|
moel@1
|
67 |
private const byte CONFIGURATION_REGISTER = 0x00;
|
moel@1
|
68 |
private const byte TEMPERATURE_BASE_REG = 0x29;
|
moel@1
|
69 |
private const byte VENDOR_ID_REGISTER = 0x58;
|
moel@1
|
70 |
private const byte FAN_TACHOMETER_16_BIT_ENABLE_REGISTER = 0x0c;
|
moel@1
|
71 |
private byte[] FAN_TACHOMETER_REG =
|
moel@1
|
72 |
new byte[] { 0x0d, 0x0e, 0x0f, 0x80, 0x82 };
|
moel@1
|
73 |
private byte[] FAN_TACHOMETER_EXT_REG =
|
moel@1
|
74 |
new byte[] { 0x18, 0x19, 0x1a, 0x81, 0x83 };
|
moel@1
|
75 |
private const byte VOLTAGE_BASE_REG = 0x20;
|
moel@1
|
76 |
|
moel@1
|
77 |
private byte ReadByte(byte register) {
|
moel@1
|
78 |
WinRing0.WriteIoPortByte(
|
moel@1
|
79 |
(ushort)(address + ADDRESS_REGISTER_OFFSET), register);
|
moel@1
|
80 |
return WinRing0.ReadIoPortByte((ushort)(address + DATA_REGISTER_OFFSET));
|
moel@1
|
81 |
}
|
moel@1
|
82 |
|
moel@1
|
83 |
public IT87(Chip chip, ushort address) {
|
moel@1
|
84 |
|
moel@1
|
85 |
this.chip = chip;
|
moel@1
|
86 |
this.address = address;
|
moel@1
|
87 |
|
moel@1
|
88 |
switch (chip) {
|
moel@1
|
89 |
case Chip.IT8716F: name = "ITE IT8716F"; break;
|
moel@1
|
90 |
case Chip.IT8718F: name = "ITE IT8718F"; break;
|
moel@1
|
91 |
case Chip.IT8720F: name = "ITE IT8720F"; break;
|
moel@1
|
92 |
case Chip.IT8726F: name = "ITE IT8726F"; break;
|
moel@1
|
93 |
default: return;
|
moel@1
|
94 |
}
|
moel@1
|
95 |
|
moel@1
|
96 |
// Check vendor id
|
moel@1
|
97 |
byte vendorId = ReadByte(VENDOR_ID_REGISTER);
|
moel@1
|
98 |
if (vendorId != ITE_VENDOR_ID)
|
moel@1
|
99 |
return;
|
moel@1
|
100 |
|
moel@1
|
101 |
// Bit 0x10 of the configuration register should always be 1
|
moel@1
|
102 |
if ((ReadByte(CONFIGURATION_REGISTER) & 0x10) == 0)
|
moel@1
|
103 |
return;
|
moel@1
|
104 |
|
moel@1
|
105 |
temperatures = new Sensor[3];
|
moel@1
|
106 |
for (int i = 0; i < temperatures.Length; i++)
|
moel@1
|
107 |
temperatures[i] = new Sensor("Temperature #" + (i + 1), i,
|
moel@1
|
108 |
SensorType.Temperature, this);
|
moel@1
|
109 |
|
moel@6
|
110 |
fans = new Sensor[5];
|
moel@1
|
111 |
for (int i = 0; i < fans.Length; i++)
|
moel@1
|
112 |
fans[i] = new Sensor("Fan #" + (i + 1), i, SensorType.Fan, this);
|
moel@1
|
113 |
|
moel@1
|
114 |
voltageGains = new float[] {
|
moel@1
|
115 |
1, 1, 1, (6.8f / 10 + 1), 1, 1, 1, 1, 1 };
|
moel@1
|
116 |
|
moel@1
|
117 |
voltages = new Sensor[2];
|
moel@1
|
118 |
voltages[0] = new Sensor("CPU VCore", 0, SensorType.Voltage, this);
|
moel@1
|
119 |
voltages[1] = new Sensor("Battery", 8, SensorType.Voltage, this);
|
moel@1
|
120 |
|
moel@1
|
121 |
available = true;
|
moel@1
|
122 |
icon = Utilities.EmbeddedResources.GetImage("chip.png");
|
moel@1
|
123 |
}
|
moel@1
|
124 |
|
moel@1
|
125 |
public bool IsAvailable {
|
moel@1
|
126 |
get { return available; }
|
moel@1
|
127 |
}
|
moel@1
|
128 |
|
moel@1
|
129 |
public string Name {
|
moel@1
|
130 |
get { return name; }
|
moel@1
|
131 |
}
|
moel@1
|
132 |
|
moel@1
|
133 |
public string Identifier {
|
moel@1
|
134 |
get { return "/lpc/it87"; }
|
moel@1
|
135 |
}
|
moel@1
|
136 |
|
moel@1
|
137 |
public Image Icon {
|
moel@1
|
138 |
get { return icon; }
|
moel@1
|
139 |
}
|
moel@1
|
140 |
|
moel@1
|
141 |
public ISensor[] Sensors {
|
moel@1
|
142 |
get { return active.ToArray(); }
|
moel@1
|
143 |
}
|
moel@1
|
144 |
|
moel@1
|
145 |
public string GetReport() {
|
moel@1
|
146 |
StringBuilder r = new StringBuilder();
|
moel@1
|
147 |
|
moel@1
|
148 |
r.AppendLine("LPC IT87");
|
moel@1
|
149 |
r.AppendLine();
|
moel@1
|
150 |
r.Append("Chip ID: 0x"); r.AppendLine(chip.ToString("X"));
|
moel@1
|
151 |
r.Append("Chip Name: "); r.AppendLine(name);
|
moel@7
|
152 |
r.Append("Base Address: 0x"); r.AppendLine(address.ToString("X4"));
|
moel@1
|
153 |
r.AppendLine();
|
moel@1
|
154 |
r.AppendLine("Environment Controller Registers");
|
moel@1
|
155 |
r.AppendLine();
|
moel@1
|
156 |
|
moel@1
|
157 |
r.AppendLine(" 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F");
|
moel@1
|
158 |
r.AppendLine();
|
moel@1
|
159 |
for (int i = 0; i <= 0xA; i++) {
|
moel@1
|
160 |
r.Append(" "); r.Append((i << 4).ToString("X2")); r.Append(" ");
|
moel@1
|
161 |
for (int j = 0; j <= 0xF; j++) {
|
moel@1
|
162 |
r.Append(" ");
|
moel@1
|
163 |
r.Append(ReadByte((byte)((i << 4) | j)).ToString("X2"));
|
moel@1
|
164 |
}
|
moel@1
|
165 |
r.AppendLine();
|
moel@1
|
166 |
}
|
moel@1
|
167 |
r.AppendLine();
|
moel@1
|
168 |
|
moel@1
|
169 |
return r.ToString();
|
moel@1
|
170 |
}
|
moel@1
|
171 |
|
moel@1
|
172 |
public void Update() {
|
moel@1
|
173 |
|
moel@1
|
174 |
foreach (Sensor sensor in voltages) {
|
moel@1
|
175 |
int value = ReadByte((byte)(VOLTAGE_BASE_REG + sensor.Index));
|
moel@1
|
176 |
sensor.Value = voltageGains[sensor.Index] * 0.001f * (value << 4);
|
moel@1
|
177 |
if (sensor.Value > 0)
|
moel@1
|
178 |
ActivateSensor(sensor);
|
moel@1
|
179 |
else
|
moel@1
|
180 |
DeactivateSensor(sensor);
|
moel@1
|
181 |
}
|
moel@1
|
182 |
|
moel@1
|
183 |
foreach (Sensor sensor in temperatures) {
|
moel@1
|
184 |
int value = ReadByte((byte)(TEMPERATURE_BASE_REG + sensor.Index));
|
moel@1
|
185 |
sensor.Value = value;
|
moel@1
|
186 |
if (value < 254)
|
moel@1
|
187 |
ActivateSensor(sensor);
|
moel@1
|
188 |
else
|
moel@1
|
189 |
DeactivateSensor(sensor);
|
moel@1
|
190 |
}
|
moel@1
|
191 |
|
moel@1
|
192 |
foreach (Sensor sensor in fans) {
|
moel@1
|
193 |
int value = ReadByte(FAN_TACHOMETER_REG[sensor.Index]);
|
moel@1
|
194 |
value |= ReadByte(FAN_TACHOMETER_EXT_REG[sensor.Index]) << 8;
|
moel@1
|
195 |
|
moel@1
|
196 |
if (value > 0) {
|
moel@1
|
197 |
sensor.Value = (value < 0xffff) ? 1.35e6f / ((value) * 2) : 0;
|
moel@1
|
198 |
ActivateSensor(sensor);
|
moel@1
|
199 |
} else {
|
moel@1
|
200 |
DeactivateSensor(sensor);
|
moel@1
|
201 |
}
|
moel@1
|
202 |
}
|
moel@1
|
203 |
}
|
moel@1
|
204 |
|
moel@1
|
205 |
private void ActivateSensor(Sensor sensor) {
|
moel@1
|
206 |
if (!active.Contains(sensor)) {
|
moel@1
|
207 |
active.Add(sensor);
|
moel@1
|
208 |
SensorAdded(sensor);
|
moel@1
|
209 |
}
|
moel@1
|
210 |
}
|
moel@1
|
211 |
|
moel@1
|
212 |
private void DeactivateSensor(Sensor sensor) {
|
moel@1
|
213 |
if (active.Contains(sensor)) {
|
moel@1
|
214 |
active.Remove(sensor);
|
moel@1
|
215 |
SensorRemoved(sensor);
|
moel@1
|
216 |
}
|
moel@1
|
217 |
}
|
moel@1
|
218 |
|
moel@1
|
219 |
public event SensorEventHandler SensorAdded;
|
moel@1
|
220 |
public event SensorEventHandler SensorRemoved;
|
moel@1
|
221 |
|
moel@1
|
222 |
}
|
moel@1
|
223 |
}
|