Added a fan control sensor for ATI GPUs.
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 {
46 private List<ISuperIO> superIOs = new List<ISuperIO>();
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;
82 private const byte IT87_CHIP_VERSION_REGISTER = 0x22;
84 private void IT87Enter() {
85 WinRing0.WriteIoPortByte(registerPort, 0x87);
86 WinRing0.WriteIoPortByte(registerPort, 0x01);
87 WinRing0.WriteIoPortByte(registerPort, 0x55);
88 WinRing0.WriteIoPortByte(registerPort, 0x55);
91 private void IT87Exit() {
92 WinRing0.WriteIoPortByte(registerPort, CONFIGURATION_CONTROL_REGISTER);
93 WinRing0.WriteIoPortByte(valuePort, 0x02);
97 private const byte FINTEK_VENDOR_ID_REGISTER = 0x23;
98 private const ushort FINTEK_VENDOR_ID = 0x1934;
100 private const byte WINBOND_HARDWARE_MONITOR_LDN = 0x0B;
102 private const byte F71858_HARDWARE_MONITOR_LDN = 0x02;
103 private const byte FINTEK_HARDWARE_MONITOR_LDN = 0x04;
105 private void WinbondFintekEnter() {
106 WinRing0.WriteIoPortByte(registerPort, 0x87);
107 WinRing0.WriteIoPortByte(registerPort, 0x87);
110 private void WinbondFintekExit() {
111 WinRing0.WriteIoPortByte(registerPort, 0xAA);
115 private void SMSCEnter() {
116 WinRing0.WriteIoPortByte(registerPort, 0x55);
119 private void SMSCExit() {
120 WinRing0.WriteIoPortByte(registerPort, 0xAA);
123 private void Detect() {
125 for (int i = 0; i < REGISTER_PORTS.Length; i++) {
126 registerPort = REGISTER_PORTS[i];
127 valuePort = VALUE_PORTS[i];
129 WinbondFintekEnter();
131 byte logicalDeviceNumber;
132 byte id = ReadByte(CHIP_ID_REGISTER);
133 byte revision = ReadByte(CHIP_REVISION_REGISTER);
135 logicalDeviceNumber = 0;
141 logicalDeviceNumber = F71858_HARDWARE_MONITOR_LDN;
145 logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
152 logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
159 logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
166 logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
172 chip = Chip.F71889ED;
173 logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
181 chip = Chip.W83627HF;
182 logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
186 switch (revision & 0xF0) {
188 chip = Chip.W83627THF;
189 logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
195 chip = Chip.W83687THF;
196 logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
200 switch (revision & 0xF0) {
203 chip = Chip.W83627EHF;
204 logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
208 switch (revision & 0xF0) {
210 chip = Chip.W83627DHG;
211 logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
215 switch (revision & 0xF0) {
217 chip = Chip.W83667HG;
218 logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
222 switch (revision & 0xF0) {
224 chip = Chip.W83627DHGP;
225 logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
229 switch (revision & 0xF0) {
231 chip = Chip.W83667HGB;
232 logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
236 if (chip == Chip.Unknown) {
237 if (id != 0 && id != 0xff) {
240 report.Append("Chip ID: Unknown Winbond / Fintek with ID 0x");
241 report.AppendLine(((id << 8) | revision).ToString("X"));
246 Select(logicalDeviceNumber);
247 ushort address = ReadWord(BASE_ADDRESS_REGISTER);
249 ushort verify = ReadWord(BASE_ADDRESS_REGISTER);
251 ushort vendorID = ReadWord(FINTEK_VENDOR_ID_REGISTER);
255 if (address != verify) {
256 report.Append("Chip ID: 0x");
257 report.AppendLine(chip.ToString("X"));
258 report.Append("Chip revision: 0x");
259 report.AppendLine(revision.ToString("X"));
260 report.AppendLine("Error: Address verification failed");
265 // some Fintek chips have address register offset 0x05 added already
266 if ((address & 0x07) == 0x05)
269 if (address < 0x100 || (address & 0xF007) != 0) {
270 report.Append("Chip ID: 0x");
271 report.AppendLine(chip.ToString("X"));
272 report.Append("Chip revision: 0x");
273 report.AppendLine(revision.ToString("X"));
274 report.Append("Error: Invalid address 0x");
275 report.AppendLine(address.ToString("X"));
282 case Chip.W83627DHGP:
289 superIOs.Add(new W836XX(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 report.Append("Error: Invalid vendor ID 0x");
303 report.AppendLine(vendorID.ToString("X"));
307 superIOs.Add(new F718XX(chip, address));
317 ushort chipID = ReadWord(CHIP_ID_REGISTER);
319 case 0x8712: chip = Chip.IT8712F; break;
320 case 0x8716: chip = Chip.IT8716F; break;
321 case 0x8718: chip = Chip.IT8718F; break;
322 case 0x8720: chip = Chip.IT8720F; break;
323 case 0x8726: chip = Chip.IT8726F; break;
324 default: chip = Chip.Unknown; break;
326 if (chip == Chip.Unknown) {
327 if (chipID != 0 && chipID != 0xffff) {
330 report.Append("Chip ID: Unknown ITE with ID 0x");
331 report.AppendLine(chipID.ToString("X"));
335 Select(IT87_ENVIRONMENT_CONTROLLER_LDN);
336 ushort address = ReadWord(BASE_ADDRESS_REGISTER);
338 ushort verify = ReadWord(BASE_ADDRESS_REGISTER);
340 byte version = (byte)(ReadByte(IT87_CHIP_VERSION_REGISTER) & 0x0F);
344 if (address != verify || address < 0x100 || (address & 0xF007) != 0) {
345 report.Append("Chip ID: 0x");
346 report.AppendLine(chip.ToString("X"));
347 report.Append("Error: Invalid address 0x");
348 report.AppendLine(address.ToString("X"));
353 superIOs.Add(new IT87XX(chip, address, version));
360 chipID = ReadWord(CHIP_ID_REGISTER);
362 default: chip = Chip.Unknown; break;
364 if (chip == Chip.Unknown) {
365 if (chipID != 0 && chipID != 0xffff) {
368 report.Append("Chip ID: Unknown SMSC with ID 0x");
369 report.AppendLine(chipID.ToString("X"));
381 if (!WinRing0.IsAvailable)
384 if (!WinRing0.WaitIsaBusMutex(100))
389 WinRing0.ReleaseIsaBusMutex();
392 public ISuperIO[] SuperIO {
394 return superIOs.ToArray();
398 public string GetReport() {
399 if (report.Length > 0) {
400 report.Insert(0, "LPCIO" + Environment.NewLine +
401 Environment.NewLine);
402 return report.ToString();