blob: ad3cd45c34eef1aa74d45e2d82049464ecfc103a [file] [log] [blame]
Stefan Reinauer6a5bc462007-01-17 10:57:42 +00001/*
2 * This file is part of the LinuxBIOS project.
3 *
4 * Copyright (C) 2006 Ronald Minnich <rminnich@gmail.com>
Uwe Hermannbd263922007-09-01 19:42:42 +00005 * Copyright (C) 2007 Uwe Hermann <uwe@hermann-uwe.de>
Uwe Hermann519419b2007-09-16 20:59:01 +00006 * Copyright (C) 2007 Carl-Daniel Hailfinger
Stefan Reinauer6a5bc462007-01-17 10:57:42 +00007 *
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.
12 *
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.
17 *
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
21 */
22
Uwe Hermann0120e1a2007-09-16 18:11:03 +000023#include "superiotool.h"
Ronald G. Minnich394e7c42006-02-22 22:12:21 +000024
Uwe Hermann2046ff92007-09-01 21:02:44 +000025unsigned char regval(unsigned short port, unsigned char reg)
26{
Ronald G. Minnich394e7c42006-02-22 22:12:21 +000027 outb(reg, port);
Carl-Daniel Hailfingerb1786c22007-08-28 10:43:57 +000028 return inb(port + 1);
Ronald G. Minnich394e7c42006-02-22 22:12:21 +000029}
30
Uwe Hermann2046ff92007-09-01 21:02:44 +000031void regwrite(unsigned short port, unsigned char reg, unsigned char val)
32{
Carl-Daniel Hailfinger7a7890a2007-08-27 07:28:28 +000033 outb(reg, port);
Carl-Daniel Hailfingerb1786c22007-08-28 10:43:57 +000034 outb(val, port + 1);
Carl-Daniel Hailfinger7a7890a2007-08-27 07:28:28 +000035}
36
Uwe Hermann519419b2007-09-16 20:59:01 +000037void dump_superio(const char *name, const struct superio_registers reg_table[],
38 unsigned short port, unsigned short id)
39{
40 int i, j, k;
41 signed short *idx;
42
43 printf("%s ", name);
44
45 for (i = 0; /* Nothing */; i++) {
46 if (reg_table[i].superio_id == EOT)
47 break;
48
49 if ((unsigned short)reg_table[i].superio_id != id)
50 continue;
51
52 printf("%s\n", reg_table[i].name);
53
54 for (j = 0;; j++) {
55 if (reg_table[i].ldn[j].ldn == EOT)
56 break;
57
58 if (reg_table[i].ldn[j].ldn != NOLDN) {
59 printf("Switching to LDN 0x%01x\n",
60 reg_table[i].ldn[j].ldn);
61 regwrite(port, 0x07,
62 reg_table[i].ldn[j].ldn);
63 }
64
65 idx = reg_table[i].ldn[j].idx;
66
67 printf("idx ");
68 for (k = 0;; k++) {
69 if (idx[k] == EOT)
70 break;
71 printf("%02x ", idx[k]);
72 }
73
74 printf("\nval ");
75 for (k = 0;; k++) {
76 if (idx[k] == EOT)
77 break;
78 printf("%02x ", regval(port, idx[k]));
79 }
80
81 printf("\ndef ");
82 idx = reg_table[i].ldn[j].def;
83 for (k = 0;; k++) {
84 if (idx[k] == EOT)
85 break;
86 if (idx[k] == NANA)
87 printf("NA ");
88 else
89 printf("%02x ", idx[k]);
90 }
91 printf("\n");
92 }
93 }
94}
95
Uwe Hermann2046ff92007-09-01 21:02:44 +000096void probe_superio(unsigned short port)
97{
Stefan Reinauer6a5bc462007-01-17 10:57:42 +000098 probe_idregs_simple(port);
99 probe_idregs_fintek(port);
Carl-Daniel Hailfinger7a7890a2007-08-27 07:28:28 +0000100 probe_idregs_ite(port);
Ronald G. Minnich394e7c42006-02-22 22:12:21 +0000101}
102
Uwe Hermann2046ff92007-09-01 21:02:44 +0000103int main(int argc, char *argv[])
Stefan Reinauer6a5bc462007-01-17 10:57:42 +0000104{
Ronald G. Minnich394e7c42006-02-22 22:12:21 +0000105 if (iopl(3) < 0) {
106 perror("iopl");
107 exit(1);
108 }
109
Uwe Hermann2046ff92007-09-01 21:02:44 +0000110 probe_superio(0x2e); /* Try 0x2e. */
111 probe_superio(0x4e); /* Try 0x4e. */
Stefan Reinauer6a5bc462007-01-17 10:57:42 +0000112
113 return 0;
Ronald G. Minnich394e7c42006-02-22 22:12:21 +0000114}