691ce13967ea1af4e7a6dc9e234a11d13fd1b45b
[coreboot.git] / util / superiotool / nsc.c
1 /*
2  * This file is part of the LinuxBIOS project.
3  *
4  * Copyright (C) 2006 Ronald Minnich <rminnich@gmail.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19  */
20
21 #include "superiotool.h"
22
23 /* Well, they really thought this through, eh? Family is 8 bits! */
24 static const char *familyid[] = {
25         [0xf1] = "PC8374 (Winbond/NatSemi)"
26 };
27
28 void dump_ns8374(uint16_t port)
29 {
30         printf("Enables: 21=%02x, 22=%02x, 23=%02x, 24=%02x, 26=%02x\n",
31                regval(port, 0x21), regval(port, 0x22), regval(port, 0x23),
32                regval(port, 0x24), regval(port, 0x26));
33         printf("SMBUS at %02x\n", regval(port, 0x2a));
34
35         /* Check COM1. This is all we care about at present. */
36         printf("COM 1 is globally %s\n",
37                regval(port, 0x26) & 8 ? "disabled" : "enabled");
38
39         /* Select COM1. */
40         regwrite(port, 0x07, 0x03);
41         printf("COM 1 is locally %s\n",
42                regval(port, 0x30) & 1 ? "enabled" : "disabled");
43         printf
44             ("COM1 60=%02x, 61=%02x, 70=%02x, 71=%02x, 74=%02x, 75=%02x, f0=%02x\n",
45              regval(port, 0x60), regval(port, 0x61), regval(port, 0x70),
46              regval(port, 0x71), regval(port, 0x74), regval(port, 0x75),
47              regval(port, 0xf0));
48
49         /* Select GPIO. */
50         regwrite(port, 0x07, 0x07);
51         printf("GPIO is %s\n", regval(port, 0x30) & 1 ? "enabled" : "disabled");
52         printf
53             ("GPIO 60=%02x, 61=%02x, 70=%02x, 71=%02x, 74=%02x, 75=%02x, f0=%02x\n",
54              regval(port, 0x60), regval(port, 0x61), regval(port, 0x70),
55              regval(port, 0x71), regval(port, 0x74), regval(port, 0x75),
56              regval(port, 0xf0));
57 }
58
59 void probe_idregs_simple(uint16_t port)
60 {
61         uint16_t id;
62
63         outb(0x20, port);
64         if (inb(port) != 0x20) {
65                 if (inb(port) == 0xff)
66                         printf("No Super I/O chip found at 0x%04x\n", port);
67                 else
68                         printf("Probing 0x%04x, failed (0x%02x), data returns 0x%02x\n", port, inb(port), inb(port + 1));
69                 return;
70         }
71         id = inb(port + 1);
72
73         printf("Super I/O found at 0x%02x: id = 0x%02x\n", port, id);
74         if (id == 0xff)
75                 return;
76
77         if (familyid[id])
78                 printf("%s\n", familyid[id]);
79         else
80                 printf("<unknown>\n");
81
82         switch (id) {
83         case 0xf1:
84                 dump_ns8374(port);
85                 break;
86         default:
87                 printf("No dump for 0x%02x\n", id);
88                 break;
89         }
90 }
91