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.Text;
|
moel@1
|
41 |
using System.Threading;
|
moel@1
|
42 |
|
moel@1
|
43 |
namespace OpenHardwareMonitor.Hardware.LPC {
|
moel@1
|
44 |
public class LPCGroup : IGroup {
|
moel@67
|
45 |
|
moel@1
|
46 |
private List<IHardware> hardware = new List<IHardware>();
|
moel@67
|
47 |
private StringBuilder report = new StringBuilder();
|
moel@1
|
48 |
|
moel@1
|
49 |
private Chip chip = Chip.Unknown;
|
moel@1
|
50 |
|
moel@1
|
51 |
// I/O Ports
|
moel@7
|
52 |
private ushort[] REGISTER_PORTS = new ushort[] { 0x2e, 0x4e };
|
moel@7
|
53 |
private ushort[] VALUE_PORTS = new ushort[] { 0x2f, 0x4f };
|
moel@7
|
54 |
|
moel@7
|
55 |
private ushort registerPort;
|
moel@7
|
56 |
private ushort valuePort;
|
moel@1
|
57 |
|
moel@1
|
58 |
// Registers
|
moel@1
|
59 |
private const byte CONFIGURATION_CONTROL_REGISTER = 0x02;
|
moel@1
|
60 |
private const byte DEVCIE_SELECT_REGISTER = 0x07;
|
moel@1
|
61 |
private const byte CHIP_ID_REGISTER = 0x20;
|
moel@1
|
62 |
private const byte CHIP_REVISION_REGISTER = 0x21;
|
moel@7
|
63 |
private const byte BASE_ADDRESS_REGISTER = 0x60;
|
moel@1
|
64 |
|
moel@7
|
65 |
private byte ReadByte(byte register) {
|
moel@7
|
66 |
WinRing0.WriteIoPortByte(registerPort, register);
|
moel@7
|
67 |
return WinRing0.ReadIoPortByte(valuePort);
|
moel@13
|
68 |
}
|
moel@1
|
69 |
|
moel@7
|
70 |
private ushort ReadWord(byte register) {
|
moel@7
|
71 |
return (ushort)((ReadByte(register) << 8) |
|
moel@7
|
72 |
ReadByte((byte)(register + 1)));
|
moel@1
|
73 |
}
|
moel@1
|
74 |
|
moel@7
|
75 |
private void Select(byte logicalDeviceNumber) {
|
moel@7
|
76 |
WinRing0.WriteIoPortByte(registerPort, DEVCIE_SELECT_REGISTER);
|
moel@7
|
77 |
WinRing0.WriteIoPortByte(valuePort, logicalDeviceNumber);
|
moel@1
|
78 |
}
|
moel@1
|
79 |
|
moel@34
|
80 |
// ITE
|
moel@7
|
81 |
private const byte IT87_ENVIRONMENT_CONTROLLER_LDN = 0x04;
|
moel@1
|
82 |
|
moel@7
|
83 |
private void IT87Enter() {
|
moel@7
|
84 |
WinRing0.WriteIoPortByte(registerPort, 0x87);
|
moel@7
|
85 |
WinRing0.WriteIoPortByte(registerPort, 0x01);
|
moel@7
|
86 |
WinRing0.WriteIoPortByte(registerPort, 0x55);
|
moel@7
|
87 |
WinRing0.WriteIoPortByte(registerPort, 0x55);
|
moel@1
|
88 |
}
|
moel@1
|
89 |
|
moel@7
|
90 |
internal void IT87Exit() {
|
moel@7
|
91 |
WinRing0.WriteIoPortByte(registerPort, CONFIGURATION_CONTROL_REGISTER);
|
moel@7
|
92 |
WinRing0.WriteIoPortByte(valuePort, 0x02);
|
moel@1
|
93 |
}
|
moel@1
|
94 |
|
moel@7
|
95 |
// Winbond, Fintek
|
moel@7
|
96 |
private const byte FINTEK_VENDOR_ID_REGISTER = 0x23;
|
moel@7
|
97 |
private const ushort FINTEK_VENDOR_ID = 0x1934;
|
moel@7
|
98 |
|
moel@34
|
99 |
private const byte WINBOND_HARDWARE_MONITOR_LDN = 0x0B;
|
moel@16
|
100 |
|
moel@16
|
101 |
private const byte F71858_HARDWARE_MONITOR_LDN = 0x02;
|
moel@16
|
102 |
private const byte FINTEK_HARDWARE_MONITOR_LDN = 0x04;
|
moel@7
|
103 |
|
moel@7
|
104 |
private void WinbondFintekEnter() {
|
moel@7
|
105 |
WinRing0.WriteIoPortByte(registerPort, 0x87);
|
moel@7
|
106 |
WinRing0.WriteIoPortByte(registerPort, 0x87);
|
moel@1
|
107 |
}
|
moel@1
|
108 |
|
moel@7
|
109 |
private void WinbondFintekExit() {
|
moel@7
|
110 |
WinRing0.WriteIoPortByte(registerPort, 0xAA);
|
moel@1
|
111 |
}
|
moel@1
|
112 |
|
moel@67
|
113 |
// SMSC
|
moel@67
|
114 |
private void SMSCEnter() {
|
moel@67
|
115 |
WinRing0.WriteIoPortByte(registerPort, 0x55);
|
moel@67
|
116 |
}
|
moel@67
|
117 |
|
moel@67
|
118 |
private void SMSCExit() {
|
moel@67
|
119 |
WinRing0.WriteIoPortByte(registerPort, 0xAA);
|
moel@67
|
120 |
}
|
moel@67
|
121 |
|
moel@1
|
122 |
public LPCGroup() {
|
moel@1
|
123 |
if (!WinRing0.IsAvailable)
|
moel@1
|
124 |
return;
|
moel@1
|
125 |
|
moel@7
|
126 |
for (int i = 0; i < REGISTER_PORTS.Length; i++) {
|
moel@7
|
127 |
registerPort = REGISTER_PORTS[i];
|
moel@7
|
128 |
valuePort = VALUE_PORTS[i];
|
moel@1
|
129 |
|
moel@7
|
130 |
WinbondFintekEnter();
|
moel@1
|
131 |
|
moel@16
|
132 |
byte logicalDeviceNumber;
|
moel@7
|
133 |
byte id = ReadByte(CHIP_ID_REGISTER);
|
moel@7
|
134 |
byte revision = ReadByte(CHIP_REVISION_REGISTER);
|
moel@34
|
135 |
chip = Chip.Unknown;
|
moel@34
|
136 |
logicalDeviceNumber = 0;
|
moel@7
|
137 |
switch (id) {
|
moel@16
|
138 |
case 0x05:
|
moel@16
|
139 |
switch (revision) {
|
moel@68
|
140 |
case 0x07:
|
moel@68
|
141 |
chip = Chip.F71858;
|
moel@68
|
142 |
logicalDeviceNumber = F71858_HARDWARE_MONITOR_LDN;
|
moel@68
|
143 |
break;
|
moel@16
|
144 |
case 0x41:
|
moel@16
|
145 |
chip = Chip.F71882;
|
moel@16
|
146 |
logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
|
moel@34
|
147 |
break;
|
moel@16
|
148 |
} break;
|
moel@16
|
149 |
case 0x06:
|
moel@16
|
150 |
switch (revision) {
|
moel@16
|
151 |
case 0x01:
|
moel@16
|
152 |
chip = Chip.F71862;
|
moel@16
|
153 |
logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
|
moel@34
|
154 |
break;
|
moel@16
|
155 |
} break;
|
moel@16
|
156 |
case 0x07:
|
moel@16
|
157 |
switch (revision) {
|
moel@16
|
158 |
case 0x23:
|
moel@103
|
159 |
chip = Chip.F71889F;
|
moel@16
|
160 |
logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
|
moel@34
|
161 |
break;
|
moel@16
|
162 |
} break;
|
moel@16
|
163 |
case 0x08:
|
moel@16
|
164 |
switch (revision) {
|
moel@16
|
165 |
case 0x14:
|
moel@16
|
166 |
chip = Chip.F71869;
|
moel@16
|
167 |
logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
|
moel@34
|
168 |
break;
|
moel@16
|
169 |
} break;
|
moel@103
|
170 |
case 0x09:
|
moel@103
|
171 |
switch (revision) {
|
moel@103
|
172 |
case 0x09:
|
moel@103
|
173 |
chip = Chip.F71889ED;
|
moel@103
|
174 |
logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
|
moel@103
|
175 |
break;
|
moel@103
|
176 |
} break;
|
moel@31
|
177 |
case 0x52:
|
moel@31
|
178 |
switch (revision) {
|
moel@31
|
179 |
case 0x17:
|
moel@31
|
180 |
case 0x3A:
|
moel@92
|
181 |
case 0x41:
|
moel@31
|
182 |
chip = Chip.W83627HF;
|
moel@34
|
183 |
logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
|
moel@34
|
184 |
break;
|
moel@34
|
185 |
} break;
|
moel@54
|
186 |
case 0x82:
|
moel@54
|
187 |
switch (revision) {
|
moel@54
|
188 |
case 0x83:
|
moel@54
|
189 |
chip = Chip.W83627THF;
|
moel@54
|
190 |
logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
|
moel@54
|
191 |
break;
|
moel@54
|
192 |
} break;
|
moel@67
|
193 |
case 0x85:
|
moel@67
|
194 |
switch (revision) {
|
moel@67
|
195 |
case 0x41:
|
moel@67
|
196 |
chip = Chip.W83687THF;
|
moel@67
|
197 |
logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
|
moel@67
|
198 |
break;
|
moel@67
|
199 |
} break;
|
moel@34
|
200 |
case 0x88:
|
moel@34
|
201 |
switch (revision & 0xF0) {
|
moel@34
|
202 |
case 0x60:
|
moel@34
|
203 |
chip = Chip.W83627EHF;
|
moel@34
|
204 |
logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
|
moel@31
|
205 |
break;
|
moel@31
|
206 |
} break;
|
moel@7
|
207 |
case 0xA0:
|
moel@7
|
208 |
switch (revision & 0xF0) {
|
moel@7
|
209 |
case 0x20:
|
moel@7
|
210 |
chip = Chip.W83627DHG;
|
moel@34
|
211 |
logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
|
moel@34
|
212 |
break;
|
moel@34
|
213 |
} break;
|
moel@34
|
214 |
case 0xA5:
|
moel@34
|
215 |
switch (revision & 0xF0) {
|
moel@34
|
216 |
case 0x10:
|
moel@34
|
217 |
chip = Chip.W83667HG;
|
moel@34
|
218 |
logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
|
moel@7
|
219 |
break;
|
moel@19
|
220 |
} break;
|
moel@19
|
221 |
case 0xB0:
|
moel@19
|
222 |
switch (revision & 0xF0) {
|
moel@19
|
223 |
case 0x70:
|
moel@19
|
224 |
chip = Chip.W83627DHGP;
|
moel@34
|
225 |
logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
|
moel@34
|
226 |
break;
|
moel@34
|
227 |
} break;
|
moel@34
|
228 |
case 0xB3:
|
moel@34
|
229 |
switch (revision & 0xF0) {
|
moel@34
|
230 |
case 0x50:
|
moel@34
|
231 |
chip = Chip.W83667HGB;
|
moel@34
|
232 |
logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
|
moel@19
|
233 |
break;
|
moel@34
|
234 |
} break;
|
moel@7
|
235 |
}
|
moel@67
|
236 |
if (chip == Chip.Unknown) {
|
moel@67
|
237 |
if (id != 0 && id != 0xff) {
|
moel@67
|
238 |
WinbondFintekExit();
|
moel@67
|
239 |
|
moel@67
|
240 |
report.Append("Chip ID: Unknown Winbond / Fintek with ID 0x");
|
moel@67
|
241 |
report.AppendLine(((id << 8) | revision).ToString("X"));
|
moel@67
|
242 |
report.AppendLine();
|
moel@67
|
243 |
}
|
moel@67
|
244 |
} else {
|
moel@1
|
245 |
|
moel@16
|
246 |
Select(logicalDeviceNumber);
|
moel@60
|
247 |
ushort address = ReadWord(BASE_ADDRESS_REGISTER);
|
moel@7
|
248 |
Thread.Sleep(1);
|
moel@7
|
249 |
ushort verify = ReadWord(BASE_ADDRESS_REGISTER);
|
moel@68
|
250 |
|
moel@103
|
251 |
ushort vendorID = ReadWord(FINTEK_VENDOR_ID_REGISTER);
|
moel@1
|
252 |
|
moel@7
|
253 |
WinbondFintekExit();
|
moel@1
|
254 |
|
moel@67
|
255 |
if (address != verify) {
|
moel@67
|
256 |
report.Append("Chip ID: 0x");
|
moel@67
|
257 |
report.AppendLine(chip.ToString("X"));
|
moel@67
|
258 |
report.Append("Chip revision: 0x");
|
moel@67
|
259 |
report.AppendLine(revision.ToString("X"));
|
moel@67
|
260 |
report.AppendLine("Error: Address verification failed");
|
moel@67
|
261 |
report.AppendLine();
|
moel@60
|
262 |
return;
|
moel@67
|
263 |
}
|
moel@60
|
264 |
|
moel@60
|
265 |
// some Fintek chips have address register offset 0x05 added already
|
moel@60
|
266 |
if ((address & 0x07) == 0x05)
|
moel@60
|
267 |
address &= 0xFFF8;
|
moel@60
|
268 |
|
moel@67
|
269 |
if (address < 0x100 || (address & 0xF007) != 0) {
|
moel@67
|
270 |
report.Append("Chip ID: 0x");
|
moel@67
|
271 |
report.AppendLine(chip.ToString("X"));
|
moel@67
|
272 |
report.Append("Chip revision: 0x");
|
moel@67
|
273 |
report.AppendLine(revision.ToString("X"));
|
moel@67
|
274 |
report.Append("Error: Invalid address 0x");
|
moel@67
|
275 |
report.AppendLine(address.ToString("X"));
|
moel@67
|
276 |
report.AppendLine();
|
moel@7
|
277 |
return;
|
moel@67
|
278 |
}
|
moel@67
|
279 |
|
moel@7
|
280 |
switch (chip) {
|
moel@7
|
281 |
case Chip.W83627DHG:
|
moel@19
|
282 |
case Chip.W83627DHGP:
|
moel@34
|
283 |
case Chip.W83627EHF:
|
moel@31
|
284 |
case Chip.W83627HF:
|
moel@54
|
285 |
case Chip.W83627THF:
|
moel@34
|
286 |
case Chip.W83667HG:
|
moel@34
|
287 |
case Chip.W83667HGB:
|
moel@67
|
288 |
case Chip.W83687THF:
|
moel@34
|
289 |
W836XX w836XX = new W836XX(chip, revision, address);
|
moel@34
|
290 |
if (w836XX.IsAvailable)
|
moel@34
|
291 |
hardware.Add(w836XX);
|
moel@7
|
292 |
break;
|
moel@68
|
293 |
case Chip.F71858:
|
moel@16
|
294 |
case Chip.F71862:
|
moel@103
|
295 |
case Chip.F71869:
|
moel@16
|
296 |
case Chip.F71882:
|
moel@103
|
297 |
case Chip.F71889ED:
|
moel@103
|
298 |
case Chip.F71889F:
|
moel@103
|
299 |
if (vendorID != FINTEK_VENDOR_ID) {
|
moel@103
|
300 |
report.Append("Chip ID: 0x");
|
moel@103
|
301 |
report.AppendLine(chip.ToString("X"));
|
moel@103
|
302 |
report.Append("Chip revision: 0x");
|
moel@103
|
303 |
report.AppendLine(revision.ToString("X"));
|
moel@103
|
304 |
report.Append("Error: Invalid vendor ID 0x");
|
moel@103
|
305 |
report.AppendLine(vendorID.ToString("X"));
|
moel@103
|
306 |
report.AppendLine();
|
moel@103
|
307 |
return;
|
moel@103
|
308 |
}
|
moel@16
|
309 |
hardware.Add(new F718XX(chip, address));
|
moel@7
|
310 |
break;
|
moel@7
|
311 |
default: break;
|
moel@7
|
312 |
}
|
moel@7
|
313 |
|
moel@7
|
314 |
return;
|
moel@7
|
315 |
}
|
moel@1
|
316 |
|
moel@7
|
317 |
IT87Enter();
|
moel@1
|
318 |
|
moel@67
|
319 |
ushort chipID = ReadWord(CHIP_ID_REGISTER);
|
moel@67
|
320 |
switch (chipID) {
|
moel@93
|
321 |
case 0x8712: chip = Chip.IT8712F; break;
|
moel@21
|
322 |
case 0x8716: chip = Chip.IT8716F; break;
|
moel@21
|
323 |
case 0x8718: chip = Chip.IT8718F; break;
|
moel@21
|
324 |
case 0x8720: chip = Chip.IT8720F; break;
|
moel@67
|
325 |
case 0x8726: chip = Chip.IT8726F; break;
|
moel@7
|
326 |
default: chip = Chip.Unknown; break;
|
moel@7
|
327 |
}
|
moel@67
|
328 |
if (chip == Chip.Unknown) {
|
moel@67
|
329 |
if (chipID != 0 && chipID != 0xffff) {
|
moel@67
|
330 |
IT87Exit();
|
moel@7
|
331 |
|
moel@67
|
332 |
report.Append("Chip ID: Unknown ITE with ID 0x");
|
moel@67
|
333 |
report.AppendLine(chipID.ToString("X"));
|
moel@67
|
334 |
report.AppendLine();
|
moel@67
|
335 |
}
|
moel@67
|
336 |
} else {
|
moel@7
|
337 |
Select(IT87_ENVIRONMENT_CONTROLLER_LDN);
|
moel@7
|
338 |
ushort address = ReadWord(BASE_ADDRESS_REGISTER);
|
moel@7
|
339 |
Thread.Sleep(1);
|
moel@7
|
340 |
ushort verify = ReadWord(BASE_ADDRESS_REGISTER);
|
moel@7
|
341 |
|
moel@7
|
342 |
IT87Exit();
|
moel@7
|
343 |
|
moel@67
|
344 |
if (address != verify || address < 0x100 || (address & 0xF007) != 0) {
|
moel@67
|
345 |
report.Append("Chip ID: 0x");
|
moel@67
|
346 |
report.AppendLine(chip.ToString("X"));
|
moel@67
|
347 |
report.Append("Error: Invalid address 0x");
|
moel@67
|
348 |
report.AppendLine(address.ToString("X"));
|
moel@67
|
349 |
report.AppendLine();
|
moel@7
|
350 |
return;
|
moel@67
|
351 |
}
|
moel@7
|
352 |
|
moel@16
|
353 |
IT87XX it87 = new IT87XX(chip, address);
|
moel@7
|
354 |
if (it87.IsAvailable)
|
moel@7
|
355 |
hardware.Add(it87);
|
moel@7
|
356 |
|
moel@1
|
357 |
return;
|
moel@7
|
358 |
}
|
moel@67
|
359 |
|
moel@67
|
360 |
SMSCEnter();
|
moel@67
|
361 |
|
moel@67
|
362 |
chipID = ReadWord(CHIP_ID_REGISTER);
|
moel@67
|
363 |
switch (chipID) {
|
moel@67
|
364 |
default: chip = Chip.Unknown; break;
|
moel@67
|
365 |
}
|
moel@67
|
366 |
if (chip == Chip.Unknown) {
|
moel@67
|
367 |
if (chipID != 0 && chipID != 0xffff) {
|
moel@67
|
368 |
SMSCExit();
|
moel@67
|
369 |
|
moel@67
|
370 |
report.Append("Chip ID: Unknown SMSC with ID 0x");
|
moel@67
|
371 |
report.AppendLine(chipID.ToString("X"));
|
moel@67
|
372 |
report.AppendLine();
|
moel@67
|
373 |
}
|
moel@67
|
374 |
} else {
|
moel@67
|
375 |
SMSCExit();
|
moel@67
|
376 |
|
moel@67
|
377 |
return;
|
moel@67
|
378 |
}
|
moel@7
|
379 |
}
|
moel@1
|
380 |
}
|
moel@1
|
381 |
|
moel@1
|
382 |
public IHardware[] Hardware {
|
moel@1
|
383 |
get {
|
moel@1
|
384 |
return hardware.ToArray();
|
moel@1
|
385 |
}
|
moel@1
|
386 |
}
|
moel@1
|
387 |
|
moel@1
|
388 |
public string GetReport() {
|
moel@67
|
389 |
if (report.Length > 0) {
|
moel@67
|
390 |
report.Insert(0, "LPCIO" + Environment.NewLine +
|
moel@67
|
391 |
Environment.NewLine);
|
moel@67
|
392 |
return report.ToString();
|
moel@67
|
393 |
} else
|
moel@67
|
394 |
return null;
|
moel@1
|
395 |
}
|
moel@1
|
396 |
|
moel@1
|
397 |
public void Close() { }
|
moel@1
|
398 |
}
|
moel@1
|
399 |
}
|