Hardware/LPC/LPCGroup.cs
changeset 110 411b72b73d8f
parent 109 70d0c3102424
child 111 2b8a8cf92c3a
     1.1 --- a/Hardware/LPC/LPCGroup.cs	Thu May 06 19:20:38 2010 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,400 +0,0 @@
     1.4 -/*
     1.5 -  
     1.6 -  Version: MPL 1.1/GPL 2.0/LGPL 2.1
     1.7 -
     1.8 -  The contents of this file are subject to the Mozilla Public License Version
     1.9 -  1.1 (the "License"); you may not use this file except in compliance with
    1.10 -  the License. You may obtain a copy of the License at
    1.11 - 
    1.12 -  http://www.mozilla.org/MPL/
    1.13 -
    1.14 -  Software distributed under the License is distributed on an "AS IS" basis,
    1.15 -  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
    1.16 -  for the specific language governing rights and limitations under the License.
    1.17 -
    1.18 -  The Original Code is the Open Hardware Monitor code.
    1.19 -
    1.20 -  The Initial Developer of the Original Code is 
    1.21 -  Michael Möller <m.moeller@gmx.ch>.
    1.22 -  Portions created by the Initial Developer are Copyright (C) 2009-2010
    1.23 -  the Initial Developer. All Rights Reserved.
    1.24 -
    1.25 -  Contributor(s):
    1.26 -
    1.27 -  Alternatively, the contents of this file may be used under the terms of
    1.28 -  either the GNU General Public License Version 2 or later (the "GPL"), or
    1.29 -  the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
    1.30 -  in which case the provisions of the GPL or the LGPL are applicable instead
    1.31 -  of those above. If you wish to allow use of your version of this file only
    1.32 -  under the terms of either the GPL or the LGPL, and not to allow others to
    1.33 -  use your version of this file under the terms of the MPL, indicate your
    1.34 -  decision by deleting the provisions above and replace them with the notice
    1.35 -  and other provisions required by the GPL or the LGPL. If you do not delete
    1.36 -  the provisions above, a recipient may use your version of this file under
    1.37 -  the terms of any one of the MPL, the GPL or the LGPL.
    1.38 - 
    1.39 -*/
    1.40 -
    1.41 -using System;
    1.42 -using System.Collections.Generic;
    1.43 -using System.Text;
    1.44 -using System.Threading;
    1.45 -
    1.46 -namespace OpenHardwareMonitor.Hardware.LPC {
    1.47 -  public class LPCGroup : IGroup {
    1.48 -
    1.49 -    private List<IHardware> hardware = new List<IHardware>();
    1.50 -    private StringBuilder report = new StringBuilder();
    1.51 -
    1.52 -    private Chip chip = Chip.Unknown;
    1.53 -
    1.54 -    // I/O Ports
    1.55 -    private ushort[] REGISTER_PORTS = new ushort[] { 0x2e, 0x4e };
    1.56 -    private ushort[] VALUE_PORTS = new ushort[] { 0x2f, 0x4f };
    1.57 -
    1.58 -    private ushort registerPort;
    1.59 -    private ushort valuePort;
    1.60 -
    1.61 -    // Registers
    1.62 -    private const byte CONFIGURATION_CONTROL_REGISTER = 0x02;
    1.63 -    private const byte DEVCIE_SELECT_REGISTER = 0x07;
    1.64 -    private const byte CHIP_ID_REGISTER = 0x20;
    1.65 -    private const byte CHIP_REVISION_REGISTER = 0x21;
    1.66 -    private const byte BASE_ADDRESS_REGISTER = 0x60;
    1.67 -
    1.68 -    private byte ReadByte(byte register) {
    1.69 -      WinRing0.WriteIoPortByte(registerPort, register);
    1.70 -      return WinRing0.ReadIoPortByte(valuePort);
    1.71 -    } 
    1.72 -
    1.73 -    private ushort ReadWord(byte register) {
    1.74 -      return (ushort)((ReadByte(register) << 8) | 
    1.75 -        ReadByte((byte)(register + 1)));
    1.76 -    }
    1.77 -
    1.78 -    private void Select(byte logicalDeviceNumber) {
    1.79 -      WinRing0.WriteIoPortByte(registerPort, DEVCIE_SELECT_REGISTER);
    1.80 -      WinRing0.WriteIoPortByte(valuePort, logicalDeviceNumber);
    1.81 -    }
    1.82 -
    1.83 -    // ITE
    1.84 -    private const byte IT87_ENVIRONMENT_CONTROLLER_LDN = 0x04;    
    1.85 -
    1.86 -    private void IT87Enter() {
    1.87 -      WinRing0.WriteIoPortByte(registerPort, 0x87);
    1.88 -      WinRing0.WriteIoPortByte(registerPort, 0x01);
    1.89 -      WinRing0.WriteIoPortByte(registerPort, 0x55);
    1.90 -      WinRing0.WriteIoPortByte(registerPort, 0x55);
    1.91 -    }
    1.92 -
    1.93 -    internal void IT87Exit() {
    1.94 -      WinRing0.WriteIoPortByte(registerPort, CONFIGURATION_CONTROL_REGISTER);
    1.95 -      WinRing0.WriteIoPortByte(valuePort, 0x02);
    1.96 -    }
    1.97 -
    1.98 -    // Winbond, Fintek
    1.99 -    private const byte FINTEK_VENDOR_ID_REGISTER = 0x23;
   1.100 -    private const ushort FINTEK_VENDOR_ID = 0x1934;
   1.101 -
   1.102 -    private const byte WINBOND_HARDWARE_MONITOR_LDN = 0x0B;
   1.103 -
   1.104 -    private const byte F71858_HARDWARE_MONITOR_LDN = 0x02;
   1.105 -    private const byte FINTEK_HARDWARE_MONITOR_LDN = 0x04;
   1.106 -
   1.107 -    private void WinbondFintekEnter() {
   1.108 -      WinRing0.WriteIoPortByte(registerPort, 0x87);
   1.109 -      WinRing0.WriteIoPortByte(registerPort, 0x87);
   1.110 -    }
   1.111 -
   1.112 -    private void WinbondFintekExit() {
   1.113 -      WinRing0.WriteIoPortByte(registerPort, 0xAA);      
   1.114 -    }
   1.115 -
   1.116 -    // SMSC
   1.117 -    private void SMSCEnter() {
   1.118 -      WinRing0.WriteIoPortByte(registerPort, 0x55);
   1.119 -    }
   1.120 -
   1.121 -    private void SMSCExit() {
   1.122 -      WinRing0.WriteIoPortByte(registerPort, 0xAA);
   1.123 -    }
   1.124 -
   1.125 -    public LPCGroup() {
   1.126 -      if (!WinRing0.IsAvailable)
   1.127 -        return;
   1.128 -
   1.129 -      for (int i = 0; i < REGISTER_PORTS.Length; i++) {
   1.130 -        registerPort = REGISTER_PORTS[i];
   1.131 -        valuePort = VALUE_PORTS[i];
   1.132 -
   1.133 -        WinbondFintekEnter();
   1.134 -
   1.135 -        byte logicalDeviceNumber;
   1.136 -        byte id = ReadByte(CHIP_ID_REGISTER);
   1.137 -        byte revision = ReadByte(CHIP_REVISION_REGISTER);
   1.138 -        chip = Chip.Unknown;
   1.139 -        logicalDeviceNumber = 0;
   1.140 -        switch (id) {
   1.141 -          case 0x05:
   1.142 -            switch (revision) {
   1.143 -              case 0x07:
   1.144 -                chip = Chip.F71858;
   1.145 -                logicalDeviceNumber = F71858_HARDWARE_MONITOR_LDN;
   1.146 -                break;
   1.147 -              case 0x41:
   1.148 -                chip = Chip.F71882;
   1.149 -                logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
   1.150 -                break;              
   1.151 -            } break;
   1.152 -          case 0x06:
   1.153 -            switch (revision) {             
   1.154 -              case 0x01:
   1.155 -                chip = Chip.F71862;
   1.156 -                logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
   1.157 -                break;              
   1.158 -            } break;
   1.159 -          case 0x07:
   1.160 -            switch (revision) {
   1.161 -              case 0x23:
   1.162 -                chip = Chip.F71889F;
   1.163 -                logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
   1.164 -                break;              
   1.165 -            } break;
   1.166 -          case 0x08:
   1.167 -            switch (revision) {
   1.168 -              case 0x14:
   1.169 -                chip = Chip.F71869;
   1.170 -                logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
   1.171 -                break;              
   1.172 -            } break;
   1.173 -          case 0x09:
   1.174 -            switch (revision) {
   1.175 -              case 0x09:
   1.176 -                chip = Chip.F71889ED;
   1.177 -                logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
   1.178 -                break;              
   1.179 -            } break;
   1.180 -          case 0x52:
   1.181 -            switch (revision) {
   1.182 -              case 0x17:
   1.183 -              case 0x3A:
   1.184 -              case 0x41:
   1.185 -                chip = Chip.W83627HF;
   1.186 -                logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
   1.187 -                break;             
   1.188 -            } break;
   1.189 -          case 0x82:
   1.190 -            switch (revision) {
   1.191 -              case 0x83:
   1.192 -                chip = Chip.W83627THF;
   1.193 -                logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
   1.194 -                break;
   1.195 -            } break;
   1.196 -          case 0x85:
   1.197 -            switch (revision) {
   1.198 -              case 0x41:
   1.199 -                chip = Chip.W83687THF;
   1.200 -                logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
   1.201 -                break;
   1.202 -            } break;
   1.203 -          case 0x88:
   1.204 -            switch (revision & 0xF0) {
   1.205 -              case 0x50:
   1.206 -              case 0x60:
   1.207 -                chip = Chip.W83627EHF;
   1.208 -                logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
   1.209 -                break;
   1.210 -            } break;
   1.211 -          case 0xA0:
   1.212 -            switch (revision & 0xF0) {
   1.213 -              case 0x20: 
   1.214 -                chip = Chip.W83627DHG;
   1.215 -                logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;  
   1.216 -                break;             
   1.217 -            } break;
   1.218 -          case 0xA5:
   1.219 -            switch (revision & 0xF0) {
   1.220 -              case 0x10:
   1.221 -                chip = Chip.W83667HG;
   1.222 -                logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
   1.223 -                break;
   1.224 -            } break;
   1.225 -          case 0xB0:
   1.226 -            switch (revision & 0xF0) {
   1.227 -              case 0x70:
   1.228 -                chip = Chip.W83627DHGP;
   1.229 -                logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
   1.230 -                break;             
   1.231 -            } break;
   1.232 -          case 0xB3:
   1.233 -            switch (revision & 0xF0) {
   1.234 -              case 0x50:
   1.235 -                chip = Chip.W83667HGB;
   1.236 -                logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
   1.237 -                break;
   1.238 -            } break; 
   1.239 -        }
   1.240 -        if (chip == Chip.Unknown) {
   1.241 -          if (id != 0 && id != 0xff) {
   1.242 -            WinbondFintekExit();
   1.243 -
   1.244 -            report.Append("Chip ID: Unknown Winbond / Fintek with ID 0x"); 
   1.245 -            report.AppendLine(((id << 8) | revision).ToString("X"));
   1.246 -            report.AppendLine();
   1.247 -          }
   1.248 -        } else {
   1.249 -
   1.250 -          Select(logicalDeviceNumber);
   1.251 -          ushort address = ReadWord(BASE_ADDRESS_REGISTER);          
   1.252 -          Thread.Sleep(1);
   1.253 -          ushort verify = ReadWord(BASE_ADDRESS_REGISTER);
   1.254 -
   1.255 -          ushort vendorID = ReadWord(FINTEK_VENDOR_ID_REGISTER);
   1.256 -
   1.257 -          WinbondFintekExit();
   1.258 -
   1.259 -          if (address != verify) {            
   1.260 -            report.Append("Chip ID: 0x"); 
   1.261 -            report.AppendLine(chip.ToString("X"));
   1.262 -            report.Append("Chip revision: 0x"); 
   1.263 -            report.AppendLine(revision.ToString("X"));
   1.264 -            report.AppendLine("Error: Address verification failed");
   1.265 -            report.AppendLine();
   1.266 -            return;
   1.267 -          }
   1.268 -
   1.269 -          // some Fintek chips have address register offset 0x05 added already
   1.270 -          if ((address & 0x07) == 0x05)
   1.271 -            address &= 0xFFF8;
   1.272 -
   1.273 -          if (address < 0x100 || (address & 0xF007) != 0) {            
   1.274 -            report.Append("Chip ID: 0x");
   1.275 -            report.AppendLine(chip.ToString("X"));
   1.276 -            report.Append("Chip revision: 0x");
   1.277 -            report.AppendLine(revision.ToString("X"));
   1.278 -            report.Append("Error: Invalid address 0x");
   1.279 -            report.AppendLine(address.ToString("X"));
   1.280 -            report.AppendLine();
   1.281 -            return;
   1.282 -          }
   1.283 -
   1.284 -          switch (chip) {
   1.285 -            case Chip.W83627DHG:
   1.286 -            case Chip.W83627DHGP:
   1.287 -            case Chip.W83627EHF:
   1.288 -            case Chip.W83627HF:
   1.289 -            case Chip.W83627THF:
   1.290 -            case Chip.W83667HG:
   1.291 -            case Chip.W83667HGB:
   1.292 -            case Chip.W83687THF:
   1.293 -              W836XX w836XX = new W836XX(chip, revision, address);
   1.294 -              if (w836XX.IsAvailable)
   1.295 -                hardware.Add(w836XX);
   1.296 -              break;
   1.297 -            case Chip.F71858:
   1.298 -            case Chip.F71862:
   1.299 -            case Chip.F71869:
   1.300 -            case Chip.F71882:
   1.301 -            case Chip.F71889ED:
   1.302 -            case Chip.F71889F:
   1.303 -              if (vendorID != FINTEK_VENDOR_ID) {
   1.304 -                report.Append("Chip ID: 0x");
   1.305 -                report.AppendLine(chip.ToString("X"));
   1.306 -                report.Append("Chip revision: 0x");
   1.307 -                report.AppendLine(revision.ToString("X"));
   1.308 -                report.Append("Error: Invalid vendor ID 0x");
   1.309 -                report.AppendLine(vendorID.ToString("X"));
   1.310 -                report.AppendLine();
   1.311 -                return;
   1.312 -              }
   1.313 -              hardware.Add(new F718XX(chip, address));
   1.314 -              break;
   1.315 -            default: break;
   1.316 -          }
   1.317 -          
   1.318 -          return;
   1.319 -        }
   1.320 -
   1.321 -        IT87Enter();
   1.322 -
   1.323 -        ushort chipID = ReadWord(CHIP_ID_REGISTER);
   1.324 -        switch (chipID) {
   1.325 -          case 0x8712: chip = Chip.IT8712F; break;
   1.326 -          case 0x8716: chip = Chip.IT8716F; break;
   1.327 -          case 0x8718: chip = Chip.IT8718F; break;
   1.328 -          case 0x8720: chip = Chip.IT8720F; break;
   1.329 -          case 0x8726: chip = Chip.IT8726F; break; 
   1.330 -          default: chip = Chip.Unknown; break;
   1.331 -        }
   1.332 -        if (chip == Chip.Unknown) {
   1.333 -          if (chipID != 0 && chipID != 0xffff) {
   1.334 -            IT87Exit();
   1.335 -
   1.336 -            report.Append("Chip ID: Unknown ITE with ID 0x");
   1.337 -            report.AppendLine(chipID.ToString("X"));
   1.338 -            report.AppendLine();
   1.339 -          }
   1.340 -        } else {
   1.341 -          Select(IT87_ENVIRONMENT_CONTROLLER_LDN);
   1.342 -          ushort address = ReadWord(BASE_ADDRESS_REGISTER);
   1.343 -          Thread.Sleep(1);
   1.344 -          ushort verify = ReadWord(BASE_ADDRESS_REGISTER);
   1.345 -
   1.346 -          IT87Exit();
   1.347 -
   1.348 -          if (address != verify || address < 0x100 || (address & 0xF007) != 0) {
   1.349 -            report.Append("Chip ID: 0x");
   1.350 -            report.AppendLine(chip.ToString("X"));            
   1.351 -            report.Append("Error: Invalid address 0x");
   1.352 -            report.AppendLine(address.ToString("X"));
   1.353 -            report.AppendLine();
   1.354 -            return;
   1.355 -          }
   1.356 -
   1.357 -          IT87XX it87 = new IT87XX(chip, address);
   1.358 -          if (it87.IsAvailable)
   1.359 -            hardware.Add(it87);
   1.360 -
   1.361 -          return;
   1.362 -        }
   1.363 -
   1.364 -        SMSCEnter();
   1.365 -
   1.366 -        chipID = ReadWord(CHIP_ID_REGISTER);
   1.367 -        switch (chipID) {
   1.368 -          default: chip = Chip.Unknown; break;
   1.369 -        }
   1.370 -        if (chip == Chip.Unknown) {
   1.371 -          if (chipID != 0 && chipID != 0xffff) {
   1.372 -            SMSCExit();
   1.373 -
   1.374 -            report.Append("Chip ID: Unknown SMSC with ID 0x");
   1.375 -            report.AppendLine(chipID.ToString("X"));
   1.376 -            report.AppendLine();
   1.377 -          }
   1.378 -        } else {
   1.379 -          SMSCExit();
   1.380 -
   1.381 -          return;
   1.382 -        }
   1.383 -      }   
   1.384 -    }
   1.385 -
   1.386 -    public IHardware[] Hardware {
   1.387 -      get {
   1.388 -        return hardware.ToArray();
   1.389 -      }
   1.390 -    }
   1.391 -
   1.392 -    public string GetReport() {
   1.393 -      if (report.Length > 0) {
   1.394 -        report.Insert(0, "LPCIO" + Environment.NewLine +
   1.395 -          Environment.NewLine);        
   1.396 -        return report.ToString();
   1.397 -      } else
   1.398 -        return null;
   1.399 -    }
   1.400 -
   1.401 -    public void Close() { }
   1.402 -  }
   1.403 -}