Fixed Issue 43.
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;
41 using System.Threading;
43 namespace OpenHardwareMonitor.Hardware.LPC {
44 public class LPCGroup : IGroup {
46 private List<IHardware> hardware = new List<IHardware>();
47 private StringBuilder report = new StringBuilder();
49 private Chip chip = Chip.Unknown;
52 private ushort[] REGISTER_PORTS = new ushort[] { 0x2e, 0x4e };
53 private ushort[] VALUE_PORTS = new ushort[] { 0x2f, 0x4f };
55 private ushort registerPort;
56 private ushort valuePort;
59 private const byte CONFIGURATION_CONTROL_REGISTER = 0x02;
60 private const byte DEVCIE_SELECT_REGISTER = 0x07;
61 private const byte CHIP_ID_REGISTER = 0x20;
62 private const byte CHIP_REVISION_REGISTER = 0x21;
63 private const byte BASE_ADDRESS_REGISTER = 0x60;
65 private byte ReadByte(byte register) {
66 WinRing0.WriteIoPortByte(registerPort, register);
67 return WinRing0.ReadIoPortByte(valuePort);
70 private ushort ReadWord(byte register) {
71 return (ushort)((ReadByte(register) << 8) |
72 ReadByte((byte)(register + 1)));
75 private void Select(byte logicalDeviceNumber) {
76 WinRing0.WriteIoPortByte(registerPort, DEVCIE_SELECT_REGISTER);
77 WinRing0.WriteIoPortByte(valuePort, logicalDeviceNumber);
81 private const byte IT87_ENVIRONMENT_CONTROLLER_LDN = 0x04;
83 private void IT87Enter() {
84 WinRing0.WriteIoPortByte(registerPort, 0x87);
85 WinRing0.WriteIoPortByte(registerPort, 0x01);
86 WinRing0.WriteIoPortByte(registerPort, 0x55);
87 WinRing0.WriteIoPortByte(registerPort, 0x55);
90 internal void IT87Exit() {
91 WinRing0.WriteIoPortByte(registerPort, CONFIGURATION_CONTROL_REGISTER);
92 WinRing0.WriteIoPortByte(valuePort, 0x02);
96 private const byte FINTEK_VENDOR_ID_REGISTER = 0x23;
97 private const ushort FINTEK_VENDOR_ID = 0x1934;
99 private const byte WINBOND_HARDWARE_MONITOR_LDN = 0x0B;
101 private const byte F71858_HARDWARE_MONITOR_LDN = 0x02;
102 private const byte FINTEK_HARDWARE_MONITOR_LDN = 0x04;
104 private void WinbondFintekEnter() {
105 WinRing0.WriteIoPortByte(registerPort, 0x87);
106 WinRing0.WriteIoPortByte(registerPort, 0x87);
109 private void WinbondFintekExit() {
110 WinRing0.WriteIoPortByte(registerPort, 0xAA);
114 private void SMSCEnter() {
115 WinRing0.WriteIoPortByte(registerPort, 0x55);
118 private void SMSCExit() {
119 WinRing0.WriteIoPortByte(registerPort, 0xAA);
123 if (!WinRing0.IsAvailable)
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;
175 chip = Chip.W83627HF;
176 logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
182 chip = Chip.W83627THF;
183 logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
189 chip = Chip.W83687THF;
190 logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
194 switch (revision & 0xF0) {
196 chip = Chip.W83627EHF;
197 logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
201 switch (revision & 0xF0) {
203 chip = Chip.W83627DHG;
204 logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
208 switch (revision & 0xF0) {
210 chip = Chip.W83667HG;
211 logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
215 switch (revision & 0xF0) {
217 chip = Chip.W83627DHGP;
218 logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
222 switch (revision & 0xF0) {
224 chip = Chip.W83667HGB;
225 logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
229 if (chip == Chip.Unknown) {
230 if (id != 0 && id != 0xff) {
233 report.Append("Chip ID: Unknown Winbond / Fintek with ID 0x");
234 report.AppendLine(((id << 8) | revision).ToString("X"));
239 Select(logicalDeviceNumber);
240 ushort address = ReadWord(BASE_ADDRESS_REGISTER);
242 ushort verify = ReadWord(BASE_ADDRESS_REGISTER);
244 ushort vendorID = FINTEK_VENDOR_ID;
245 if (chip == Chip.F71858 || chip == Chip.F71862 ||
246 chip == Chip.F71882 || chip == Chip.F71889)
247 vendorID = ReadWord(FINTEK_VENDOR_ID_REGISTER);
251 if (address != verify) {
252 report.Append("Chip ID: 0x");
253 report.AppendLine(chip.ToString("X"));
254 report.Append("Chip revision: 0x");
255 report.AppendLine(revision.ToString("X"));
256 report.AppendLine("Error: Address verification failed");
261 // some Fintek chips have address register offset 0x05 added already
262 if ((address & 0x07) == 0x05)
265 if (address < 0x100 || (address & 0xF007) != 0) {
266 report.Append("Chip ID: 0x");
267 report.AppendLine(chip.ToString("X"));
268 report.Append("Chip revision: 0x");
269 report.AppendLine(revision.ToString("X"));
270 report.Append("Error: Invalid address 0x");
271 report.AppendLine(address.ToString("X"));
278 case Chip.W83627DHGP:
285 W836XX w836XX = new W836XX(chip, revision, address);
286 if (w836XX.IsAvailable)
287 hardware.Add(w836XX);
294 hardware.Add(new F718XX(chip, address));
304 ushort chipID = ReadWord(CHIP_ID_REGISTER);
306 case 0x8712: chip = Chip.IT8712F; break;
307 case 0x8716: chip = Chip.IT8716F; break;
308 case 0x8718: chip = Chip.IT8718F; break;
309 case 0x8720: chip = Chip.IT8720F; break;
310 case 0x8726: chip = Chip.IT8726F; break;
311 default: chip = Chip.Unknown; break;
313 if (chip == Chip.Unknown) {
314 if (chipID != 0 && chipID != 0xffff) {
317 report.Append("Chip ID: Unknown ITE with ID 0x");
318 report.AppendLine(chipID.ToString("X"));
322 Select(IT87_ENVIRONMENT_CONTROLLER_LDN);
323 ushort address = ReadWord(BASE_ADDRESS_REGISTER);
325 ushort verify = ReadWord(BASE_ADDRESS_REGISTER);
329 if (address != verify || address < 0x100 || (address & 0xF007) != 0) {
330 report.Append("Chip ID: 0x");
331 report.AppendLine(chip.ToString("X"));
332 report.Append("Error: Invalid address 0x");
333 report.AppendLine(address.ToString("X"));
338 IT87XX it87 = new IT87XX(chip, address);
339 if (it87.IsAvailable)
347 chipID = ReadWord(CHIP_ID_REGISTER);
349 default: chip = Chip.Unknown; break;
351 if (chip == Chip.Unknown) {
352 if (chipID != 0 && chipID != 0xffff) {
355 report.Append("Chip ID: Unknown SMSC with ID 0x");
356 report.AppendLine(chipID.ToString("X"));
367 public IHardware[] Hardware {
369 return hardware.ToArray();
373 public string GetReport() {
374 if (report.Length > 0) {
375 report.Insert(0, "LPCIO" + Environment.NewLine +
376 Environment.NewLine);
377 return report.ToString();
382 public void Close() { }