remove trailing whitespace
[coreboot.git] / util / superiotool / nuvoton.c
1 /*
2  * This file is part of the superiotool project.
3  *
4  * Copyright (C) 2010 Google Inc.
5  * Written by David Hendricks <dhendrix@google.com> for Nuvoton Technology Corp.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20  */
21
22 #include "superiotool.h"
23
24 #define DEVICE_ID_REG           0x20    /* Super I/O ID (SID) / family */
25 #define DEVICE_REV_REG          0x27    /* Super I/O revision ID (SRID) */
26
27 static const struct superio_registers reg_table[] = {
28         {0xfc, "WPCE775x / NPCE781x", {
29                 {NOLDN, NULL,
30                         {0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,
31                          0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,EOT},
32                         {0xfc,0x11,RSVD,RSVD,RSVD,0x00,0x00,MISC,0x00,
33                          0x04,RSVD,RSVD,RSVD,0x00,RSVD,RSVD,EOT}},
34                 {0x03, "CIR Port (CIRP)",       /* where supported */
35                         {0x30,0x60,0x61,0x70,0x71,0x74,0x75,0xf0,EOT},
36                         {0x00,0x03,0xf8,0x04,0x03,0x04,0x04,0x02,EOT}},
37                 {0x04, "Mobile System Wake-Up Control Config (MSWC)",
38                         {0x30,0x60,0x61,0x70,0x71,0x74,0x75,EOT},
39                         {0x00,0x00,0x00,0x00,0x03,0x04,0x04,EOT}},
40                 {0x05, "Mouse config (KBC)",
41                         {0x30,0x70,0x71,0x74,0x75,EOT},
42                         {0x00,0x0c,0x03,0x04,0x04,EOT}},
43                 {0x06, "Keyboard config (KBC)",
44                         {0x30,0x60,0x61,0x62,0x63,0x70,0x71,0x74,0x75,EOT},
45                         {0x00,0x00,0x60,0x00,0x64,0x01,0x03,0x04,0x04,EOT}},
46                 {0x0f, "Shared memory (SHM)",
47                         {0x30,0x60,0x61,0x70,0x71,0x74,0x75,0xf0,0xf1,0xf2,
48                         0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,EOT},
49                         {0x00,0x00,0x00,0x00,0x00,0x04,0x04,MISC,0x07,RSVD,
50                         RSVD,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,EOT}},
51                 {0x11, "Power management I/F Channel 1 (PM1)",
52                         {0x30,0x60,0x61,0x62,0x63,0x70,0x71,0x74,0x75,EOT},
53                         {0x00,0x00,0x62,0x00,0x66,0x01,0x03,0x04,0x04,EOT}},
54                 {0x12, "Power management I/F Channel 2 (PM2)",
55                         {0x30,0x60,0x61,0x62,0x63,0x70,0x71,0x74,0x75,EOT},
56                         {0x00,0x00,0x68,0x00,0x6c,0x01,0x03,0x04,0x04,EOT}},
57                 {0x15, "Enhanced Wake On CIR (EWOC)",
58                         {0x30,0x60,0x61,0x62,0x63,0x70,0x71,0x74,0x75,EOT},
59                         {0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x04,0x04,EOT}},
60                 {0x17, "Power Management I/F Channel 3 (PM3)",
61                         {0x30,0x60,0x61,0x62,0x63,0x70,0x71,0x74,0x75,EOT},
62                         {0x00,0x00,0x6a,0x00,0x6e,0x01,0x03,0x04,0x04,EOT}},
63                 {0x1a, "Serial Port with Fast Infrared Port (FIR)",
64                         {0x30,0x60,0x61,0x70,0x71,0x74,0x75,0xf0,EOT},
65                         {0x00,0x02,0xf8,0x03,0x03,0x04,0x04,0x02,EOT}},
66                 {EOT}}},
67         {0x1a, "WPCM450", {
68                 {EOT}}},
69         {0xc332, "NCT6776F (B)", {
70                 {NOLDN, NULL,
71                         {0x10,0x11,0x13,0x14,0x16,0x17,0x18,0x19,0x1a,
72                          0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,
73                          0x24,0x25,0x26,0x27,0x28,0x2a,0x2b,0x2c,0x2d,
74                          0x2e,0x2f,EOT},
75                         {0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xf0,
76                          0x78,0x00,0x00,0xff,0xff,0xc3,0x32,0xff,0x00,
77                          0x64,0x00,MISC,0x00,0x00,0xc0,0x00,0x81,0x00,
78                          0x00,MISC,EOT}},
79                 {0x00, "FDC",
80                         {0x30,0x60,0x61,0x70,0x74,0xf0,0xf1,0xf2,0xf4,
81                          0xf5,EOT},
82                         {0x01,0x03,0xf0,0x06,0x02,0x0e,0x00,0xff,0x00,
83                          0x00,EOT}},
84                 {0x01, "Parallel Port",
85                         {0x30,0x60,0x61,0x70,0x74,0xf0,EOT},
86                         {0x01,0x03,0x78,0x07,0x04,0x3f,EOT}},
87                 {0x02, "UART A",
88                         {0x30,0x60,0x61,0x70,0xf0,0xf2,EOT},
89                         {0x01,0x03,0xf8,0x04,0x00,0x00,EOT}},
90                 {0x03, "UART B, IR",
91                         {0x30,0x60,0x61,0x70,0xf0,0xf1,0xf2,EOT},
92                         {0x01,0x02,0xf8,0x03,0x00,0x00,0x00,EOT}},
93                 {0x05, "Keyboard Controller",
94                         {0x30,0x60,0x61,0x62,0x63,0x70,0x72,0xf0,EOT},
95                         {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x83,EOT}},
96                 {0x06, "CIR",
97                         {0x30,0x60,0x61,0x70,0xf0,0xf1,0xf2,0xf3,EOT},
98                         {0x00,0x00,0x00,0x00,0x08,0x09,0x32,0x00,EOT}},
99                 {0x07, "GPIO6, GPIO7, GPIO8, GPIO9",
100                         {0x30,0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,
101                          0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xf4,0xf5,
102                          0xf6,0xf7,0xf8,EOT},
103                         {0x03,0xff,0x00,0x00,0x00,0xef,0x00,0x00,0x00,
104                          0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x00,
105                          0x00,0x00,0x00,EOT}},
106                 {0x08, "WDT1, GPIO0, GPIO1, GPIOA",
107                         {0x30,0x60,0x61,0xe0,0xe1,0xe2,0xe3,0xe4,0xf0,
108                          0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,EOT},
109                         {0x02,0x00,0x00,0xff,0x00,0x00,0x00,0xef,0xff,
110                          0x00,0x00,0x00,0x00,0x00,0x00,0x00,EOT}},
111                 {0x09, "GPIO2, GPIO3, GPIO4, GPIO5",
112                         {0x30,0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,
113                          0xe8,0xe9,0xea,0xeb,0xee,0xf0,0xf1,0xf2,0xf4,
114                          0xf5,0xf6,0xf7,0xfe,EOT},
115                         {0x04,0xdf,0x00,0x00,0x00,0xff,0x00,0x00,0x00,
116                          0x00,0x00,0x00,0x00,0x00,0xff,0x00,0x00,0xff,
117                          0x00,0x00,0x00,0x00,EOT}},
118                 {0x0a, "ACPI",
119                         {0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe9,
120                          0xee,0xf0,0xf2,0xf3,0xf4,0xf6,0xf7,0xfe,EOT},
121                         {0x01,0x00,0x00,0x00,0x00,0x02,0x1c,0x00,0x00,
122                          0x00,0x00,0x00,0x00,0x00,0x00,0xc0,0x00,EOT}},
123                 {0x0b, "Hardware Monitor, Front Panel LED",
124                         {0x30,0x60,0x61,0x62,0x63,0x70,0xe0,0xe1,0xe2,
125                          0xf0,0xf1,0xf2,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,
126                          EOT},
127                         {0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x7f,0xff,
128                          0x00,0x00,0x00,0x10,0x00,0x87,0x47,0x00,0x00,
129                          EOT}},
130                 {0x0d, "VID",
131                         {0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe9,0xee,
132                          0xef,0xf0,0xf4,0xf5,EOT},
133                         {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x88,
134                          0x00,0x00,0x00,0x00,EOT}},
135                 {0x0e, "CIR WAKE-UP",
136                         {0x30,0x60,0x61,0x70,EOT},
137                         {0x00,0x00,0x00,0x00,EOT}},
138                 {0x0f, "GPIO Push-Pull or Open-drain",
139                         {0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,
140                          0xe9,0xf0,0xf1,0xf2,EOT},
141                         {0xff,0xdf,0xff,0xfe,0xf6,0xff,0xff,0xd3,0xff,
142                          0x9f,0x00,0x00,0x00,EOT}},
143                 {0x14, "SVID",
144                         {0xe0,0xe1,0xe3,0xe4,EOT},
145                         {0x00,0x80,0x00,0x00,EOT}},
146                 {0x16, "Deep Sleep",
147                         {0x30,0xe0,0xe1,0xe2,EOT},
148                         {0x20,0x20,0x04,0x05,EOT}},
149                 {0x17, "GPIOA",
150                         {0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,EOT},
151                         {0x01,0x00,0x00,0x00,0x01,0x00,EOT}},
152                 {EOT}}},
153         {0xc333, "NCT6776F (C)", {
154                 {NOLDN, NULL,
155                         {0x10,0x11,0x13,0x14,0x16,0x17,0x18,0x19,0x1a,
156                          0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,
157                          0x24,0x25,0x26,0x27,0x28,0x2a,0x2b,0x2c,0x2d,
158                          0x2e,0x2f,EOT},
159                         {0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xf0,
160                          0x78,0x00,0x00,0xff,0xff,0xc3,0x33,0xff,0x00,
161                          0x64,0x00,MISC,0x00,0x00,0xc0,0x00,0x81,0x00,
162                          0x00,MISC,EOT}},
163                 {0x00, "FDC",
164                         {0x30,0x60,0x61,0x70,0x74,0xf0,0xf1,0xf2,0xf4,
165                          0xf5,EOT},
166                         {0x01,0x03,0xf0,0x06,0x02,0x0e,0x00,0xff,0x00,
167                          0x00,EOT}},
168                 {0x01, "Parallel Port",
169                         {0x30,0x60,0x61,0x70,0x74,0xf0,EOT},
170                         {0x01,0x03,0x78,0x07,0x04,0x3f,EOT}},
171                 {0x02, "UART A",
172                         {0x30,0x60,0x61,0x70,0xf0,0xf2,EOT},
173                         {0x01,0x03,0xf8,0x04,0x00,0x00,EOT}},
174                 {0x03, "UART B, IR",
175                         {0x30,0x60,0x61,0x70,0xf0,0xf1,0xf2,EOT},
176                         {0x01,0x02,0xf8,0x03,0x00,0x00,0x00,EOT}},
177                 {0x05, "Keyboard Controller",
178                         {0x30,0x60,0x61,0x62,0x63,0x70,0x72,0xf0,EOT},
179                         {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x83,EOT}},
180                 {0x06, "CIR",
181                         {0x30,0x60,0x61,0x70,0xf0,0xf1,0xf2,0xf3,EOT},
182                         {0x00,0x00,0x00,0x00,0x08,0x09,0x32,0x00,EOT}},
183                 {0x07, "GPIO6, GPIO7, GPIO8, GPIO9",
184                         {0x30,0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,
185                          0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xf4,0xf5,
186                          0xf6,0xf7,0xf8,EOT},
187                         {0x03,0xff,0x00,0x00,0x00,0xef,0x00,0x00,0x00,
188                          0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x00,
189                          0x00,0x00,0x00,EOT}},
190                 {0x08, "WDT1, GPIO0, GPIO1, GPIOA",
191                         {0x30,0x60,0x61,0xe0,0xe1,0xe2,0xe3,0xe4,0xf0,
192                          0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,EOT},
193                         {0x02,0x00,0x00,0xff,0x00,0x00,0x00,0xef,0xff,
194                          0x00,0x00,0x00,0x00,0x00,0x00,0x00,EOT}},
195                 {0x09, "GPIO2, GPIO3, GPIO4, GPIO5",
196                         {0x30,0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,
197                          0xe8,0xe9,0xea,0xeb,0xee,0xf0,0xf1,0xf2,0xf4,
198                          0xf5,0xf6,0xf7,0xfe,EOT},
199                         {0x04,0xdf,0x00,0x00,0x00,0xff,0x00,0x00,0x00,
200                          0x00,0x00,0x00,0x00,0x00,0xff,0x00,0x00,0xff,
201                          0x00,0x00,0x00,0x00,EOT}},
202                 {0x0a, "ACPI",
203                         {0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe9,
204                          0xee,0xf0,0xf2,0xf3,0xf4,0xf6,0xf7,0xfe,EOT},
205                         {0x01,0x00,0x00,0x00,0x00,0x02,0x1c,0x00,0x00,
206                          0x00,0x00,0x00,0x00,0x00,0x00,0xc0,0x00,EOT}},
207                 {0x0b, "Hardware Monitor, Front Panel LED",
208                         {0x30,0x60,0x61,0x62,0x63,0x70,0xe0,0xe1,0xe2,
209                          0xf0,0xf1,0xf2,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,
210                          EOT},
211                         {0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x7f,0xff,
212                          0x00,0x00,0x00,0x10,0x00,0x87,0x47,0x00,0x00,
213                          EOT}},
214                 {0x0d, "VID",
215                         {0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe9,0xee,
216                          0xef,0xf0,0xf4,0xf5,EOT},
217                         {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x88,
218                          0x00,0x00,0x00,0x00,EOT}},
219                 {0x0e, "CIR WAKE-UP",
220                         {0x30,0x60,0x61,0x70,EOT},
221                         {0x00,0x00,0x00,0x00,EOT}},
222                 {0x0f, "GPIO Push-Pull or Open-drain",
223                         {0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,
224                          0xe9,0xf0,0xf1,0xf2,EOT},
225                         {0xff,0xdf,0xff,0xfe,0xf6,0xff,0xff,0xd3,0xff,
226                          0x9f,0x00,0x00,0x00,EOT}},
227                 {0x14, "SVID",
228                         {0xe0,0xe1,0xe3,0xe4,EOT},
229                         {0x00,0x80,0x00,0x00,EOT}},
230                 {0x16, "Deep Sleep",
231                         {0x30,0xe0,0xe1,0xe2,EOT},
232                         {0x20,0x20,0x04,0x05,EOT}},
233                 {0x17, "GPIOA",
234                         {0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,EOT},
235                         {0x01,0x00,0x00,0x00,0x01,0x00,EOT}},
236                 {EOT}}},
237         {EOT}
238 };
239
240 void probe_idregs_nuvoton(uint16_t port)
241 {
242         uint8_t sid, srid;
243         uint16_t chip_id = 0;
244         uint8_t chip_rev = 0;
245
246         /* Probe for the 16bit IDs first to avoid collisions */
247         probing_for("Nuvoton", "", port);
248         enter_conf_mode_winbond_fintek_ite_8787(port);
249         chip_id = (regval(port, DEVICE_ID_REG) << 8) |
250               regval(port, DEVICE_ID_REG + 1);
251
252         exit_conf_mode_winbond_fintek_ite_8787(port);
253
254         if (!superio_unknown(reg_table, chip_id)) {
255                 printf("Found Nuvoton %s (id=0x%02x) at 0x%x\n",
256                        get_superio_name(reg_table, chip_id), chip_id, port);
257                 chip_found = 1;
258                 dump_superio("Nuvoton", reg_table, port, chip_id, LDN_SEL);
259                 return;
260         }
261
262         if (verbose)
263                 printf(NOTFOUND "chip_id=0x%04x\n", chip_id);
264
265         probing_for("Nuvoton", "(sid=0xfc) ", port);
266
267         sid = regval(port, DEVICE_ID_REG);
268         srid = regval(port, DEVICE_REV_REG);
269
270         if (sid == 0xfc) {      /* WPCE775xL family */
271                 /*
272                  * bits 7-5: Chip ID
273                  * bits 4-0: Chip revision
274                  */
275                 chip_id = srid >> 5;
276                 chip_rev = srid & 0x1f;
277         }
278
279         if (superio_unknown(reg_table, sid)) {
280                 if (verbose)
281                         printf(NOTFOUND
282                                "sid=0x%02x, id=0x%02x, rev=0x%02x\n", sid,
283                                chip_id, chip_rev);
284                 return;
285         }
286
287         printf("Found Nuvoton %s (id=0x%02x, rev=0x%02x) at 0x%x\n",
288                get_superio_name(reg_table, sid), chip_id, chip_rev, port);
289         chip_found = 1;
290         dump_superio("Nuvoton", reg_table, port, sid, LDN_SEL);
291 }
292
293 void print_nuvoton_chips(void)
294 {
295         print_vendor_chips("Nuvoton", reg_table);
296 }