1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/Hardware/LPC/Winbond.cs Sun Feb 07 19:53:51 2010 +0000
1.3 @@ -0,0 +1,132 @@
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.Drawing;
1.44 +using System.Text;
1.45 +
1.46 +namespace OpenHardwareMonitor.Hardware.LPC {
1.47 + public abstract class Winbond : LPCHardware {
1.48 +
1.49 + private ushort address;
1.50 + private byte revision;
1.51 +
1.52 + private bool available;
1.53 +
1.54 + // Consts
1.55 + private const ushort WINBOND_VENDOR_ID = 0x5CA3;
1.56 + private const byte HIGH_BYTE = 0x80;
1.57 +
1.58 + // Hardware Monitor
1.59 + private const byte ADDRESS_REGISTER_OFFSET = 0x05;
1.60 + private const byte DATA_REGISTER_OFFSET = 0x06;
1.61 +
1.62 + // Hardware Monitor Registers
1.63 + private const byte BANK_SELECT_REGISTER = 0x04E;
1.64 + private const byte VENDOR_ID_REGISTER = 0x4F;
1.65 +
1.66 + protected byte ReadByte(byte bank, byte register) {
1.67 + WinRing0.WriteIoPortByte(
1.68 + (ushort)(address + ADDRESS_REGISTER_OFFSET), BANK_SELECT_REGISTER);
1.69 + WinRing0.WriteIoPortByte(
1.70 + (ushort)(address + DATA_REGISTER_OFFSET), bank);
1.71 + WinRing0.WriteIoPortByte(
1.72 + (ushort)(address + ADDRESS_REGISTER_OFFSET), register);
1.73 + return WinRing0.ReadIoPortByte(
1.74 + (ushort)(address + DATA_REGISTER_OFFSET));
1.75 + }
1.76 +
1.77 + private bool IsWinbondVendor() {
1.78 + ushort vendorId =
1.79 + (ushort)((ReadByte(HIGH_BYTE, VENDOR_ID_REGISTER) << 8) |
1.80 + ReadByte(0, VENDOR_ID_REGISTER));
1.81 + return vendorId == WINBOND_VENDOR_ID;
1.82 + }
1.83 +
1.84 + public Winbond(Chip chip, byte revision, ushort address)
1.85 + : base(chip)
1.86 + {
1.87 + this.address = address;
1.88 + this.revision = revision;
1.89 +
1.90 + available = IsWinbondVendor();
1.91 + }
1.92 +
1.93 + public bool IsAvailable {
1.94 + get { return available; }
1.95 + }
1.96 +
1.97 + public string GetReport() {
1.98 + StringBuilder r = new StringBuilder();
1.99 +
1.100 + r.AppendLine("LPC " + this.GetType().Name);
1.101 + r.AppendLine();
1.102 + r.Append("Chip ID: 0x"); r.AppendLine(chip.ToString("X"));
1.103 + r.Append("Chip revision: 0x"); r.AppendLine(revision.ToString("X"));
1.104 + r.Append("Base Adress: 0x"); r.AppendLine(address.ToString("X4"));
1.105 + r.AppendLine();
1.106 + r.AppendLine("Hardware Monitor Registers");
1.107 + r.AppendLine();
1.108 + r.AppendLine(" 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F");
1.109 + r.AppendLine();
1.110 + for (int i = 0; i < 0x7; i++) {
1.111 + r.Append(" "); r.Append((i << 4).ToString("X2")); r.Append(" ");
1.112 + for (int j = 0; j <= 0xF; j++) {
1.113 + r.Append(" ");
1.114 + r.Append(ReadByte(0, (byte)((i << 4) | j)).ToString("X2"));
1.115 + }
1.116 + r.AppendLine();
1.117 + }
1.118 + for (int k = 1; k <= 5; k++) {
1.119 + r.AppendLine("Bank " + k);
1.120 + for (int i = 0x5; i < 0x6; i++) {
1.121 + r.Append(" "); r.Append((i << 4).ToString("X2")); r.Append(" ");
1.122 + for (int j = 0; j <= 0xF; j++) {
1.123 + r.Append(" ");
1.124 + r.Append(ReadByte((byte)(k),
1.125 + (byte)((i << 4) | j)).ToString("X2"));
1.126 + }
1.127 + r.AppendLine();
1.128 + }
1.129 + }
1.130 + r.AppendLine();
1.131 +
1.132 + return r.ToString();
1.133 + }
1.134 + }
1.135 +}