Improved the code used to draw a line between the different OxyPlot subplots.
3 This Source Code Form is subject to the terms of the Mozilla Public
4 License, v. 2.0. If a copy of the MPL was not distributed with this
5 file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 Copyright (C) 2009-2013 Michael Möller <mmoeller@openhardwaremonitor.org>
12 using System.Collections.Generic;
13 using System.Globalization;
15 using System.Threading;
17 namespace OpenHardwareMonitor.Hardware.LPC {
18 internal class LPCIO {
20 private readonly List<ISuperIO> superIOs = new List<ISuperIO>();
21 private readonly StringBuilder report = new StringBuilder();
24 private readonly ushort[] REGISTER_PORTS = new ushort[] { 0x2E, 0x4E };
25 private readonly ushort[] VALUE_PORTS = new ushort[] { 0x2F, 0x4F };
27 private ushort registerPort;
28 private ushort valuePort;
31 private const byte CONFIGURATION_CONTROL_REGISTER = 0x02;
32 private const byte DEVCIE_SELECT_REGISTER = 0x07;
33 private const byte CHIP_ID_REGISTER = 0x20;
34 private const byte CHIP_REVISION_REGISTER = 0x21;
35 private const byte BASE_ADDRESS_REGISTER = 0x60;
37 private byte ReadByte(byte register) {
38 Ring0.WriteIoPort(registerPort, register);
39 return Ring0.ReadIoPort(valuePort);
42 private ushort ReadWord(byte register) {
43 return (ushort)((ReadByte(register) << 8) |
44 ReadByte((byte)(register + 1)));
47 private void Select(byte logicalDeviceNumber) {
48 Ring0.WriteIoPort(registerPort, DEVCIE_SELECT_REGISTER);
49 Ring0.WriteIoPort(valuePort, logicalDeviceNumber);
52 private void ReportUnknownChip(string type, int chip) {
53 report.Append("Chip ID: Unknown ");
55 report.Append(" with ID 0x");
56 report.Append(chip.ToString("X", CultureInfo.InvariantCulture));
57 report.Append(" at 0x");
58 report.Append(registerPort.ToString("X", CultureInfo.InvariantCulture));
60 report.AppendLine(valuePort.ToString("X", CultureInfo.InvariantCulture));
64 #region Winbond, Nuvoton, Fintek
66 private const byte FINTEK_VENDOR_ID_REGISTER = 0x23;
67 private const ushort FINTEK_VENDOR_ID = 0x1934;
69 private const byte WINBOND_NUVOTON_HARDWARE_MONITOR_LDN = 0x0B;
71 private const byte F71858_HARDWARE_MONITOR_LDN = 0x02;
72 private const byte FINTEK_HARDWARE_MONITOR_LDN = 0x04;
74 private void WinbondNuvotonFintekEnter() {
75 Ring0.WriteIoPort(registerPort, 0x87);
76 Ring0.WriteIoPort(registerPort, 0x87);
79 private void WinbondNuvotonFintekExit() {
80 Ring0.WriteIoPort(registerPort, 0xAA);
83 private bool DetectWinbondFintek() {
84 WinbondNuvotonFintekEnter();
86 byte logicalDeviceNumber = 0;
87 byte id = ReadByte(CHIP_ID_REGISTER);
88 byte revision = ReadByte(CHIP_REVISION_REGISTER);
89 Chip chip = Chip.Unknown;
95 logicalDeviceNumber = F71858_HARDWARE_MONITOR_LDN;
99 logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
106 logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
113 logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
120 logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
127 logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
130 chip = Chip.F71889ED;
131 logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
137 chip = Chip.F71889AD;
138 logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
142 logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
150 chip = Chip.W83627HF;
151 logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
155 switch (revision & 0xF0) {
157 chip = Chip.W83627THF;
158 logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
164 chip = Chip.W83687THF;
165 logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
169 switch (revision & 0xF0) {
172 chip = Chip.W83627EHF;
173 logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
177 switch (revision & 0xF0) {
179 chip = Chip.W83627DHG;
180 logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
184 switch (revision & 0xF0) {
186 chip = Chip.W83667HG;
187 logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
191 switch (revision & 0xF0) {
193 chip = Chip.W83627DHGP;
194 logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
198 switch (revision & 0xF0) {
200 chip = Chip.W83667HGB;
201 logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
205 switch (revision & 0xF0) {
207 chip = Chip.NCT6771F;
208 logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
212 switch (revision & 0xF0) {
214 chip = Chip.NCT6776F;
215 logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
219 switch (revision & 0xF0) {
221 chip = Chip.NCT6779D;
222 logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
226 if (chip == Chip.Unknown) {
227 if (id != 0 && id != 0xff) {
228 WinbondNuvotonFintekExit();
230 ReportUnknownChip("Winbond / Nuvoton / Fintek",
231 ((id << 8) | revision));
235 Select(logicalDeviceNumber);
236 ushort address = ReadWord(BASE_ADDRESS_REGISTER);
238 ushort verify = ReadWord(BASE_ADDRESS_REGISTER);
240 ushort vendorID = ReadWord(FINTEK_VENDOR_ID_REGISTER);
242 WinbondNuvotonFintekExit();
244 if (address != verify) {
245 report.Append("Chip ID: 0x");
246 report.AppendLine(chip.ToString("X"));
247 report.Append("Chip revision: 0x");
248 report.AppendLine(revision.ToString("X",
249 CultureInfo.InvariantCulture));
250 report.AppendLine("Error: Address verification failed");
255 // some Fintek chips have address register offset 0x05 added already
256 if ((address & 0x07) == 0x05)
259 if (address < 0x100 || (address & 0xF007) != 0) {
260 report.Append("Chip ID: 0x");
261 report.AppendLine(chip.ToString("X"));
262 report.Append("Chip revision: 0x");
263 report.AppendLine(revision.ToString("X",
264 CultureInfo.InvariantCulture));
265 report.Append("Error: Invalid address 0x");
266 report.AppendLine(address.ToString("X",
267 CultureInfo.InvariantCulture));
274 case Chip.W83627DHGP:
281 superIOs.Add(new W836XX(chip, revision, address));
286 superIOs.Add(new NCT677X(chip, revision, address));
297 if (vendorID != FINTEK_VENDOR_ID) {
298 report.Append("Chip ID: 0x");
299 report.AppendLine(chip.ToString("X"));
300 report.Append("Chip revision: 0x");
301 report.AppendLine(revision.ToString("X",
302 CultureInfo.InvariantCulture));
303 report.Append("Error: Invalid vendor ID 0x");
304 report.AppendLine(vendorID.ToString("X",
305 CultureInfo.InvariantCulture));
309 superIOs.Add(new F718XX(chip, address));
324 private const byte IT87_ENVIRONMENT_CONTROLLER_LDN = 0x04;
325 private const byte IT8705_GPIO_LDN = 0x05;
326 private const byte IT87XX_GPIO_LDN = 0x07;
327 private const byte IT87_CHIP_VERSION_REGISTER = 0x22;
329 private void IT87Enter() {
330 Ring0.WriteIoPort(registerPort, 0x87);
331 Ring0.WriteIoPort(registerPort, 0x01);
332 Ring0.WriteIoPort(registerPort, 0x55);
333 Ring0.WriteIoPort(registerPort, 0x55);
336 private void IT87Exit() {
337 Ring0.WriteIoPort(registerPort, CONFIGURATION_CONTROL_REGISTER);
338 Ring0.WriteIoPort(valuePort, 0x02);
341 private bool DetectIT87() {
343 // IT87XX can enter only on port 0x2E
344 if (registerPort != 0x2E)
349 ushort chipID = ReadWord(CHIP_ID_REGISTER);
352 case 0x8705: chip = Chip.IT8705F; break;
353 case 0x8712: chip = Chip.IT8712F; break;
354 case 0x8716: chip = Chip.IT8716F; break;
355 case 0x8718: chip = Chip.IT8718F; break;
356 case 0x8720: chip = Chip.IT8720F; break;
357 case 0x8721: chip = Chip.IT8721F; break;
358 case 0x8726: chip = Chip.IT8726F; break;
359 case 0x8728: chip = Chip.IT8728F; break;
360 case 0x8771: chip = Chip.IT8771E; break;
361 case 0x8772: chip = Chip.IT8772E; break;
362 default: chip = Chip.Unknown; break;
364 if (chip == Chip.Unknown) {
365 if (chipID != 0 && chipID != 0xffff) {
368 ReportUnknownChip("ITE", chipID);
371 Select(IT87_ENVIRONMENT_CONTROLLER_LDN);
372 ushort address = ReadWord(BASE_ADDRESS_REGISTER);
374 ushort verify = ReadWord(BASE_ADDRESS_REGISTER);
376 byte version = (byte)(ReadByte(IT87_CHIP_VERSION_REGISTER) & 0x0F);
380 if (chip == Chip.IT8705F) {
381 Select(IT8705_GPIO_LDN);
382 gpioAddress = ReadWord(BASE_ADDRESS_REGISTER);
384 gpioVerify = ReadWord(BASE_ADDRESS_REGISTER);
386 Select(IT87XX_GPIO_LDN);
387 gpioAddress = ReadWord(BASE_ADDRESS_REGISTER + 2);
389 gpioVerify = ReadWord(BASE_ADDRESS_REGISTER + 2);
394 if (address != verify || address < 0x100 || (address & 0xF007) != 0) {
395 report.Append("Chip ID: 0x");
396 report.AppendLine(chip.ToString("X"));
397 report.Append("Error: Invalid address 0x");
398 report.AppendLine(address.ToString("X",
399 CultureInfo.InvariantCulture));
404 if (gpioAddress != gpioVerify || gpioAddress < 0x100 ||
405 (gpioAddress & 0xF007) != 0) {
406 report.Append("Chip ID: 0x");
407 report.AppendLine(chip.ToString("X"));
408 report.Append("Error: Invalid GPIO address 0x");
409 report.AppendLine(gpioAddress.ToString("X",
410 CultureInfo.InvariantCulture));
415 superIOs.Add(new IT87XX(chip, address, gpioAddress, version));
426 private void SMSCEnter() {
427 Ring0.WriteIoPort(registerPort, 0x55);
430 private void SMSCExit() {
431 Ring0.WriteIoPort(registerPort, 0xAA);
434 private bool DetectSMSC() {
437 ushort chipID = ReadWord(CHIP_ID_REGISTER);
440 default: chip = Chip.Unknown; break;
442 if (chip == Chip.Unknown) {
443 if (chipID != 0 && chipID != 0xffff) {
446 ReportUnknownChip("SMSC", chipID);
458 private void Detect() {
460 for (int i = 0; i < REGISTER_PORTS.Length; i++) {
461 registerPort = REGISTER_PORTS[i];
462 valuePort = VALUE_PORTS[i];
464 if (DetectWinbondFintek()) continue;
466 if (DetectIT87()) continue;
468 if (DetectSMSC()) continue;
476 if (!Ring0.WaitIsaBusMutex(100))
481 Ring0.ReleaseIsaBusMutex();
484 public ISuperIO[] SuperIO {
486 return superIOs.ToArray();
490 public string GetReport() {
491 if (report.Length > 0) {
492 return "LPCIO" + Environment.NewLine + Environment.NewLine + report;