moel@1: /* moel@1: moel@1: Version: MPL 1.1/GPL 2.0/LGPL 2.1 moel@1: moel@1: The contents of this file are subject to the Mozilla Public License Version moel@1: 1.1 (the "License"); you may not use this file except in compliance with moel@1: the License. You may obtain a copy of the License at moel@1: moel@1: http://www.mozilla.org/MPL/ moel@1: moel@1: Software distributed under the License is distributed on an "AS IS" basis, moel@1: WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License moel@1: for the specific language governing rights and limitations under the License. moel@1: moel@1: The Original Code is the Open Hardware Monitor code. moel@1: moel@1: The Initial Developer of the Original Code is moel@1: Michael Möller . moel@1: Portions created by the Initial Developer are Copyright (C) 2009-2010 moel@1: the Initial Developer. All Rights Reserved. moel@1: moel@1: Contributor(s): moel@1: moel@1: Alternatively, the contents of this file may be used under the terms of moel@1: either the GNU General Public License Version 2 or later (the "GPL"), or moel@1: the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), moel@1: in which case the provisions of the GPL or the LGPL are applicable instead moel@1: of those above. If you wish to allow use of your version of this file only moel@1: under the terms of either the GPL or the LGPL, and not to allow others to moel@1: use your version of this file under the terms of the MPL, indicate your moel@1: decision by deleting the provisions above and replace them with the notice moel@1: and other provisions required by the GPL or the LGPL. If you do not delete moel@1: the provisions above, a recipient may use your version of this file under moel@1: the terms of any one of the MPL, the GPL or the LGPL. moel@1: moel@1: */ moel@1: moel@1: using System; moel@1: using System.Collections.Generic; moel@1: using System.Text; moel@1: using System.Threading; moel@1: moel@1: namespace OpenHardwareMonitor.Hardware.LPC { moel@1: public class LPCGroup : IGroup { moel@1: private List hardware = new List(); moel@1: moel@1: private Chip chip = Chip.Unknown; moel@1: moel@1: // I/O Ports moel@7: private ushort[] REGISTER_PORTS = new ushort[] { 0x2e, 0x4e }; moel@7: private ushort[] VALUE_PORTS = new ushort[] { 0x2f, 0x4f }; moel@7: moel@7: private ushort registerPort; moel@7: private ushort valuePort; moel@1: moel@1: // Registers moel@1: private const byte CONFIGURATION_CONTROL_REGISTER = 0x02; moel@1: private const byte DEVCIE_SELECT_REGISTER = 0x07; moel@1: private const byte CHIP_ID_REGISTER = 0x20; moel@1: private const byte CHIP_REVISION_REGISTER = 0x21; moel@7: private const byte BASE_ADDRESS_REGISTER = 0x60; moel@1: moel@7: private byte ReadByte(byte register) { moel@7: WinRing0.WriteIoPortByte(registerPort, register); moel@7: return WinRing0.ReadIoPortByte(valuePort); moel@13: } moel@1: moel@7: private ushort ReadWord(byte register) { moel@7: return (ushort)((ReadByte(register) << 8) | moel@7: ReadByte((byte)(register + 1))); moel@1: } moel@1: moel@7: private void Select(byte logicalDeviceNumber) { moel@7: WinRing0.WriteIoPortByte(registerPort, DEVCIE_SELECT_REGISTER); moel@7: WinRing0.WriteIoPortByte(valuePort, logicalDeviceNumber); moel@1: } moel@1: moel@1: // IT87 moel@1: private const ushort IT8716F_CHIP_ID = 0x8716; moel@1: private const ushort IT8718F_CHIP_ID = 0x8718; moel@1: private const ushort IT8720F_CHIP_ID = 0x8720; moel@1: private const ushort IT8726F_CHIP_ID = 0x8726; moel@1: moel@7: private const byte IT87_ENVIRONMENT_CONTROLLER_LDN = 0x04; moel@1: moel@7: private void IT87Enter() { moel@7: WinRing0.WriteIoPortByte(registerPort, 0x87); moel@7: WinRing0.WriteIoPortByte(registerPort, 0x01); moel@7: WinRing0.WriteIoPortByte(registerPort, 0x55); moel@7: WinRing0.WriteIoPortByte(registerPort, 0x55); moel@1: } moel@1: moel@7: internal void IT87Exit() { moel@7: WinRing0.WriteIoPortByte(registerPort, CONFIGURATION_CONTROL_REGISTER); moel@7: WinRing0.WriteIoPortByte(valuePort, 0x02); moel@1: } moel@1: moel@7: // Winbond, Fintek moel@7: private const byte FINTEK_VENDOR_ID_REGISTER = 0x23; moel@7: private const ushort FINTEK_VENDOR_ID = 0x1934; moel@7: moel@7: private const byte W83627DHG_HARDWARE_MONITOR_LDN = 0x0B; moel@7: private const byte F71882FG_HARDWARE_MONITOR_LDN = 0x04; moel@7: moel@7: private void WinbondFintekEnter() { moel@7: WinRing0.WriteIoPortByte(registerPort, 0x87); moel@7: WinRing0.WriteIoPortByte(registerPort, 0x87); moel@1: } moel@1: moel@7: private void WinbondFintekExit() { moel@7: WinRing0.WriteIoPortByte(registerPort, 0xAA); moel@1: } moel@1: moel@1: public LPCGroup() { moel@1: if (!WinRing0.IsAvailable) moel@1: return; moel@1: moel@7: for (int i = 0; i < REGISTER_PORTS.Length; i++) { moel@7: registerPort = REGISTER_PORTS[i]; moel@7: valuePort = VALUE_PORTS[i]; moel@1: moel@7: WinbondFintekEnter(); moel@1: moel@7: byte hardwareMonitorLDN; moel@7: byte id = ReadByte(CHIP_ID_REGISTER); moel@7: byte revision = ReadByte(CHIP_REVISION_REGISTER); moel@7: switch (id) { moel@7: case 0xA0: moel@7: switch (revision & 0xF0) { moel@7: case 0x20: moel@7: chip = Chip.W83627DHG; moel@7: hardwareMonitorLDN = W83627DHG_HARDWARE_MONITOR_LDN; moel@7: break; moel@7: default: moel@7: chip = Chip.Unknown; moel@7: hardwareMonitorLDN = 0; moel@7: break; moel@7: } break; moel@7: case 0x05: moel@7: switch (revision) { moel@7: case 0x41: moel@7: chip = Chip.F71882FG; moel@7: hardwareMonitorLDN = F71882FG_HARDWARE_MONITOR_LDN; moel@7: break; moel@7: default: moel@7: chip = Chip.Unknown; moel@7: hardwareMonitorLDN = 0; moel@7: break; moel@7: } break; moel@7: default: moel@7: chip = Chip.Unknown; moel@7: hardwareMonitorLDN = 0; moel@7: break; moel@7: } moel@7: if (chip != Chip.Unknown) { moel@1: moel@7: Select(hardwareMonitorLDN); moel@7: ushort address = ReadWord(BASE_ADDRESS_REGISTER); moel@7: Thread.Sleep(1); moel@7: ushort verify = ReadWord(BASE_ADDRESS_REGISTER); moel@1: moel@7: ushort vendorID = 0; moel@7: if (chip == Chip.F71882FG) moel@7: vendorID = ReadWord(FINTEK_VENDOR_ID_REGISTER); moel@1: moel@7: WinbondFintekExit(); moel@1: moel@7: if (address != verify || address == 0 || (address & 0xF007) != 0) moel@7: return; moel@7: moel@7: switch (chip) { moel@7: case Chip.W83627DHG: moel@7: W83627DHG w83627dhg = new W83627DHG(revision, address); moel@7: if (w83627dhg.IsAvailable) moel@7: hardware.Add(w83627dhg); moel@7: break; moel@7: case Chip.F71882FG: moel@7: if (vendorID == FINTEK_VENDOR_ID) moel@9: hardware.Add(new F71882(address)); moel@7: break; moel@7: default: break; moel@7: } moel@7: moel@7: return; moel@7: } moel@1: moel@7: IT87Enter(); moel@1: moel@7: switch (ReadWord(CHIP_ID_REGISTER)) { moel@7: case 0x8716: chip = Chip.IT8716F; break; moel@7: case 0x8718: chip = Chip.IT8718F; break; moel@7: case 0x8720: chip = Chip.IT8720F; break; moel@7: case 0x8726: chip = Chip.IT8726F; break; moel@7: default: chip = Chip.Unknown; break; moel@7: } moel@7: moel@7: if (chip != Chip.Unknown) { moel@7: Select(IT87_ENVIRONMENT_CONTROLLER_LDN); moel@7: ushort address = ReadWord(BASE_ADDRESS_REGISTER); moel@7: Thread.Sleep(1); moel@7: ushort verify = ReadWord(BASE_ADDRESS_REGISTER); moel@7: moel@7: IT87Exit(); moel@7: moel@7: if (address != verify || address == 0 || (address & 0xF007) != 0) moel@7: return; moel@7: moel@7: IT87 it87 = new IT87(chip, address); moel@7: if (it87.IsAvailable) moel@7: hardware.Add(it87); moel@7: moel@1: return; moel@7: } moel@7: } moel@1: } moel@1: moel@1: public IHardware[] Hardware { moel@1: get { moel@1: return hardware.ToArray(); moel@1: } moel@1: } moel@1: moel@1: public string GetReport() { moel@1: return null; moel@1: } moel@1: moel@1: public void Close() { } moel@1: } moel@1: }