Added support for IT8705F super I/O chips.
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-2012 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;
146 chip = Chip.W83627HF;
147 logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
151 switch (revision & 0xF0) {
153 chip = Chip.W83627THF;
154 logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
160 chip = Chip.W83687THF;
161 logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
165 switch (revision & 0xF0) {
168 chip = Chip.W83627EHF;
169 logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
173 switch (revision & 0xF0) {
175 chip = Chip.W83627DHG;
176 logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
180 switch (revision & 0xF0) {
182 chip = Chip.W83667HG;
183 logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
187 switch (revision & 0xF0) {
189 chip = Chip.W83627DHGP;
190 logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
194 switch (revision & 0xF0) {
196 chip = Chip.W83667HGB;
197 logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
201 switch (revision & 0xF0) {
203 chip = Chip.NCT6771F;
204 logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
208 switch (revision & 0xF0) {
210 chip = Chip.NCT6776F;
211 logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
215 if (chip == Chip.Unknown) {
216 if (id != 0 && id != 0xff) {
217 WinbondNuvotonFintekExit();
219 ReportUnknownChip("Winbond / Nuvoton / Fintek",
220 ((id << 8) | revision));
224 Select(logicalDeviceNumber);
225 ushort address = ReadWord(BASE_ADDRESS_REGISTER);
227 ushort verify = ReadWord(BASE_ADDRESS_REGISTER);
229 ushort vendorID = ReadWord(FINTEK_VENDOR_ID_REGISTER);
231 WinbondNuvotonFintekExit();
233 if (address != verify) {
234 report.Append("Chip ID: 0x");
235 report.AppendLine(chip.ToString("X"));
236 report.Append("Chip revision: 0x");
237 report.AppendLine(revision.ToString("X",
238 CultureInfo.InvariantCulture));
239 report.AppendLine("Error: Address verification failed");
244 // some Fintek chips have address register offset 0x05 added already
245 if ((address & 0x07) == 0x05)
248 if (address < 0x100 || (address & 0xF007) != 0) {
249 report.Append("Chip ID: 0x");
250 report.AppendLine(chip.ToString("X"));
251 report.Append("Chip revision: 0x");
252 report.AppendLine(revision.ToString("X",
253 CultureInfo.InvariantCulture));
254 report.Append("Error: Invalid address 0x");
255 report.AppendLine(address.ToString("X",
256 CultureInfo.InvariantCulture));
263 case Chip.W83627DHGP:
270 superIOs.Add(new W836XX(chip, revision, address));
274 superIOs.Add(new NCT677X(chip, revision, address));
284 if (vendorID != FINTEK_VENDOR_ID) {
285 report.Append("Chip ID: 0x");
286 report.AppendLine(chip.ToString("X"));
287 report.Append("Chip revision: 0x");
288 report.AppendLine(revision.ToString("X",
289 CultureInfo.InvariantCulture));
290 report.Append("Error: Invalid vendor ID 0x");
291 report.AppendLine(vendorID.ToString("X",
292 CultureInfo.InvariantCulture));
296 superIOs.Add(new F718XX(chip, address));
311 private const byte IT87_ENVIRONMENT_CONTROLLER_LDN = 0x04;
312 private const byte IT8705_GPIO_LDN = 0x05;
313 private const byte IT87XX_GPIO_LDN = 0x07;
314 private const byte IT87_CHIP_VERSION_REGISTER = 0x22;
316 private void IT87Enter() {
317 Ring0.WriteIoPort(registerPort, 0x87);
318 Ring0.WriteIoPort(registerPort, 0x01);
319 Ring0.WriteIoPort(registerPort, 0x55);
320 Ring0.WriteIoPort(registerPort, 0x55);
323 private void IT87Exit() {
324 Ring0.WriteIoPort(registerPort, CONFIGURATION_CONTROL_REGISTER);
325 Ring0.WriteIoPort(valuePort, 0x02);
328 private bool DetectIT87() {
330 // IT87XX can enter only on port 0x2E
331 if (registerPort != 0x2E)
336 ushort chipID = ReadWord(CHIP_ID_REGISTER);
339 case 0x8705: chip = Chip.IT8705F; break;
340 case 0x8712: chip = Chip.IT8712F; break;
341 case 0x8716: chip = Chip.IT8716F; break;
342 case 0x8718: chip = Chip.IT8718F; break;
343 case 0x8720: chip = Chip.IT8720F; break;
344 case 0x8721: chip = Chip.IT8721F; break;
345 case 0x8726: chip = Chip.IT8726F; break;
346 case 0x8728: chip = Chip.IT8728F; break;
347 case 0x8771: chip = Chip.IT8771E; break;
348 case 0x8772: chip = Chip.IT8772E; break;
349 default: chip = Chip.Unknown; break;
351 if (chip == Chip.Unknown) {
352 if (chipID != 0 && chipID != 0xffff) {
355 ReportUnknownChip("ITE", chipID);
358 Select(IT87_ENVIRONMENT_CONTROLLER_LDN);
359 ushort address = ReadWord(BASE_ADDRESS_REGISTER);
361 ushort verify = ReadWord(BASE_ADDRESS_REGISTER);
363 byte version = (byte)(ReadByte(IT87_CHIP_VERSION_REGISTER) & 0x0F);
367 if (chip == Chip.IT8705F) {
368 Select(IT8705_GPIO_LDN);
369 gpioAddress = ReadWord(BASE_ADDRESS_REGISTER);
371 gpioVerify = ReadWord(BASE_ADDRESS_REGISTER);
373 Select(IT87XX_GPIO_LDN);
374 gpioAddress = ReadWord(BASE_ADDRESS_REGISTER + 2);
376 gpioVerify = ReadWord(BASE_ADDRESS_REGISTER + 2);
381 if (address != verify || address < 0x100 || (address & 0xF007) != 0) {
382 report.Append("Chip ID: 0x");
383 report.AppendLine(chip.ToString("X"));
384 report.Append("Error: Invalid address 0x");
385 report.AppendLine(address.ToString("X",
386 CultureInfo.InvariantCulture));
391 if (gpioAddress != gpioVerify || gpioAddress < 0x100 ||
392 (gpioAddress & 0xF007) != 0) {
393 report.Append("Chip ID: 0x");
394 report.AppendLine(chip.ToString("X"));
395 report.Append("Error: Invalid GPIO address 0x");
396 report.AppendLine(gpioAddress.ToString("X",
397 CultureInfo.InvariantCulture));
402 superIOs.Add(new IT87XX(chip, address, gpioAddress, version));
413 private void SMSCEnter() {
414 Ring0.WriteIoPort(registerPort, 0x55);
417 private void SMSCExit() {
418 Ring0.WriteIoPort(registerPort, 0xAA);
421 private bool DetectSMSC() {
424 ushort chipID = ReadWord(CHIP_ID_REGISTER);
427 default: chip = Chip.Unknown; break;
429 if (chip == Chip.Unknown) {
430 if (chipID != 0 && chipID != 0xffff) {
433 ReportUnknownChip("SMSC", chipID);
445 private void Detect() {
447 for (int i = 0; i < REGISTER_PORTS.Length; i++) {
448 registerPort = REGISTER_PORTS[i];
449 valuePort = VALUE_PORTS[i];
451 if (DetectWinbondFintek()) continue;
453 if (DetectIT87()) continue;
455 if (DetectSMSC()) continue;
463 if (!Ring0.WaitIsaBusMutex(100))
468 Ring0.ReleaseIsaBusMutex();
471 public ISuperIO[] SuperIO {
473 return superIOs.ToArray();
477 public string GetReport() {
478 if (report.Length > 0) {
479 return "LPCIO" + Environment.NewLine + Environment.NewLine + report;