Changed the project files to Visual Studio 2010. Fixed some Code Analysis warnings.
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-2010
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 List<ISuperIO> superIOs = new List<ISuperIO>();
48 private StringBuilder report = new StringBuilder();
50 private Chip chip = Chip.Unknown;
53 private ushort[] REGISTER_PORTS = new ushort[] { 0x2e, 0x4e };
54 private ushort[] VALUE_PORTS = new ushort[] { 0x2f, 0x4f };
56 private ushort registerPort;
57 private ushort valuePort;
60 private const byte CONFIGURATION_CONTROL_REGISTER = 0x02;
61 private const byte DEVCIE_SELECT_REGISTER = 0x07;
62 private const byte CHIP_ID_REGISTER = 0x20;
63 private const byte CHIP_REVISION_REGISTER = 0x21;
64 private const byte BASE_ADDRESS_REGISTER = 0x60;
66 private byte ReadByte(byte register) {
67 WinRing0.WriteIoPortByte(registerPort, register);
68 return WinRing0.ReadIoPortByte(valuePort);
71 private ushort ReadWord(byte register) {
72 return (ushort)((ReadByte(register) << 8) |
73 ReadByte((byte)(register + 1)));
76 private void Select(byte logicalDeviceNumber) {
77 WinRing0.WriteIoPortByte(registerPort, DEVCIE_SELECT_REGISTER);
78 WinRing0.WriteIoPortByte(valuePort, logicalDeviceNumber);
82 private const byte IT87_ENVIRONMENT_CONTROLLER_LDN = 0x04;
83 private const byte IT87_CHIP_VERSION_REGISTER = 0x22;
85 private void IT87Enter() {
86 WinRing0.WriteIoPortByte(registerPort, 0x87);
87 WinRing0.WriteIoPortByte(registerPort, 0x01);
88 WinRing0.WriteIoPortByte(registerPort, 0x55);
89 WinRing0.WriteIoPortByte(registerPort, 0x55);
92 private void IT87Exit() {
93 WinRing0.WriteIoPortByte(registerPort, CONFIGURATION_CONTROL_REGISTER);
94 WinRing0.WriteIoPortByte(valuePort, 0x02);
98 private const byte FINTEK_VENDOR_ID_REGISTER = 0x23;
99 private const ushort FINTEK_VENDOR_ID = 0x1934;
101 private const byte WINBOND_HARDWARE_MONITOR_LDN = 0x0B;
103 private const byte F71858_HARDWARE_MONITOR_LDN = 0x02;
104 private const byte FINTEK_HARDWARE_MONITOR_LDN = 0x04;
106 private void WinbondFintekEnter() {
107 WinRing0.WriteIoPortByte(registerPort, 0x87);
108 WinRing0.WriteIoPortByte(registerPort, 0x87);
111 private void WinbondFintekExit() {
112 WinRing0.WriteIoPortByte(registerPort, 0xAA);
116 private void SMSCEnter() {
117 WinRing0.WriteIoPortByte(registerPort, 0x55);
120 private void SMSCExit() {
121 WinRing0.WriteIoPortByte(registerPort, 0xAA);
124 private void Detect() {
126 for (int i = 0; i < REGISTER_PORTS.Length; i++) {
127 registerPort = REGISTER_PORTS[i];
128 valuePort = VALUE_PORTS[i];
130 WinbondFintekEnter();
132 byte logicalDeviceNumber;
133 byte id = ReadByte(CHIP_ID_REGISTER);
134 byte revision = ReadByte(CHIP_REVISION_REGISTER);
136 logicalDeviceNumber = 0;
142 logicalDeviceNumber = F71858_HARDWARE_MONITOR_LDN;
146 logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
153 logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
160 logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
167 logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
173 chip = Chip.F71889ED;
174 logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
182 chip = Chip.W83627HF;
183 logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
187 switch (revision & 0xF0) {
189 chip = Chip.W83627THF;
190 logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
196 chip = Chip.W83687THF;
197 logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
201 switch (revision & 0xF0) {
204 chip = Chip.W83627EHF;
205 logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
209 switch (revision & 0xF0) {
211 chip = Chip.W83627DHG;
212 logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
216 switch (revision & 0xF0) {
218 chip = Chip.W83667HG;
219 logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
223 switch (revision & 0xF0) {
225 chip = Chip.W83627DHGP;
226 logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
230 switch (revision & 0xF0) {
232 chip = Chip.W83667HGB;
233 logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
237 if (chip == Chip.Unknown) {
238 if (id != 0 && id != 0xff) {
241 report.Append("Chip ID: Unknown Winbond / Fintek with ID 0x");
242 report.AppendLine(((id << 8) | revision).ToString("X",
243 CultureInfo.InvariantCulture));
248 Select(logicalDeviceNumber);
249 ushort address = ReadWord(BASE_ADDRESS_REGISTER);
251 ushort verify = ReadWord(BASE_ADDRESS_REGISTER);
253 ushort vendorID = ReadWord(FINTEK_VENDOR_ID_REGISTER);
257 if (address != verify) {
258 report.Append("Chip ID: 0x");
259 report.AppendLine(chip.ToString("X"));
260 report.Append("Chip revision: 0x");
261 report.AppendLine(revision.ToString("X", 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", CultureInfo.InvariantCulture));
276 report.Append("Error: Invalid address 0x");
277 report.AppendLine(address.ToString("X", CultureInfo.InvariantCulture));
284 case Chip.W83627DHGP:
291 superIOs.Add(new W836XX(chip, revision, address));
299 if (vendorID != FINTEK_VENDOR_ID) {
300 report.Append("Chip ID: 0x");
301 report.AppendLine(chip.ToString("X"));
302 report.Append("Chip revision: 0x");
303 report.AppendLine(revision.ToString("X", CultureInfo.InvariantCulture));
304 report.Append("Error: Invalid vendor ID 0x");
305 report.AppendLine(vendorID.ToString("X", CultureInfo.InvariantCulture));
309 superIOs.Add(new F718XX(chip, address));
319 ushort chipID = ReadWord(CHIP_ID_REGISTER);
321 case 0x8712: chip = Chip.IT8712F; break;
322 case 0x8716: chip = Chip.IT8716F; break;
323 case 0x8718: chip = Chip.IT8718F; break;
324 case 0x8720: chip = Chip.IT8720F; break;
325 case 0x8726: chip = Chip.IT8726F; break;
326 default: chip = Chip.Unknown; break;
328 if (chip == Chip.Unknown) {
329 if (chipID != 0 && chipID != 0xffff) {
332 report.Append("Chip ID: Unknown ITE with ID 0x");
333 report.AppendLine(chipID.ToString("X", CultureInfo.InvariantCulture));
337 Select(IT87_ENVIRONMENT_CONTROLLER_LDN);
338 ushort address = ReadWord(BASE_ADDRESS_REGISTER);
340 ushort verify = ReadWord(BASE_ADDRESS_REGISTER);
342 byte version = (byte)(ReadByte(IT87_CHIP_VERSION_REGISTER) & 0x0F);
346 if (address != verify || address < 0x100 || (address & 0xF007) != 0) {
347 report.Append("Chip ID: 0x");
348 report.AppendLine(chip.ToString("X"));
349 report.Append("Error: Invalid address 0x");
350 report.AppendLine(address.ToString("X", CultureInfo.InvariantCulture));
355 superIOs.Add(new IT87XX(chip, address, version));
362 chipID = ReadWord(CHIP_ID_REGISTER);
364 default: chip = Chip.Unknown; break;
366 if (chip == Chip.Unknown) {
367 if (chipID != 0 && chipID != 0xffff) {
370 report.Append("Chip ID: Unknown SMSC with ID 0x");
371 report.AppendLine(chipID.ToString("X", CultureInfo.InvariantCulture));
383 if (!WinRing0.IsAvailable)
386 if (!WinRing0.WaitIsaBusMutex(100))
391 WinRing0.ReleaseIsaBusMutex();
394 public ISuperIO[] SuperIO {
396 return superIOs.ToArray();
400 public string GetReport() {
401 if (report.Length > 0) {
402 report.Insert(0, "LPCIO" + Environment.NewLine +
403 Environment.NewLine);
404 return report.ToString();