2 * This file is part of the superiotool project.
4 * Copyright (C) 2006 Ronald Minnich <rminnich@gmail.com>
5 * Copyright (C) 2007 Uwe Hermann <uwe@hermann-uwe.de>
6 * Copyright (C) 2007 Carl-Daniel Hailfinger
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "superiotool.h"
25 /* Command line options. */
26 int dump = 0, verbose = 0;
28 /* Global flag which indicates whether a chip was detected at all. */
31 uint8_t regval(uint16_t port, uint8_t reg)
37 void regwrite(uint16_t port, uint8_t reg, uint8_t val)
43 void enter_conf_mode_winbond_fintek_ite_8787(uint16_t port)
49 void exit_conf_mode_winbond_fintek_ite_8787(uint16_t port)
51 outb(0xaa, port); /* Fintek, Winbond */
52 regwrite(port, 0x02, 0x02); /* ITE */
55 int superio_unknown(const struct superio_registers reg_table[], uint16_t id)
57 return !strncmp(get_superio_name(reg_table, id), "<unknown>", 9);
60 const char *get_superio_name(const struct superio_registers reg_table[],
65 for (i = 0; /* Nothing */; i++) {
66 if (reg_table[i].superio_id == EOT)
69 if ((uint16_t)reg_table[i].superio_id != id)
72 return reg_table[i].name;
78 static void dump_regs(const struct superio_registers reg_table[],
79 int i, int j, uint16_t port)
84 if (reg_table[i].ldn[j].ldn != NOLDN) {
85 printf("LDN 0x%02x ", reg_table[i].ldn[j].ldn);
86 if (reg_table[i].ldn[j].name != NULL)
87 printf("(%s)", reg_table[i].ldn[j].name);
88 regwrite(port, 0x07, reg_table[i].ldn[j].ldn);
90 printf("Register dump:");
93 idx = reg_table[i].ldn[j].idx;
96 for (k = 0; /* Nothing */; k++) {
99 printf("%02x ", idx[k]);
103 for (k = 0; /* Nothing */; k++) {
106 printf("%02x ", regval(port, idx[k]));
110 idx = reg_table[i].ldn[j].def;
111 for (k = 0; /* Nothing */; k++) {
114 else if (idx[k] == NANA)
116 else if (idx[k] == RSVD)
118 else if (idx[k] == MISC) /* TODO */
121 printf("%02x ", idx[k]);
126 void dump_superio(const char *vendor,
127 const struct superio_registers reg_table[],
128 uint16_t port, uint16_t id)
130 int i, j, no_dump_available = 1;
135 for (i = 0; /* Nothing */; i++) {
136 if (reg_table[i].superio_id == EOT)
139 if ((uint16_t)reg_table[i].superio_id != id)
142 for (j = 0; /* Nothing */; j++) {
143 if (reg_table[i].ldn[j].ldn == EOT)
145 no_dump_available = 0;
146 dump_regs(reg_table, i, j, port);
149 if (no_dump_available)
150 printf("No dump available for this Super I/O\n");
154 void probing_for(const char *vendor, const char *info, uint16_t port)
159 /* Yes, there's no space between '%s' and 'at'! */
160 printf("Probing for %s Super I/O %sat 0x%x...\n",
164 static void print_version(void)
166 printf("superiotool r%s\n", SUPERIOTOOL_VERSION);
169 int main(int argc, char *argv[])
171 int i, j, opt, option_index;
173 const static struct option long_options[] = {
174 {"dump", no_argument, NULL, 'd'},
175 {"verbose", no_argument, NULL, 'V'},
176 {"version", no_argument, NULL, 'v'},
177 {"help", no_argument, NULL, 'h'},
181 while ((opt = getopt_long(argc, argv, "dVvh",
182 long_options, &option_index)) != EOF) {
199 /* Unknown option. */
207 printf("Superiotool must be run as root.\n");
213 for (i = 0; i < ARRAY_SIZE(superio_ports_table); i++) {
214 for (j = 0; superio_ports_table[i].ports[j] != EOT; j++)
215 superio_ports_table[i].probe_idregs(
216 superio_ports_table[i].ports[j]);
220 printf("No Super I/O found\n");