Add -D / --dump-readable option which prints the Super I/O register
[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 static void dump_readable_ns8374(uint16_t port)
29 {
30         if (!dump_readable)
31                 return;
32
33         printf("Enables: 21=%02x, 22=%02x, 23=%02x, 24=%02x, 26=%02x\n",
34                regval(port, 0x21), regval(port, 0x22), regval(port, 0x23),
35                regval(port, 0x24), regval(port, 0x26));
36         printf("SMBUS at %02x\n", regval(port, 0x2a));
37
38         /* Check COM1. This is all we care about at present. */
39         printf("COM 1 is globally %s\n",
40                regval(port, 0x26) & 8 ? "disabled" : "enabled");
41
42         /* Select COM1. */
43         regwrite(port, 0x07, 0x03);
44         printf("COM 1 is locally %s\n",
45                regval(port, 0x30) & 1 ? "enabled" : "disabled");
46         printf
47             ("COM1 60=%02x, 61=%02x, 70=%02x, 71=%02x, 74=%02x, 75=%02x, f0=%02x\n",
48              regval(port, 0x60), regval(port, 0x61), regval(port, 0x70),
49              regval(port, 0x71), regval(port, 0x74), regval(port, 0x75),
50              regval(port, 0xf0));
51
52         /* Select GPIO. */
53         regwrite(port, 0x07, 0x07);
54         printf("GPIO is %s\n", regval(port, 0x30) & 1 ? "enabled" : "disabled");
55         printf
56             ("GPIO 60=%02x, 61=%02x, 70=%02x, 71=%02x, 74=%02x, 75=%02x, f0=%02x\n",
57              regval(port, 0x60), regval(port, 0x61), regval(port, 0x70),
58              regval(port, 0x71), regval(port, 0x74), regval(port, 0x75),
59              regval(port, 0xf0));
60 }
61
62 void probe_idregs_simple(uint16_t port)
63 {
64         uint16_t id;
65
66         outb(0x20, port);
67         if (inb(port) != 0x20) {
68                 no_superio_found(port);
69                 /* TODO: Exit config mode? */
70                 return;
71         }
72         id = inb(port + 1);
73
74         printf("Super I/O found at 0x%02x: id = 0x%02x\n", port, id);
75         if (id == 0xff)
76                 return;
77
78         if (familyid[id])
79                 printf("%s\n", familyid[id]);
80         else
81                 printf("<unknown>\n");
82
83         switch (id) {
84         case 0xf1:
85                 dump_readable_ns8374(port);
86                 break;
87         default:
88                 printf("No dump for 0x%02x\n", id);
89                 break;
90         }
91 }
92