moel@110
|
1 |
/*
|
moel@110
|
2 |
|
moel@344
|
3 |
This Source Code Form is subject to the terms of the Mozilla Public
|
moel@344
|
4 |
License, v. 2.0. If a copy of the MPL was not distributed with this
|
moel@344
|
5 |
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
moel@110
|
6 |
|
moel@408
|
7 |
Copyright (C) 2009-2013 Michael Möller <mmoeller@openhardwaremonitor.org>
|
moel@344
|
8 |
|
moel@110
|
9 |
*/
|
moel@110
|
10 |
|
moel@110
|
11 |
using System;
|
moel@110
|
12 |
using System.Collections.Generic;
|
moel@166
|
13 |
using System.Globalization;
|
moel@110
|
14 |
using System.Text;
|
moel@110
|
15 |
using System.Threading;
|
moel@110
|
16 |
|
moel@110
|
17 |
namespace OpenHardwareMonitor.Hardware.LPC {
|
moel@165
|
18 |
internal class LPCIO {
|
moel@110
|
19 |
|
moel@195
|
20 |
private readonly List<ISuperIO> superIOs = new List<ISuperIO>();
|
moel@195
|
21 |
private readonly StringBuilder report = new StringBuilder();
|
moel@110
|
22 |
|
moel@110
|
23 |
// I/O Ports
|
moel@195
|
24 |
private readonly ushort[] REGISTER_PORTS = new ushort[] { 0x2E, 0x4E };
|
moel@195
|
25 |
private readonly ushort[] VALUE_PORTS = new ushort[] { 0x2F, 0x4F };
|
moel@110
|
26 |
|
moel@110
|
27 |
private ushort registerPort;
|
moel@110
|
28 |
private ushort valuePort;
|
moel@110
|
29 |
|
moel@110
|
30 |
// Registers
|
moel@110
|
31 |
private const byte CONFIGURATION_CONTROL_REGISTER = 0x02;
|
moel@110
|
32 |
private const byte DEVCIE_SELECT_REGISTER = 0x07;
|
moel@110
|
33 |
private const byte CHIP_ID_REGISTER = 0x20;
|
moel@110
|
34 |
private const byte CHIP_REVISION_REGISTER = 0x21;
|
moel@110
|
35 |
private const byte BASE_ADDRESS_REGISTER = 0x60;
|
moel@110
|
36 |
|
moel@110
|
37 |
private byte ReadByte(byte register) {
|
moel@236
|
38 |
Ring0.WriteIoPort(registerPort, register);
|
moel@236
|
39 |
return Ring0.ReadIoPort(valuePort);
|
moel@228
|
40 |
}
|
moel@110
|
41 |
|
moel@110
|
42 |
private ushort ReadWord(byte register) {
|
moel@228
|
43 |
return (ushort)((ReadByte(register) << 8) |
|
moel@110
|
44 |
ReadByte((byte)(register + 1)));
|
moel@110
|
45 |
}
|
moel@110
|
46 |
|
moel@110
|
47 |
private void Select(byte logicalDeviceNumber) {
|
moel@236
|
48 |
Ring0.WriteIoPort(registerPort, DEVCIE_SELECT_REGISTER);
|
moel@236
|
49 |
Ring0.WriteIoPort(valuePort, logicalDeviceNumber);
|
moel@110
|
50 |
}
|
moel@110
|
51 |
|
moel@169
|
52 |
private void ReportUnknownChip(string type, int chip) {
|
moel@169
|
53 |
report.Append("Chip ID: Unknown ");
|
moel@169
|
54 |
report.Append(type);
|
moel@169
|
55 |
report.Append(" with ID 0x");
|
moel@169
|
56 |
report.Append(chip.ToString("X", CultureInfo.InvariantCulture));
|
moel@169
|
57 |
report.Append(" at 0x");
|
moel@169
|
58 |
report.Append(registerPort.ToString("X", CultureInfo.InvariantCulture));
|
moel@169
|
59 |
report.Append("/0x");
|
moel@169
|
60 |
report.AppendLine(valuePort.ToString("X", CultureInfo.InvariantCulture));
|
moel@169
|
61 |
report.AppendLine();
|
moel@110
|
62 |
}
|
moel@110
|
63 |
|
moel@245
|
64 |
#region Winbond, Nuvoton, Fintek
|
moel@110
|
65 |
|
moel@110
|
66 |
private const byte FINTEK_VENDOR_ID_REGISTER = 0x23;
|
moel@110
|
67 |
private const ushort FINTEK_VENDOR_ID = 0x1934;
|
moel@110
|
68 |
|
moel@245
|
69 |
private const byte WINBOND_NUVOTON_HARDWARE_MONITOR_LDN = 0x0B;
|
moel@110
|
70 |
|
moel@110
|
71 |
private const byte F71858_HARDWARE_MONITOR_LDN = 0x02;
|
moel@110
|
72 |
private const byte FINTEK_HARDWARE_MONITOR_LDN = 0x04;
|
moel@110
|
73 |
|
moel@245
|
74 |
private void WinbondNuvotonFintekEnter() {
|
moel@236
|
75 |
Ring0.WriteIoPort(registerPort, 0x87);
|
moel@236
|
76 |
Ring0.WriteIoPort(registerPort, 0x87);
|
moel@110
|
77 |
}
|
moel@110
|
78 |
|
moel@245
|
79 |
private void WinbondNuvotonFintekExit() {
|
moel@236
|
80 |
Ring0.WriteIoPort(registerPort, 0xAA);
|
moel@110
|
81 |
}
|
moel@110
|
82 |
|
moel@167
|
83 |
private bool DetectWinbondFintek() {
|
moel@245
|
84 |
WinbondNuvotonFintekEnter();
|
moel@167
|
85 |
|
moel@195
|
86 |
byte logicalDeviceNumber = 0;
|
moel@167
|
87 |
byte id = ReadByte(CHIP_ID_REGISTER);
|
moel@167
|
88 |
byte revision = ReadByte(CHIP_REVISION_REGISTER);
|
moel@167
|
89 |
Chip chip = Chip.Unknown;
|
moel@167
|
90 |
switch (id) {
|
moel@167
|
91 |
case 0x05:
|
moel@167
|
92 |
switch (revision) {
|
moel@167
|
93 |
case 0x07:
|
moel@167
|
94 |
chip = Chip.F71858;
|
moel@167
|
95 |
logicalDeviceNumber = F71858_HARDWARE_MONITOR_LDN;
|
moel@167
|
96 |
break;
|
moel@167
|
97 |
case 0x41:
|
moel@167
|
98 |
chip = Chip.F71882;
|
moel@167
|
99 |
logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
|
moel@167
|
100 |
break;
|
moel@167
|
101 |
} break;
|
moel@167
|
102 |
case 0x06:
|
moel@167
|
103 |
switch (revision) {
|
moel@167
|
104 |
case 0x01:
|
moel@167
|
105 |
chip = Chip.F71862;
|
moel@167
|
106 |
logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
|
moel@167
|
107 |
break;
|
moel@167
|
108 |
} break;
|
moel@167
|
109 |
case 0x07:
|
moel@167
|
110 |
switch (revision) {
|
moel@167
|
111 |
case 0x23:
|
moel@167
|
112 |
chip = Chip.F71889F;
|
moel@167
|
113 |
logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
|
moel@167
|
114 |
break;
|
moel@167
|
115 |
} break;
|
moel@167
|
116 |
case 0x08:
|
moel@167
|
117 |
switch (revision) {
|
moel@167
|
118 |
case 0x14:
|
moel@167
|
119 |
chip = Chip.F71869;
|
moel@167
|
120 |
logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
|
moel@167
|
121 |
break;
|
moel@167
|
122 |
} break;
|
moel@167
|
123 |
case 0x09:
|
moel@167
|
124 |
switch (revision) {
|
moel@352
|
125 |
case 0x01:
|
moel@352
|
126 |
chip = Chip.F71808E;
|
moel@352
|
127 |
logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
|
moel@352
|
128 |
break;
|
moel@167
|
129 |
case 0x09:
|
moel@167
|
130 |
chip = Chip.F71889ED;
|
moel@167
|
131 |
logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
|
moel@167
|
132 |
break;
|
moel@167
|
133 |
} break;
|
moel@296
|
134 |
case 0x10:
|
moel@296
|
135 |
switch (revision) {
|
moel@296
|
136 |
case 0x05:
|
moel@296
|
137 |
chip = Chip.F71889AD;
|
moel@296
|
138 |
logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
|
moel@296
|
139 |
break;
|
moel@408
|
140 |
case 0x07:
|
moel@408
|
141 |
chip = Chip.F71869A;
|
moel@408
|
142 |
logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
|
moel@408
|
143 |
break;
|
moel@296
|
144 |
} break;
|
moel@167
|
145 |
case 0x52:
|
moel@167
|
146 |
switch (revision) {
|
moel@167
|
147 |
case 0x17:
|
moel@167
|
148 |
case 0x3A:
|
moel@167
|
149 |
case 0x41:
|
moel@167
|
150 |
chip = Chip.W83627HF;
|
moel@245
|
151 |
logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
|
moel@167
|
152 |
break;
|
moel@167
|
153 |
} break;
|
moel@167
|
154 |
case 0x82:
|
moel@167
|
155 |
switch (revision & 0xF0) {
|
moel@167
|
156 |
case 0x80:
|
moel@167
|
157 |
chip = Chip.W83627THF;
|
moel@245
|
158 |
logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
|
moel@167
|
159 |
break;
|
moel@167
|
160 |
} break;
|
moel@167
|
161 |
case 0x85:
|
moel@167
|
162 |
switch (revision) {
|
moel@167
|
163 |
case 0x41:
|
moel@167
|
164 |
chip = Chip.W83687THF;
|
moel@245
|
165 |
logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
|
moel@167
|
166 |
break;
|
moel@167
|
167 |
} break;
|
moel@167
|
168 |
case 0x88:
|
moel@167
|
169 |
switch (revision & 0xF0) {
|
moel@167
|
170 |
case 0x50:
|
moel@167
|
171 |
case 0x60:
|
moel@167
|
172 |
chip = Chip.W83627EHF;
|
moel@245
|
173 |
logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
|
moel@167
|
174 |
break;
|
moel@167
|
175 |
} break;
|
moel@167
|
176 |
case 0xA0:
|
moel@167
|
177 |
switch (revision & 0xF0) {
|
moel@167
|
178 |
case 0x20:
|
moel@167
|
179 |
chip = Chip.W83627DHG;
|
moel@245
|
180 |
logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
|
moel@167
|
181 |
break;
|
moel@167
|
182 |
} break;
|
moel@167
|
183 |
case 0xA5:
|
moel@167
|
184 |
switch (revision & 0xF0) {
|
moel@167
|
185 |
case 0x10:
|
moel@167
|
186 |
chip = Chip.W83667HG;
|
moel@245
|
187 |
logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
|
moel@167
|
188 |
break;
|
moel@167
|
189 |
} break;
|
moel@167
|
190 |
case 0xB0:
|
moel@167
|
191 |
switch (revision & 0xF0) {
|
moel@167
|
192 |
case 0x70:
|
moel@167
|
193 |
chip = Chip.W83627DHGP;
|
moel@245
|
194 |
logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
|
moel@167
|
195 |
break;
|
moel@167
|
196 |
} break;
|
moel@167
|
197 |
case 0xB3:
|
moel@167
|
198 |
switch (revision & 0xF0) {
|
moel@167
|
199 |
case 0x50:
|
moel@167
|
200 |
chip = Chip.W83667HGB;
|
moel@245
|
201 |
logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
|
moel@245
|
202 |
break;
|
moel@245
|
203 |
} break;
|
moel@245
|
204 |
case 0xB4:
|
moel@245
|
205 |
switch (revision & 0xF0) {
|
moel@245
|
206 |
case 0x70:
|
moel@245
|
207 |
chip = Chip.NCT6771F;
|
moel@245
|
208 |
logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
|
moel@167
|
209 |
break;
|
moel@167
|
210 |
} break;
|
moel@265
|
211 |
case 0xC3:
|
moel@265
|
212 |
switch (revision & 0xF0) {
|
moel@265
|
213 |
case 0x30:
|
moel@265
|
214 |
chip = Chip.NCT6776F;
|
moel@265
|
215 |
logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
|
moel@265
|
216 |
break;
|
moel@265
|
217 |
} break;
|
moel@355
|
218 |
case 0xC5:
|
moel@355
|
219 |
switch (revision & 0xF0) {
|
moel@355
|
220 |
case 0x60:
|
moel@355
|
221 |
chip = Chip.NCT6779D;
|
moel@355
|
222 |
logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
|
moel@355
|
223 |
break;
|
moel@355
|
224 |
} break;
|
moel@413
|
225 |
case 0xC8:
|
moel@413
|
226 |
switch (revision) {
|
moel@413
|
227 |
case 0x03:
|
moel@413
|
228 |
chip = Chip.NCT6791D;
|
moel@413
|
229 |
logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
|
moel@413
|
230 |
break;
|
moel@413
|
231 |
} break;
|
moel@167
|
232 |
}
|
moel@167
|
233 |
if (chip == Chip.Unknown) {
|
moel@167
|
234 |
if (id != 0 && id != 0xff) {
|
moel@245
|
235 |
WinbondNuvotonFintekExit();
|
moel@167
|
236 |
|
moel@245
|
237 |
ReportUnknownChip("Winbond / Nuvoton / Fintek",
|
moel@245
|
238 |
((id << 8) | revision));
|
moel@167
|
239 |
}
|
moel@167
|
240 |
} else {
|
moel@167
|
241 |
|
moel@167
|
242 |
Select(logicalDeviceNumber);
|
moel@167
|
243 |
ushort address = ReadWord(BASE_ADDRESS_REGISTER);
|
moel@167
|
244 |
Thread.Sleep(1);
|
moel@167
|
245 |
ushort verify = ReadWord(BASE_ADDRESS_REGISTER);
|
moel@167
|
246 |
|
moel@167
|
247 |
ushort vendorID = ReadWord(FINTEK_VENDOR_ID_REGISTER);
|
moel@167
|
248 |
|
moel@245
|
249 |
WinbondNuvotonFintekExit();
|
moel@167
|
250 |
|
moel@167
|
251 |
if (address != verify) {
|
moel@167
|
252 |
report.Append("Chip ID: 0x");
|
moel@167
|
253 |
report.AppendLine(chip.ToString("X"));
|
moel@167
|
254 |
report.Append("Chip revision: 0x");
|
moel@228
|
255 |
report.AppendLine(revision.ToString("X",
|
moel@167
|
256 |
CultureInfo.InvariantCulture));
|
moel@167
|
257 |
report.AppendLine("Error: Address verification failed");
|
moel@167
|
258 |
report.AppendLine();
|
moel@167
|
259 |
return false;
|
moel@167
|
260 |
}
|
moel@167
|
261 |
|
moel@167
|
262 |
// some Fintek chips have address register offset 0x05 added already
|
moel@167
|
263 |
if ((address & 0x07) == 0x05)
|
moel@167
|
264 |
address &= 0xFFF8;
|
moel@167
|
265 |
|
moel@167
|
266 |
if (address < 0x100 || (address & 0xF007) != 0) {
|
moel@167
|
267 |
report.Append("Chip ID: 0x");
|
moel@167
|
268 |
report.AppendLine(chip.ToString("X"));
|
moel@167
|
269 |
report.Append("Chip revision: 0x");
|
moel@228
|
270 |
report.AppendLine(revision.ToString("X",
|
moel@167
|
271 |
CultureInfo.InvariantCulture));
|
moel@167
|
272 |
report.Append("Error: Invalid address 0x");
|
moel@228
|
273 |
report.AppendLine(address.ToString("X",
|
moel@167
|
274 |
CultureInfo.InvariantCulture));
|
moel@167
|
275 |
report.AppendLine();
|
moel@167
|
276 |
return false;
|
moel@167
|
277 |
}
|
moel@167
|
278 |
|
moel@167
|
279 |
switch (chip) {
|
moel@167
|
280 |
case Chip.W83627DHG:
|
moel@167
|
281 |
case Chip.W83627DHGP:
|
moel@167
|
282 |
case Chip.W83627EHF:
|
moel@167
|
283 |
case Chip.W83627HF:
|
moel@167
|
284 |
case Chip.W83627THF:
|
moel@167
|
285 |
case Chip.W83667HG:
|
moel@167
|
286 |
case Chip.W83667HGB:
|
moel@167
|
287 |
case Chip.W83687THF:
|
moel@167
|
288 |
superIOs.Add(new W836XX(chip, revision, address));
|
moel@167
|
289 |
break;
|
moel@245
|
290 |
case Chip.NCT6771F:
|
moel@265
|
291 |
case Chip.NCT6776F:
|
moel@355
|
292 |
case Chip.NCT6779D:
|
moel@413
|
293 |
case Chip.NCT6791D:
|
moel@245
|
294 |
superIOs.Add(new NCT677X(chip, revision, address));
|
moel@245
|
295 |
break;
|
moel@167
|
296 |
case Chip.F71858:
|
moel@167
|
297 |
case Chip.F71862:
|
moel@167
|
298 |
case Chip.F71869:
|
moel@408
|
299 |
case Chip.F71869A:
|
moel@167
|
300 |
case Chip.F71882:
|
moel@296
|
301 |
case Chip.F71889AD:
|
moel@167
|
302 |
case Chip.F71889ED:
|
moel@167
|
303 |
case Chip.F71889F:
|
moel@352
|
304 |
case Chip.F71808E:
|
moel@167
|
305 |
if (vendorID != FINTEK_VENDOR_ID) {
|
moel@167
|
306 |
report.Append("Chip ID: 0x");
|
moel@167
|
307 |
report.AppendLine(chip.ToString("X"));
|
moel@167
|
308 |
report.Append("Chip revision: 0x");
|
moel@228
|
309 |
report.AppendLine(revision.ToString("X",
|
moel@167
|
310 |
CultureInfo.InvariantCulture));
|
moel@167
|
311 |
report.Append("Error: Invalid vendor ID 0x");
|
moel@228
|
312 |
report.AppendLine(vendorID.ToString("X",
|
moel@167
|
313 |
CultureInfo.InvariantCulture));
|
moel@167
|
314 |
report.AppendLine();
|
moel@167
|
315 |
return false;
|
moel@167
|
316 |
}
|
moel@167
|
317 |
superIOs.Add(new F718XX(chip, address));
|
moel@167
|
318 |
break;
|
moel@167
|
319 |
default: break;
|
moel@167
|
320 |
}
|
moel@167
|
321 |
|
moel@167
|
322 |
return true;
|
moel@167
|
323 |
}
|
moel@167
|
324 |
|
moel@167
|
325 |
return false;
|
moel@167
|
326 |
}
|
moel@167
|
327 |
|
moel@169
|
328 |
#endregion
|
moel@169
|
329 |
|
moel@169
|
330 |
#region ITE
|
moel@169
|
331 |
|
moel@169
|
332 |
private const byte IT87_ENVIRONMENT_CONTROLLER_LDN = 0x04;
|
moel@353
|
333 |
private const byte IT8705_GPIO_LDN = 0x05;
|
moel@353
|
334 |
private const byte IT87XX_GPIO_LDN = 0x07;
|
moel@169
|
335 |
private const byte IT87_CHIP_VERSION_REGISTER = 0x22;
|
moel@169
|
336 |
|
moel@169
|
337 |
private void IT87Enter() {
|
moel@236
|
338 |
Ring0.WriteIoPort(registerPort, 0x87);
|
moel@236
|
339 |
Ring0.WriteIoPort(registerPort, 0x01);
|
moel@236
|
340 |
Ring0.WriteIoPort(registerPort, 0x55);
|
moel@236
|
341 |
Ring0.WriteIoPort(registerPort, 0x55);
|
moel@169
|
342 |
}
|
moel@169
|
343 |
|
moel@169
|
344 |
private void IT87Exit() {
|
moel@236
|
345 |
Ring0.WriteIoPort(registerPort, CONFIGURATION_CONTROL_REGISTER);
|
moel@236
|
346 |
Ring0.WriteIoPort(valuePort, 0x02);
|
moel@169
|
347 |
}
|
moel@169
|
348 |
|
moel@167
|
349 |
private bool DetectIT87() {
|
moel@169
|
350 |
|
moel@169
|
351 |
// IT87XX can enter only on port 0x2E
|
moel@169
|
352 |
if (registerPort != 0x2E)
|
moel@169
|
353 |
return false;
|
moel@169
|
354 |
|
moel@167
|
355 |
IT87Enter();
|
moel@167
|
356 |
|
moel@167
|
357 |
ushort chipID = ReadWord(CHIP_ID_REGISTER);
|
moel@167
|
358 |
Chip chip;
|
moel@167
|
359 |
switch (chipID) {
|
moel@353
|
360 |
case 0x8705: chip = Chip.IT8705F; break;
|
moel@167
|
361 |
case 0x8712: chip = Chip.IT8712F; break;
|
moel@167
|
362 |
case 0x8716: chip = Chip.IT8716F; break;
|
moel@167
|
363 |
case 0x8718: chip = Chip.IT8718F; break;
|
moel@167
|
364 |
case 0x8720: chip = Chip.IT8720F; break;
|
moel@170
|
365 |
case 0x8721: chip = Chip.IT8721F; break;
|
moel@167
|
366 |
case 0x8726: chip = Chip.IT8726F; break;
|
moel@277
|
367 |
case 0x8728: chip = Chip.IT8728F; break;
|
moel@341
|
368 |
case 0x8771: chip = Chip.IT8771E; break;
|
moel@319
|
369 |
case 0x8772: chip = Chip.IT8772E; break;
|
moel@167
|
370 |
default: chip = Chip.Unknown; break;
|
moel@167
|
371 |
}
|
moel@167
|
372 |
if (chip == Chip.Unknown) {
|
moel@167
|
373 |
if (chipID != 0 && chipID != 0xffff) {
|
moel@167
|
374 |
IT87Exit();
|
moel@167
|
375 |
|
moel@167
|
376 |
ReportUnknownChip("ITE", chipID);
|
moel@167
|
377 |
}
|
moel@167
|
378 |
} else {
|
moel@167
|
379 |
Select(IT87_ENVIRONMENT_CONTROLLER_LDN);
|
moel@167
|
380 |
ushort address = ReadWord(BASE_ADDRESS_REGISTER);
|
moel@167
|
381 |
Thread.Sleep(1);
|
moel@167
|
382 |
ushort verify = ReadWord(BASE_ADDRESS_REGISTER);
|
moel@167
|
383 |
|
moel@167
|
384 |
byte version = (byte)(ReadByte(IT87_CHIP_VERSION_REGISTER) & 0x0F);
|
moel@167
|
385 |
|
moel@353
|
386 |
ushort gpioAddress;
|
moel@353
|
387 |
ushort gpioVerify;
|
moel@353
|
388 |
if (chip == Chip.IT8705F) {
|
moel@353
|
389 |
Select(IT8705_GPIO_LDN);
|
moel@353
|
390 |
gpioAddress = ReadWord(BASE_ADDRESS_REGISTER);
|
moel@353
|
391 |
Thread.Sleep(1);
|
moel@353
|
392 |
gpioVerify = ReadWord(BASE_ADDRESS_REGISTER);
|
moel@353
|
393 |
} else {
|
moel@353
|
394 |
Select(IT87XX_GPIO_LDN);
|
moel@353
|
395 |
gpioAddress = ReadWord(BASE_ADDRESS_REGISTER + 2);
|
moel@353
|
396 |
Thread.Sleep(1);
|
moel@353
|
397 |
gpioVerify = ReadWord(BASE_ADDRESS_REGISTER + 2);
|
moel@353
|
398 |
}
|
moel@353
|
399 |
|
moel@167
|
400 |
IT87Exit();
|
moel@167
|
401 |
|
moel@167
|
402 |
if (address != verify || address < 0x100 || (address & 0xF007) != 0) {
|
moel@167
|
403 |
report.Append("Chip ID: 0x");
|
moel@167
|
404 |
report.AppendLine(chip.ToString("X"));
|
moel@167
|
405 |
report.Append("Error: Invalid address 0x");
|
moel@167
|
406 |
report.AppendLine(address.ToString("X",
|
moel@167
|
407 |
CultureInfo.InvariantCulture));
|
moel@167
|
408 |
report.AppendLine();
|
moel@167
|
409 |
return false;
|
moel@167
|
410 |
}
|
moel@167
|
411 |
|
moel@228
|
412 |
if (gpioAddress != gpioVerify || gpioAddress < 0x100 ||
|
moel@228
|
413 |
(gpioAddress & 0xF007) != 0) {
|
moel@228
|
414 |
report.Append("Chip ID: 0x");
|
moel@228
|
415 |
report.AppendLine(chip.ToString("X"));
|
moel@228
|
416 |
report.Append("Error: Invalid GPIO address 0x");
|
moel@228
|
417 |
report.AppendLine(gpioAddress.ToString("X",
|
moel@228
|
418 |
CultureInfo.InvariantCulture));
|
moel@228
|
419 |
report.AppendLine();
|
moel@228
|
420 |
return false;
|
moel@228
|
421 |
}
|
moel@228
|
422 |
|
moel@228
|
423 |
superIOs.Add(new IT87XX(chip, address, gpioAddress, version));
|
moel@167
|
424 |
return true;
|
moel@167
|
425 |
}
|
moel@167
|
426 |
|
moel@167
|
427 |
return false;
|
moel@167
|
428 |
}
|
moel@167
|
429 |
|
moel@169
|
430 |
#endregion
|
moel@169
|
431 |
|
moel@169
|
432 |
#region SMSC
|
moel@169
|
433 |
|
moel@169
|
434 |
private void SMSCEnter() {
|
moel@236
|
435 |
Ring0.WriteIoPort(registerPort, 0x55);
|
moel@169
|
436 |
}
|
moel@169
|
437 |
|
moel@169
|
438 |
private void SMSCExit() {
|
moel@236
|
439 |
Ring0.WriteIoPort(registerPort, 0xAA);
|
moel@169
|
440 |
}
|
moel@169
|
441 |
|
moel@167
|
442 |
private bool DetectSMSC() {
|
moel@167
|
443 |
SMSCEnter();
|
moel@167
|
444 |
|
moel@167
|
445 |
ushort chipID = ReadWord(CHIP_ID_REGISTER);
|
moel@167
|
446 |
Chip chip;
|
moel@167
|
447 |
switch (chipID) {
|
moel@167
|
448 |
default: chip = Chip.Unknown; break;
|
moel@167
|
449 |
}
|
moel@167
|
450 |
if (chip == Chip.Unknown) {
|
moel@167
|
451 |
if (chipID != 0 && chipID != 0xffff) {
|
moel@167
|
452 |
SMSCExit();
|
moel@167
|
453 |
|
moel@167
|
454 |
ReportUnknownChip("SMSC", chipID);
|
moel@167
|
455 |
}
|
moel@167
|
456 |
} else {
|
moel@167
|
457 |
SMSCExit();
|
moel@167
|
458 |
return true;
|
moel@167
|
459 |
}
|
moel@167
|
460 |
|
moel@167
|
461 |
return false;
|
moel@167
|
462 |
}
|
moel@167
|
463 |
|
moel@169
|
464 |
#endregion
|
moel@169
|
465 |
|
moel@163
|
466 |
private void Detect() {
|
moel@110
|
467 |
|
moel@110
|
468 |
for (int i = 0; i < REGISTER_PORTS.Length; i++) {
|
moel@110
|
469 |
registerPort = REGISTER_PORTS[i];
|
moel@110
|
470 |
valuePort = VALUE_PORTS[i];
|
moel@110
|
471 |
|
moel@167
|
472 |
if (DetectWinbondFintek()) continue;
|
moel@110
|
473 |
|
moel@167
|
474 |
if (DetectIT87()) continue;
|
moel@110
|
475 |
|
moel@167
|
476 |
if (DetectSMSC()) continue;
|
moel@228
|
477 |
}
|
moel@163
|
478 |
}
|
moel@163
|
479 |
|
moel@163
|
480 |
public LPCIO() {
|
moel@236
|
481 |
if (!Ring0.IsOpen)
|
moel@163
|
482 |
return;
|
moel@163
|
483 |
|
moel@236
|
484 |
if (!Ring0.WaitIsaBusMutex(100))
|
moel@163
|
485 |
return;
|
moel@163
|
486 |
|
moel@163
|
487 |
Detect();
|
moel@163
|
488 |
|
moel@236
|
489 |
Ring0.ReleaseIsaBusMutex();
|
moel@110
|
490 |
}
|
moel@110
|
491 |
|
moel@130
|
492 |
public ISuperIO[] SuperIO {
|
moel@110
|
493 |
get {
|
moel@130
|
494 |
return superIOs.ToArray();
|
moel@110
|
495 |
}
|
moel@110
|
496 |
}
|
moel@110
|
497 |
|
moel@110
|
498 |
public string GetReport() {
|
moel@110
|
499 |
if (report.Length > 0) {
|
moel@195
|
500 |
return "LPCIO" + Environment.NewLine + Environment.NewLine + report;
|
moel@110
|
501 |
} else
|
moel@110
|
502 |
return null;
|
moel@110
|
503 |
}
|
moel@110
|
504 |
}
|
moel@110
|
505 |
}
|