* Convert the NSC code to the common code structure all other Super I/Os use.
[coreboot.git] / util / superiotool / nsc.c
1 /*
2  * This file is part of the superiotool project.
3  *
4  * Copyright (C) 2006 Ronald Minnich <rminnich@gmail.com>
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 CHIP_ID_REG     0x20    /* Super I/O ID (SID) / family */
25 #define CHIP_REV_REG    0x27    /* Super I/O revision ID (SRID) */
26
27 /* SID[7..0]: chip family. SRID[7..5]: chip ID, SRID[4..0]: chip rev. */
28 const static struct superio_registers reg_table[] = {
29         {0xf1, "PC8374L", {
30                 {EOT}}},
31         {EOT}
32 };
33
34 static void dump_readable_pc8374l(uint16_t port)
35 {
36         if (!dump_readable)
37                 return;
38
39         printf("Human-readable register dump:\n");
40
41         printf("Enables: 21=%02x, 22=%02x, 23=%02x, 24=%02x, 26=%02x\n",
42                regval(port, 0x21), regval(port, 0x22), regval(port, 0x23),
43                regval(port, 0x24), regval(port, 0x26));
44         printf("SMBUS at %02x\n", regval(port, 0x2a));
45
46         /* Check COM1. This is all we care about at present. */
47         printf("COM 1 is globally %s\n",
48                regval(port, 0x26) & 8 ? "disabled" : "enabled");
49
50         /* Select COM1. */
51         regwrite(port, 0x07, 0x03);
52         printf("COM 1 is locally %s\n",
53                regval(port, 0x30) & 1 ? "enabled" : "disabled");
54         printf
55             ("COM1 60=%02x, 61=%02x, 70=%02x, 71=%02x, 74=%02x, 75=%02x, f0=%02x\n",
56              regval(port, 0x60), regval(port, 0x61), regval(port, 0x70),
57              regval(port, 0x71), regval(port, 0x74), regval(port, 0x75),
58              regval(port, 0xf0));
59
60         /* Select GPIO. */
61         regwrite(port, 0x07, 0x07);
62         printf("GPIO is %s\n", regval(port, 0x30) & 1 ? "enabled" : "disabled");
63         printf
64             ("GPIO 60=%02x, 61=%02x, 70=%02x, 71=%02x, 74=%02x, 75=%02x, f0=%02x\n",
65              regval(port, 0x60), regval(port, 0x61), regval(port, 0x70),
66              regval(port, 0x71), regval(port, 0x74), regval(port, 0x75),
67              regval(port, 0xf0));
68 }
69
70 void probe_idregs_nsc(uint16_t port)
71 {
72         uint8_t id, rev;
73
74         probing_for("NSC", "", port);
75
76         outb(CHIP_ID_REG, port);
77         if (inb(port) != CHIP_ID_REG) {
78                 if (verbose)
79                         printf(NOTFOUND "port=0x%02x, port+1=0x%02x\n",
80                                inb(port), inb(port + 1));
81                 return;
82         }
83         id = inb(port + 1);
84
85         outb(CHIP_REV_REG, port);
86         if (inb(port) != CHIP_REV_REG) {
87                 printf("Warning: Can't get chip revision. Setting to 0xff.\n");
88                 rev = 0xff;
89         } else {
90                 rev = inb(port + 1);
91         }
92
93         if (superio_unknown(reg_table, id)) {
94                 if (verbose)
95                         printf(NOTFOUND "sid=0x%02x, srid=0x%02x\n", id, rev);
96                 return;
97         }
98
99         printf("Found NSC %s (sid=0x%02x, srid=0x%02x) at 0x%x\n",
100                get_superio_name(reg_table, id), id, rev, port);
101
102         dump_superio("NSC", reg_table, port, id);
103         if (id == 0xf1)
104                 dump_readable_pc8374l(port);
105 }
106