Added a mainboard specific configuration for the Gigabyte Z68X-UD7-B3 mainboard.
3 Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 The contents of this file are subject to the Mozilla Public License Version
6 1.1 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
9 http://www.mozilla.org/MPL/
11 Software distributed under the License is distributed on an "AS IS" basis,
12 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 for the specific language governing rights and limitations under the License.
15 The Original Code is the Open Hardware Monitor code.
17 The Initial Developer of the Original Code is
18 Michael Möller <m.moeller@gmx.ch>.
19 Portions created by the Initial Developer are Copyright (C) 2009-2011
20 the Initial Developer. All Rights Reserved.
24 Alternatively, the contents of this file may be used under the terms of
25 either the GNU General Public License Version 2 or later (the "GPL"), or
26 the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 in which case the provisions of the GPL or the LGPL are applicable instead
28 of those above. If you wish to allow use of your version of this file only
29 under the terms of either the GPL or the LGPL, and not to allow others to
30 use your version of this file under the terms of the MPL, indicate your
31 decision by deleting the provisions above and replace them with the notice
32 and other provisions required by the GPL or the LGPL. If you do not delete
33 the provisions above, a recipient may use your version of this file under
34 the terms of any one of the MPL, the GPL or the LGPL.
39 using System.Collections.Generic;
40 using System.Globalization;
42 using System.Threading;
44 namespace OpenHardwareMonitor.Hardware.LPC {
45 internal class LPCIO {
47 private readonly List<ISuperIO> superIOs = new List<ISuperIO>();
48 private readonly StringBuilder report = new StringBuilder();
51 private readonly ushort[] REGISTER_PORTS = new ushort[] { 0x2E, 0x4E };
52 private readonly ushort[] VALUE_PORTS = new ushort[] { 0x2F, 0x4F };
54 private ushort registerPort;
55 private ushort valuePort;
58 private const byte CONFIGURATION_CONTROL_REGISTER = 0x02;
59 private const byte DEVCIE_SELECT_REGISTER = 0x07;
60 private const byte CHIP_ID_REGISTER = 0x20;
61 private const byte CHIP_REVISION_REGISTER = 0x21;
62 private const byte BASE_ADDRESS_REGISTER = 0x60;
64 private byte ReadByte(byte register) {
65 Ring0.WriteIoPort(registerPort, register);
66 return Ring0.ReadIoPort(valuePort);
69 private ushort ReadWord(byte register) {
70 return (ushort)((ReadByte(register) << 8) |
71 ReadByte((byte)(register + 1)));
74 private void Select(byte logicalDeviceNumber) {
75 Ring0.WriteIoPort(registerPort, DEVCIE_SELECT_REGISTER);
76 Ring0.WriteIoPort(valuePort, logicalDeviceNumber);
79 private void ReportUnknownChip(string type, int chip) {
80 report.Append("Chip ID: Unknown ");
82 report.Append(" with ID 0x");
83 report.Append(chip.ToString("X", CultureInfo.InvariantCulture));
84 report.Append(" at 0x");
85 report.Append(registerPort.ToString("X", CultureInfo.InvariantCulture));
87 report.AppendLine(valuePort.ToString("X", CultureInfo.InvariantCulture));
91 #region Winbond, Nuvoton, Fintek
93 private const byte FINTEK_VENDOR_ID_REGISTER = 0x23;
94 private const ushort FINTEK_VENDOR_ID = 0x1934;
96 private const byte WINBOND_NUVOTON_HARDWARE_MONITOR_LDN = 0x0B;
98 private const byte F71858_HARDWARE_MONITOR_LDN = 0x02;
99 private const byte FINTEK_HARDWARE_MONITOR_LDN = 0x04;
101 private void WinbondNuvotonFintekEnter() {
102 Ring0.WriteIoPort(registerPort, 0x87);
103 Ring0.WriteIoPort(registerPort, 0x87);
106 private void WinbondNuvotonFintekExit() {
107 Ring0.WriteIoPort(registerPort, 0xAA);
110 private bool DetectWinbondFintek() {
111 WinbondNuvotonFintekEnter();
113 byte logicalDeviceNumber = 0;
114 byte id = ReadByte(CHIP_ID_REGISTER);
115 byte revision = ReadByte(CHIP_REVISION_REGISTER);
116 Chip chip = Chip.Unknown;
122 logicalDeviceNumber = F71858_HARDWARE_MONITOR_LDN;
126 logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
133 logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
140 logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
147 logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
153 chip = Chip.F71889ED;
154 logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
160 chip = Chip.F71889AD;
161 logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
169 chip = Chip.W83627HF;
170 logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
174 switch (revision & 0xF0) {
176 chip = Chip.W83627THF;
177 logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
183 chip = Chip.W83687THF;
184 logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
188 switch (revision & 0xF0) {
191 chip = Chip.W83627EHF;
192 logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
196 switch (revision & 0xF0) {
198 chip = Chip.W83627DHG;
199 logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
203 switch (revision & 0xF0) {
205 chip = Chip.W83667HG;
206 logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
210 switch (revision & 0xF0) {
212 chip = Chip.W83627DHGP;
213 logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
217 switch (revision & 0xF0) {
219 chip = Chip.W83667HGB;
220 logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
224 switch (revision & 0xF0) {
226 chip = Chip.NCT6771F;
227 logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
231 switch (revision & 0xF0) {
233 chip = Chip.NCT6776F;
234 logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
238 if (chip == Chip.Unknown) {
239 if (id != 0 && id != 0xff) {
240 WinbondNuvotonFintekExit();
242 ReportUnknownChip("Winbond / Nuvoton / Fintek",
243 ((id << 8) | revision));
247 Select(logicalDeviceNumber);
248 ushort address = ReadWord(BASE_ADDRESS_REGISTER);
250 ushort verify = ReadWord(BASE_ADDRESS_REGISTER);
252 ushort vendorID = ReadWord(FINTEK_VENDOR_ID_REGISTER);
254 WinbondNuvotonFintekExit();
256 if (address != verify) {
257 report.Append("Chip ID: 0x");
258 report.AppendLine(chip.ToString("X"));
259 report.Append("Chip revision: 0x");
260 report.AppendLine(revision.ToString("X",
261 CultureInfo.InvariantCulture));
262 report.AppendLine("Error: Address verification failed");
267 // some Fintek chips have address register offset 0x05 added already
268 if ((address & 0x07) == 0x05)
271 if (address < 0x100 || (address & 0xF007) != 0) {
272 report.Append("Chip ID: 0x");
273 report.AppendLine(chip.ToString("X"));
274 report.Append("Chip revision: 0x");
275 report.AppendLine(revision.ToString("X",
276 CultureInfo.InvariantCulture));
277 report.Append("Error: Invalid address 0x");
278 report.AppendLine(address.ToString("X",
279 CultureInfo.InvariantCulture));
286 case Chip.W83627DHGP:
293 superIOs.Add(new W836XX(chip, revision, address));
297 superIOs.Add(new NCT677X(chip, revision, address));
306 if (vendorID != FINTEK_VENDOR_ID) {
307 report.Append("Chip ID: 0x");
308 report.AppendLine(chip.ToString("X"));
309 report.Append("Chip revision: 0x");
310 report.AppendLine(revision.ToString("X",
311 CultureInfo.InvariantCulture));
312 report.Append("Error: Invalid vendor ID 0x");
313 report.AppendLine(vendorID.ToString("X",
314 CultureInfo.InvariantCulture));
318 superIOs.Add(new F718XX(chip, address));
333 private const byte IT87_ENVIRONMENT_CONTROLLER_LDN = 0x04;
334 private const byte IT87_GPIO_LDN = 0x07;
335 private const byte IT87_CHIP_VERSION_REGISTER = 0x22;
337 private void IT87Enter() {
338 Ring0.WriteIoPort(registerPort, 0x87);
339 Ring0.WriteIoPort(registerPort, 0x01);
340 Ring0.WriteIoPort(registerPort, 0x55);
341 Ring0.WriteIoPort(registerPort, 0x55);
344 private void IT87Exit() {
345 Ring0.WriteIoPort(registerPort, CONFIGURATION_CONTROL_REGISTER);
346 Ring0.WriteIoPort(valuePort, 0x02);
349 private bool DetectIT87() {
351 // IT87XX can enter only on port 0x2E
352 if (registerPort != 0x2E)
357 ushort chipID = ReadWord(CHIP_ID_REGISTER);
360 case 0x8712: chip = Chip.IT8712F; break;
361 case 0x8716: chip = Chip.IT8716F; break;
362 case 0x8718: chip = Chip.IT8718F; break;
363 case 0x8720: chip = Chip.IT8720F; break;
364 case 0x8721: chip = Chip.IT8721F; break;
365 case 0x8726: chip = Chip.IT8726F; break;
366 case 0x8728: chip = Chip.IT8728F; break;
367 default: chip = Chip.Unknown; break;
369 if (chip == Chip.Unknown) {
370 if (chipID != 0 && chipID != 0xffff) {
373 ReportUnknownChip("ITE", chipID);
376 Select(IT87_ENVIRONMENT_CONTROLLER_LDN);
377 ushort address = ReadWord(BASE_ADDRESS_REGISTER);
379 ushort verify = ReadWord(BASE_ADDRESS_REGISTER);
381 byte version = (byte)(ReadByte(IT87_CHIP_VERSION_REGISTER) & 0x0F);
383 Select(IT87_GPIO_LDN);
384 ushort gpioAddress = ReadWord(BASE_ADDRESS_REGISTER + 2);
386 ushort gpioVerify = ReadWord(BASE_ADDRESS_REGISTER + 2);
390 if (address != verify || address < 0x100 || (address & 0xF007) != 0) {
391 report.Append("Chip ID: 0x");
392 report.AppendLine(chip.ToString("X"));
393 report.Append("Error: Invalid address 0x");
394 report.AppendLine(address.ToString("X",
395 CultureInfo.InvariantCulture));
400 if (gpioAddress != gpioVerify || gpioAddress < 0x100 ||
401 (gpioAddress & 0xF007) != 0) {
402 report.Append("Chip ID: 0x");
403 report.AppendLine(chip.ToString("X"));
404 report.Append("Error: Invalid GPIO address 0x");
405 report.AppendLine(gpioAddress.ToString("X",
406 CultureInfo.InvariantCulture));
411 superIOs.Add(new IT87XX(chip, address, gpioAddress, version));
422 private void SMSCEnter() {
423 Ring0.WriteIoPort(registerPort, 0x55);
426 private void SMSCExit() {
427 Ring0.WriteIoPort(registerPort, 0xAA);
430 private bool DetectSMSC() {
433 ushort chipID = ReadWord(CHIP_ID_REGISTER);
436 default: chip = Chip.Unknown; break;
438 if (chip == Chip.Unknown) {
439 if (chipID != 0 && chipID != 0xffff) {
442 ReportUnknownChip("SMSC", chipID);
454 private void Detect() {
456 for (int i = 0; i < REGISTER_PORTS.Length; i++) {
457 registerPort = REGISTER_PORTS[i];
458 valuePort = VALUE_PORTS[i];
460 if (DetectWinbondFintek()) continue;
462 if (DetectIT87()) continue;
464 if (DetectSMSC()) continue;
472 if (!Ring0.WaitIsaBusMutex(100))
477 Ring0.ReleaseIsaBusMutex();
480 public ISuperIO[] SuperIO {
482 return superIOs.ToArray();
486 public string GetReport() {
487 if (report.Length > 0) {
488 return "LPCIO" + Environment.NewLine + Environment.NewLine + report;