Add support for the LPC47M182 to superiotool
[coreboot.git] / util / superiotool / superiotool.h
1 /*
2  * This file is part of the superiotool project.
3  *
4  * Copyright (C) 2007 Carl-Daniel Hailfinger
5  * Copyright (C) 2007 Uwe Hermann <uwe@hermann-uwe.de>
6  * Copyright (C) 2008 Robinson P. Tryon <bishop.robinson@gmail.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
21  */
22
23 #ifndef SUPERIOTOOL_H
24 #define SUPERIOTOOL_H
25
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <stdint.h>
29 #include <string.h>
30 #include <getopt.h>
31 #if defined(__GLIBC__)
32 #include <sys/io.h>
33 #endif
34
35 #if defined(__FreeBSD__)
36 #include <sys/types.h>
37 #include <machine/cpufunc.h>
38 #define OUTB(x, y) do { u_int tmp = (y); outb(tmp, (x)); } while (0)
39 #define OUTW(x, y) do { u_int tmp = (y); outw(tmp, (x)); } while (0)
40 #define OUTL(x, y) do { u_int tmp = (y); outl(tmp, (x)); } while (0)
41 #define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })
42 #define INW(x) __extension__ ({ u_int tmp = (x); inw(tmp); })
43 #define INL(x) __extension__ ({ u_int tmp = (x); inl(tmp); })
44 #else
45 #define OUTB outb
46 #define OUTW outw
47 #define OUTL outl
48 #define INB  inb
49 #define INW  inw
50 #define INL  inl
51 #endif
52
53 #define USAGE "Usage: superiotool [-d] [-e] [-l] [-V] [-v] [-h]\n\n\
54   -d | --dump            Dump Super I/O register contents\n\
55   -e | --extra-dump      Dump secondary registers too (e.g. EC registers)\n\
56   -l | --list-supported  Show the list of supported Super I/O chips\n\
57   -V | --verbose         Verbose mode\n\
58   -v | --version         Show the superiotool version\n\
59   -h | --help            Show a short help text\n\n"
60
61 #define USAGE_INFO "\
62 Per default (no options) superiotool will just probe for a Super I/O\n\
63 and print its vendor, name, ID, revision, and config port.\n"
64
65 #define NOTFOUND "  Failed. Returned data: "
66
67 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
68
69 #define EOT             -1              /* End Of Table */
70 #define NOLDN           -2              /* NO LDN needed */
71 #define NANA            -3              /* Not Available */
72 #define RSVD            -4              /* Reserved */
73 #define MISC            -5              /* Needs special comment in output */
74 #define MAXLDN          0x14            /* Biggest LDN */
75 #define LDNSIZE         (MAXLDN + 3)    /* Biggest LDN + 0 + NOLDN + EOT */
76 #define MAXNUMIDX       170             /* Maximum number of indices */
77 #define IDXSIZE         (MAXNUMIDX + 1)
78 #define MAXNUMPORTS     (6 + 1)         /* Maximum number of Super I/O ports */
79
80 /* Select registers for various components. */
81 #define LDN_SEL         0x07            /* LDN select register */
82 #define WINBOND_HWM_SEL 0x4e            /* Hardware monitor bank select */
83
84 /* Command line parameters. */
85 extern int dump, verbose, extra_dump;
86
87 extern int chip_found;
88
89 struct superio_registers {
90         int32_t superio_id;             /* Signed, as we need EOT. */
91         const char *name;               /* Super I/O name */
92         struct {
93                 int8_t ldn;
94                 const char *name;       /* LDN name */
95                 int16_t idx[IDXSIZE];
96                 int16_t def[IDXSIZE];
97         } ldn[LDNSIZE];
98 };
99
100 /* superiotool.c */
101 uint8_t regval(uint16_t port, uint8_t reg);
102 void regwrite(uint16_t port, uint8_t reg, uint8_t val);
103 void enter_conf_mode_winbond_fintek_ite_8787(uint16_t port);
104 void exit_conf_mode_winbond_fintek_ite_8787(uint16_t port);
105 int superio_unknown(const struct superio_registers reg_table[], uint16_t id);
106 const char *get_superio_name(const struct superio_registers reg_table[],
107                              uint16_t id);
108 void dump_superio(const char *name, const struct superio_registers reg_table[],
109                   uint16_t port, uint16_t id, uint8_t ldn_sel);
110 void dump_io(uint16_t iobase, uint16_t length);
111 void probing_for(const char *vendor, const char *info, uint16_t port);
112 void print_vendor_chips(const char *vendor,
113                         const struct superio_registers reg_table[]);
114
115 /* ali.c */
116 void probe_idregs_ali(uint16_t port);
117 void print_ali_chips(void);
118
119 /* fintek.c */
120 void probe_idregs_fintek(uint16_t port);
121 void print_fintek_chips(void);
122
123 /* ite.c */
124 void probe_idregs_ite(uint16_t port);
125 void print_ite_chips(void);
126
127 /* nsc.c */
128 void probe_idregs_nsc(uint16_t port);
129 void print_nsc_chips(void);
130
131 /* smsc.c */
132 void probe_idregs_smsc(uint16_t port);
133 void print_smsc_chips(void);
134
135 /* winbond.c */
136 void probe_idregs_winbond(uint16_t port);
137 void print_winbond_chips(void);
138
139 /** Table of which config ports to probe for each Super I/O family. */
140 static const struct {
141         void (*probe_idregs) (uint16_t port);
142         int ports[MAXNUMPORTS]; /* Signed, as we need EOT. */
143 } superio_ports_table[] = {
144         {probe_idregs_ali,      {0x3f0, 0x370, EOT}},
145         {probe_idregs_fintek,   {0x2e, 0x4e, EOT}},
146         /* Only use 0x370 for ITE, but 0x3f0 or 0x3bd would also be valid. */
147         {probe_idregs_ite,      {0x2e, 0x4e, 0x370, EOT}},
148         {probe_idregs_nsc,      {0x2e, 0x4e, 0x15c, EOT}},
149         {probe_idregs_smsc,     {0x2e, 0x4e, 0x162e, 0x164e, 0x3f0, 0x370, EOT}},
150         {probe_idregs_winbond,  {0x2e, 0x4e, 0x3f0, 0x370, 0x250, EOT}},
151 };
152
153 /** Table of functions to print out supported Super I/O chips. */
154 static const struct {
155         void (*print_list) (void);
156 } vendor_print_functions[] = {
157         {print_ali_chips},
158         {print_fintek_chips},
159         {print_ite_chips},
160         {print_nsc_chips},
161         {print_smsc_chips},
162         {print_winbond_chips},
163 };
164
165 #endif