Hardware/LPC/Winbond.cs
author moel.mich
Sun, 07 Feb 2010 20:11:30 +0000
changeset 32 a7f5e400f0da
permissions -rw-r--r--
Release version 0.1.14. Added more report details for T-Balancer bigNG.
moel@31
     1
/*
moel@31
     2
  
moel@31
     3
  Version: MPL 1.1/GPL 2.0/LGPL 2.1
moel@31
     4
moel@31
     5
  The contents of this file are subject to the Mozilla Public License Version
moel@31
     6
  1.1 (the "License"); you may not use this file except in compliance with
moel@31
     7
  the License. You may obtain a copy of the License at
moel@31
     8
 
moel@31
     9
  http://www.mozilla.org/MPL/
moel@31
    10
moel@31
    11
  Software distributed under the License is distributed on an "AS IS" basis,
moel@31
    12
  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
moel@31
    13
  for the specific language governing rights and limitations under the License.
moel@31
    14
moel@31
    15
  The Original Code is the Open Hardware Monitor code.
moel@31
    16
moel@31
    17
  The Initial Developer of the Original Code is 
moel@31
    18
  Michael Möller <m.moeller@gmx.ch>.
moel@31
    19
  Portions created by the Initial Developer are Copyright (C) 2009-2010
moel@31
    20
  the Initial Developer. All Rights Reserved.
moel@31
    21
moel@31
    22
  Contributor(s):
moel@31
    23
moel@31
    24
  Alternatively, the contents of this file may be used under the terms of
moel@31
    25
  either the GNU General Public License Version 2 or later (the "GPL"), or
moel@31
    26
  the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
moel@31
    27
  in which case the provisions of the GPL or the LGPL are applicable instead
moel@31
    28
  of those above. If you wish to allow use of your version of this file only
moel@31
    29
  under the terms of either the GPL or the LGPL, and not to allow others to
moel@31
    30
  use your version of this file under the terms of the MPL, indicate your
moel@31
    31
  decision by deleting the provisions above and replace them with the notice
moel@31
    32
  and other provisions required by the GPL or the LGPL. If you do not delete
moel@31
    33
  the provisions above, a recipient may use your version of this file under
moel@31
    34
  the terms of any one of the MPL, the GPL or the LGPL.
moel@31
    35
 
moel@31
    36
*/
moel@31
    37
moel@31
    38
using System;
moel@31
    39
using System.Collections.Generic;
moel@31
    40
using System.Drawing;
moel@31
    41
using System.Text;
moel@31
    42
moel@31
    43
namespace OpenHardwareMonitor.Hardware.LPC {
moel@31
    44
  public abstract class Winbond : LPCHardware {
moel@31
    45
moel@31
    46
    private ushort address;
moel@31
    47
    private byte revision;
moel@31
    48
moel@31
    49
    private bool available;
moel@31
    50
moel@31
    51
    // Consts 
moel@31
    52
    private const ushort WINBOND_VENDOR_ID = 0x5CA3;
moel@31
    53
    private const byte HIGH_BYTE = 0x80;
moel@31
    54
moel@31
    55
    // Hardware Monitor
moel@31
    56
    private const byte ADDRESS_REGISTER_OFFSET = 0x05;
moel@31
    57
    private const byte DATA_REGISTER_OFFSET = 0x06;
moel@31
    58
moel@31
    59
    // Hardware Monitor Registers
moel@31
    60
    private const byte BANK_SELECT_REGISTER = 0x04E;
moel@31
    61
    private const byte VENDOR_ID_REGISTER = 0x4F;
moel@31
    62
moel@31
    63
    protected byte ReadByte(byte bank, byte register) {
moel@31
    64
      WinRing0.WriteIoPortByte(
moel@31
    65
         (ushort)(address + ADDRESS_REGISTER_OFFSET), BANK_SELECT_REGISTER);
moel@31
    66
      WinRing0.WriteIoPortByte(
moel@31
    67
         (ushort)(address + DATA_REGISTER_OFFSET), bank);
moel@31
    68
      WinRing0.WriteIoPortByte(
moel@31
    69
         (ushort)(address + ADDRESS_REGISTER_OFFSET), register);
moel@31
    70
      return WinRing0.ReadIoPortByte(
moel@31
    71
        (ushort)(address + DATA_REGISTER_OFFSET));
moel@31
    72
    } 
moel@31
    73
moel@31
    74
    private bool IsWinbondVendor() {
moel@31
    75
      ushort vendorId =
moel@31
    76
        (ushort)((ReadByte(HIGH_BYTE, VENDOR_ID_REGISTER) << 8) |
moel@31
    77
           ReadByte(0, VENDOR_ID_REGISTER));
moel@31
    78
      return vendorId == WINBOND_VENDOR_ID;
moel@31
    79
    }
moel@31
    80
moel@31
    81
    public Winbond(Chip chip, byte revision, ushort address)
moel@31
    82
      : base(chip) 
moel@31
    83
    {
moel@31
    84
      this.address = address;
moel@31
    85
      this.revision = revision;
moel@31
    86
moel@31
    87
      available = IsWinbondVendor();
moel@31
    88
    }
moel@31
    89
moel@31
    90
    public bool IsAvailable {
moel@31
    91
      get { return available; }
moel@31
    92
    }    
moel@31
    93
   
moel@31
    94
    public string GetReport() {
moel@31
    95
      StringBuilder r = new StringBuilder();
moel@31
    96
moel@31
    97
      r.AppendLine("LPC " + this.GetType().Name);
moel@31
    98
      r.AppendLine();
moel@31
    99
      r.Append("Chip ID: 0x"); r.AppendLine(chip.ToString("X"));
moel@31
   100
      r.Append("Chip revision: 0x"); r.AppendLine(revision.ToString("X"));
moel@31
   101
      r.Append("Base Adress: 0x"); r.AppendLine(address.ToString("X4"));
moel@31
   102
      r.AppendLine();
moel@31
   103
      r.AppendLine("Hardware Monitor Registers");
moel@31
   104
      r.AppendLine();
moel@31
   105
      r.AppendLine("      00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F");
moel@31
   106
      r.AppendLine();
moel@31
   107
      for (int i = 0; i < 0x7; i++) {
moel@31
   108
        r.Append(" "); r.Append((i << 4).ToString("X2")); r.Append("  ");
moel@31
   109
        for (int j = 0; j <= 0xF; j++) {
moel@31
   110
          r.Append(" ");
moel@31
   111
          r.Append(ReadByte(0, (byte)((i << 4) | j)).ToString("X2"));
moel@31
   112
        }
moel@31
   113
        r.AppendLine();
moel@31
   114
      }
moel@31
   115
      for (int k = 1; k <= 5; k++) {
moel@31
   116
        r.AppendLine("Bank " + k);
moel@31
   117
        for (int i = 0x5; i < 0x6; i++) {
moel@31
   118
          r.Append(" "); r.Append((i << 4).ToString("X2")); r.Append("  ");
moel@31
   119
          for (int j = 0; j <= 0xF; j++) {
moel@31
   120
            r.Append(" ");
moel@31
   121
            r.Append(ReadByte((byte)(k),
moel@31
   122
              (byte)((i << 4) | j)).ToString("X2"));
moel@31
   123
          }
moel@31
   124
          r.AppendLine();
moel@31
   125
        }
moel@31
   126
      }
moel@31
   127
      r.AppendLine();
moel@31
   128
moel@31
   129
      return r.ToString();
moel@31
   130
    }
moel@31
   131
  }
moel@31
   132
}