Split up superiotool.c into multiple source files, one per vendor.
[coreboot.git] / util / superiotool / ite.c
1 /*
2  * This file is part of the LinuxBIOS project.
3  *
4  * Copyright (C) 2007 Carl-Daniel Hailfinger
5  * Copyright (C) 2007 Uwe Hermann <uwe@hermann-uwe.de>
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 EOT             -1              /* End Of Table */
25 #define NOLDN           -2              /* NO LDN needed */
26 #define NANA            -3              /* Not Available */
27 #define MAXNAMELEN      20              /* Maximum Name Length */
28 #define MAXLDN          0xa             /* Biggest LDN */
29 #define LDNSIZE         (MAXLDN + 3)    /* Biggest LDN + 0 + NOLDN + EOT */
30 #define MAXNUMIDX       70              /* Maximum number of indexes */
31 #define IDXSIZE         (MAXNUMIDX + 1)
32
33 const static struct ite_registers {
34         /* Yes, superio_id should be unsigned, but EOT has to be negative. */
35         signed short superio_id;
36         const char name[MAXNAMELEN];
37         struct ite_ldnidx {
38                 signed short ldn;
39                 signed short idx[IDXSIZE];
40                 signed short def[IDXSIZE];
41         } ldn[LDNSIZE];
42 } ite_reg_table[] = {
43         {0x8702, "IT8702", {
44                 {EOT}}},
45         {0x8705, "IT8705 or IT8700", {
46                 {EOT}}},
47         {0x8708, "IT8708", {
48                 {NOLDN,
49                         {0x07,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,
50                          0x29,0x2a,0x2e,0x2f,EOT},
51                         {NANA,0x87,0x08,0x00,0x00,NANA,0x3f,0x00,0xff,0xff,
52                          0xff,0xff,0x00,0x00,EOT}},
53                 {0x0,
54                         {0x30,0x60,0x61,0x70,0x74,0xf0,0xf1,EOT},
55                         {0x00,0x03,0xf0,0x06,0x02,0x00,0x00,EOT}},
56                 {0x1,
57                         {0x30,0x60,0x61,0x70,0xf0,EOT},
58                         {0x00,0x03,0xf8,0x04,0x00,EOT}},
59                 {0x2,
60                         {0x30,0x60,0x61,0x70,0xf0,0xf1,0xf2,0xf3,EOT},
61                         {0x00,0x02,0xf8,0x03,0x00,0x50,0x00,0x7f,EOT}},
62                 {0x3,
63                         {0x30,0x60,0x61,0x62,0x63,0x64,0x65,0x70,0x74,
64                          0xf0,EOT},
65                         {0x00,0x03,0x78,0x07,0x78,0x00,0x80,0x07,0x03,
66                          0x03,EOT}},
67                 {0x4,
68                         {0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,
69                          0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,EOT},
70                         {NANA,NANA,0x00,0x00,0x00,0x00,0x00,0x00,
71                          0x00,0x00,0x00,0x00,0x00,NANA,NANA,EOT}},
72                 {0x5,   /* Note: 0x30 can actually be 0x00 _or_ 0x01. */
73                         {0x30,0x60,0x61,0x62,0x63,0x70,0x71,0xf0,EOT},
74                         {0x01,0x00,0x60,0x00,0x64,0x01,0x02,0x00,EOT}},
75                 {0x6,
76                         {0x30,0x70,0x71,0xf0,EOT},
77                         {0x00,0x0c,0x02,0x00,EOT}},
78                 {0x7,
79                         {0x70,0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb8,0xb9,0xba,
80                          0xbb,0xbc,0xbd,0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc8,
81                          0xc9,0xca,0xcb,0xcc,0xcd,0xd0,0xd1,0xd2,0xd3,0xd4,
82                          0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xf0,0xf1,
83                          0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,
84                          0xfc,EOT},
85                         {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
86                          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
87                          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
88                          0x00,0x00,NANA,NANA,NANA,NANA,NANA,NANA,0x00,0x00,
89                          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,NANA,
90                          0x00,EOT}},
91                 {0x8,
92                         {0x30,0x60,0x61,EOT},
93                         {0x00,0x02,0x01,EOT}},
94                 {0x9,
95                         {0x30,0x60,0x61,0x70,0xf0,EOT},
96                         {0x00,0x03,0x10,0x0b,0x00,EOT}},
97                 {0xa,
98                         {0x30,0x60,0x61,0x70,0xf0,EOT},
99                         {0x00,0x03,0x00,0x0a,0x00,EOT}},
100                 {EOT}}},
101         {0x8710, "IT8710", {
102                 {EOT}}},
103         {0x8712, "IT8712", {
104                 {NOLDN,
105                         {0x07,0x20,0x21,0x22,0x23,0x24,0x2b,EOT},
106                         {NANA,0x87,0x12,0x08,0x00,0x00,0x00,EOT}},
107                 {0x0,
108                         {0x30,0x60,0x61,0x70,0x74,0xf0,0xf1,EOT},
109                         {0x00,0x03,0xf0,0x06,0x02,0x00,0x00,EOT}},
110                 {0x1,
111                         {0x30,0x60,0x61,0x70,0xf0,0xf1,0xf2,0xf3,EOT},
112                         {0x00,0x03,0xf8,0x04,0x00,0x50,0x00,0x7f,EOT}},
113                 {0x2,
114                         {0x30,0x60,0x61,0x70,0xf0,0xf1,0xf2,0xf3,EOT},
115                         {0x00,0x02,0xf8,0x03,0x00,0x50,0x00,0x7f,EOT}},
116                 {0x3,
117                         {0x30,0x60,0x61,0x62,0x63,0x70,0x74,0xf0,EOT},
118                         {0x00,0x03,0x78,0x07,0x78,0x07,0x03,0x03,EOT}},
119                 {0x4,
120                         {0x30,0x60,0x61,0x62,0x63,0x70,0xf0,0xf1,0xf2,0xf3,
121                          0xf4,0xf5,0xf6,EOT},
122                         {0x00,0x02,0x90,0x02,0x30,0x09,0x00,0x00,0x00,0x00,
123                          0x00,NANA,NANA,EOT}},
124                 {0x5,
125                         {0x30,0x60,0x61,0x62,0x63,0x70,0x71,0xf0,EOT},
126                         {0x01,0x00,0x60,0x00,0x64,0x01,0x02,0x08,EOT}},
127                 {0x6,
128                         {0x30,0x70,0x71,0xf0,EOT},
129                         {0x00,0x0c,0x02,0x00,EOT}},
130                 {0x7,
131                         {0x25,0x26,0x27,0x28,0x29,0x2a,0x2c,0x60,0x61,0x62,
132                          0x63,0x64,0x65,0x70,0x71,0x72,0x73,0x74,0xb0,0xb1,
133                          0xb2,0xb3,0xb4,0xb5,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,
134                          0xc0,0xc1,0xc2,0xc3,0xc4,0xc8,0xc9,0xca,0xcb,0xcc,
135                          0xe0,0xe1,0xe2,0xe3,0xe4,0xf0,0xf1,0xf2,0xf3,0xf4,
136                          0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,EOT},
137                         {0x01,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,
138                          0x00,0x00,0x00,0x00,0x00,0x30,0x38,0x00,0x00,0x00,
139                          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
140                          0x01,0x00,0x00,0x40,0x00,0x01,0x00,0x00,0x40,0x00,
141                          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
142                          0x00,0x00,0x00,0x00,0x00,0x00,0x00,NANA,0x00,EOT}},
143                 {0x8,
144                         {0x30,0x60,0x61,0x70,0xf0,EOT},
145                         {0x00,0x03,0x00,0x0a,0x00,EOT}},
146                 {0x9,
147                         {0x30,0x60,0x61,EOT},
148                         {0x00,0x02,0x01,EOT}},
149                 {0xa,
150                         {0x30,0x60,0x61,0x70,0xf0,EOT},
151                         {0x00,0x03,0x10,0x0b,0x00,EOT}},
152                 {EOT}}},
153         {0x8716, "IT8716", {
154                 {NOLDN,
155                         {0x07,0x20,0x21,0x22,0x23,0x24,0x2b,EOT},
156                         {NANA,0x87,0x16,0x01,0x00,0x00,0x00,EOT}},
157                 {0x0,
158                         {0x30,0x60,0x61,0x70,0x74,0xf0,0xf1,EOT},
159                         {0x00,0x03,0xf0,0x06,0x02,0x00,0x00,EOT}},
160                 {0x1,
161                         {0x30,0x60,0x61,0x70,0xf0,0xf1,0xf2,0xf3,EOT},
162                         {0x00,0x03,0xf8,0x04,0x00,0x50,0x00,0x7f,EOT}},
163                 {0x2,
164                         {0x30,0x60,0x61,0x70,0xf0,0xf1,0xf2,0xf3,EOT},
165                         {0x00,0x02,0xf8,0x03,0x00,0x50,0x00,0x7f,EOT}},
166                 {0x3,
167                         {0x30,0x60,0x61,0x62,0x63,0x70,0x74,0xf0,EOT},
168                         {0x00,0x03,0x78,0x07,0x78,0x07,0x03,0x03,EOT}},
169                 {0x4,
170                         {0x30,0x60,0x61,0x62,0x63,0x70,0xf0,0xf1,0xf2,0xf3,
171                          0xf4,0xf5,0xf6,EOT},
172                         {0x00,0x02,0x90,0x02,0x30,0x09,0x00,0x00,0x00,0x00,
173                          0x00,NANA,NANA,EOT}},
174                 {0x5,
175                         {0x30,0x60,0x61,0x62,0x63,0x70,0x71,0xf0,EOT},
176                         {0x01,0x00,0x60,0x00,0x64,0x01,0x02,0x00,EOT}},
177                 {0x6,
178                         {0x30,0x70,0x71,0xf0,EOT},
179                         {0x00,0x0c,0x02,0x00,EOT}},
180                 {0x7,
181                         {0x25,0x26,0x27,0x28,0x29,0x2a,0x2c,0x60,0x61,0x62,
182                          0x63,0x64,0x65,0x70,0x71,0x72,0x73,0x74,0xb0,0xb1,
183                          0xb2,0xb3,0xb4,0xb5,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,
184                          0xc0,0xc1,0xc2,0xc3,0xc4,0xc8,0xc9,0xca,0xcb,0xcc,
185                          0xe0,0xe1,0xe2,0xe3,0xe4,0xf0,0xf1,0xf2,0xf3,0xf4,
186                          0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,EOT},
187                         {0x01,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,
188                          0x00,0x00,0x00,0x00,0x00,0x20,0x38,0x00,0x00,0x00,
189                          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
190                          0x01,0x00,0x00,0x40,0x00,0x01,0x00,0x00,0x40,0x00,
191                          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
192                          0x00,0x00,0x00,0x00,0x00,0x00,0x00,NANA,0x00,EOT}},
193                 {0x8,
194                         {0x30,0x60,0x61,0x70,0xf0,EOT},
195                         {0x00,0x03,0x00,0x0a,0x00,EOT}},
196                 {0x9,
197                         {0x30,0x60,0x61,EOT},
198                         {0x00,0x02,0x01,EOT}},
199                 {0xa,
200                         {0x30,0x60,0x61,0x70,0xf0,EOT},
201                         {0x00,0x03,0x10,0x0b,0x00,EOT}},
202                 {EOT}}},
203         {0x8718, "IT8718", {
204                 {EOT}}},
205         {EOT}
206 };
207
208 void dump_ite(unsigned short port, unsigned short id)
209 {
210         int i, j, k;
211         signed short *idx;
212
213         printf("ITE ");
214
215         /* TODO: Get datasheets for IT8711 and IT8712. */
216         switch (id) {
217         case 0x8702:
218         case 0x8705: /* IT8700F or IT8705F */
219         case 0x8708:
220         case 0x8710:
221         case 0x8712:
222         case 0x8716:
223         /* Note: IT8726F has ID 0x8726 (datasheet wrongly says 0x8716). */
224         case 0x8718:
225                 for (i = 0;; i++) {
226                         if (ite_reg_table[i].superio_id == EOT)
227                                 break;
228                         if ((unsigned short)ite_reg_table[i].superio_id != id)
229                                 continue;
230                         printf("%s\n", ite_reg_table[i].name);
231                         for (j = 0;; j++) {
232                                 if (ite_reg_table[i].ldn[j].ldn == EOT)
233                                         break;
234                                 if (ite_reg_table[i].ldn[j].ldn != NOLDN) {
235                                         printf("Switching to LDN 0x%01x\n",
236                                                ite_reg_table[i].ldn[j].ldn);
237                                         regwrite(port, 0x07,
238                                                  ite_reg_table[i].ldn[j].ldn);
239                                 }
240                                 idx = ite_reg_table[i].ldn[j].idx;
241                                 printf("idx ");
242                                 for (k = 0;; k++) {
243                                         if (idx[k] == EOT)
244                                                 break;
245                                         printf("%02x ", idx[k]);
246                                 }
247                                 printf("\nval ");
248                                 for (k = 0;; k++) {
249                                         if (idx[k] == EOT)
250                                                 break;
251                                         printf("%02x ", regval(port, idx[k]));
252                                 }
253                                 printf("\ndef ");
254                                 idx = ite_reg_table[i].ldn[j].def;
255                                 for (k = 0;; k++) {
256                                         if (idx[k] == EOT)
257                                                 break;
258                                         if (idx[k] == NANA)
259                                                 printf("NA ");
260                                         else
261                                                 printf("%02x ", idx[k]);
262                                 }
263                                 printf("\n");
264                         }
265                 }
266                 break;
267         default:
268                 printf("Unknown ITE chip, id=%04x\n", id);
269                 for (i = 0x20; i <= 0x24; i++)
270                         printf("index %02x=%02x\n", i, regval(port, i));
271                 break;
272         }
273 }
274
275 void probe_idregs_ite(unsigned short port)
276 {
277         unsigned int id, chipver;
278
279         /* Enable configuration sequence (ITE uses this for newer IT87[012]x)
280          * IT871[01] uses 0x87, 0x87 -> fintek detection should handle it
281          * IT8708 uses 0x87, 0x87 -> fintek detection should handle it
282          * IT8761 uses 0x87, 0x61, 0x55, 0x55/0xaa
283          * IT86xx series uses different ports
284          * IT8661 uses 0x86, 0x61, 0x55/0xaa, 0x55/0xaa and 32 more writes
285          * IT8673 uses 0x86, 0x80, 0x55/0xaa, 0x55/0xaa and 32 more writes
286          */
287         outb(0x87, port);
288         outb(0x01, port);
289         outb(0x55, port);
290         if (port == 0x2e)
291                 outb(0x55, port);
292         else
293                 outb(0xAA, port);
294
295         /* Read Chip ID Byte 1. */
296         id = regval(port, 0x20);
297         if (id != 0x87) {
298                 if (inb(port) == 0xff)
299                         printf("No Super I/O chip found at 0x%04x\n", port);
300                 else
301                         printf("Probing 0x%04x, failed (0x%02x), data returns 0x%02x\n", port, inb(port), inb(port + 1));
302                 return;
303         }
304
305         id <<= 8;
306
307         /* Read Chip ID Byte 2. */
308         id |= regval(port, 0x21);
309
310         /* Read chip version, only bits 3..0 for all IT87xx. */
311         chipver = regval(port, 0x22) & 0x0f;
312
313         printf("Super I/O found at 0x%02x: id=0x%04x, chipver=0x%01x\n",
314                port, id, chipver);
315
316         switch (id) {
317         case 0x8702:
318         case 0x8705:
319         case 0x8708:
320         case 0x8712:
321         case 0x8716:
322         case 0x8718:
323         case 0x8726:
324                 dump_ite(port, id);
325                 break;
326         default:
327                 printf("No dump for ID 0x%04x\n", id);
328                 break;
329         }
330         regwrite(port, 0x02, 0x02);     /* Exit MB PnP mode. */
331 }
332