1c035234b2a0ebe75ae950ec15d697697f2f9fc4
[coreboot.git] / util / superiotool / amd.c
1 /*
2  * This file is part of the superiotool project.
3  *
4  * Copyright (C) 2011 Rudolf Marek <r.marek@assembler.cz>
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 #define DEVICE_ID_REG           0x20
24 #define DEVICE_REV_REG          0x21
25
26 static const struct superio_registers reg_table[] = {
27         {0xb7, "SB7xx", {
28                 {NOLDN, NULL,
29                         {0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x28,0x29,0x2a,
30                          0x2b,0x2c,0x2e, 0x2f, EOT},
31                          {NANA,NANA,NANA,NANA,NANA,NANA,NANA,NANA,NANA,NANA,NANA,NANA,NANA,NANA,EOT}},
32                 {0x3, "EC channel 0",
33                         {0x30,0x60,0x61, EOT},
34                          {NANA,NANA,NANA,EOT}},
35                 {0x5, "Irda",
36                         {0x30,0x60,0x61,0x70, EOT},
37                          {NANA,NANA,NANA,NANA,EOT}},
38                 {0x7, "Keyboard Controller",
39                         {0x30, EOT},
40                          {NANA,EOT}},
41                 {0x9, "Mailbox",
42                         {0x30,0x60,0x61, EOT},
43                         {NANA,NANA,NANA,EOT}},
44                 {EOT}}},
45         {0xb8, "SB8xx", {
46                 {NOLDN, NULL,
47                         {0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x28,0x29,0x2a,
48                          0x2b,0x2c,0x2e, 0x2f, EOT},
49                          {NANA,NANA,NANA,NANA,NANA,NANA,NANA,NANA,NANA,NANA,NANA,NANA,NANA,NANA,EOT}},
50                 {0x3, "EC channel 0",
51                         {0x30,0x60,0x61, EOT},
52                          {NANA,NANA,NANA,EOT}},
53                 {0x5, "Irda",
54                         {0x30,0x60,0x61,0x70, EOT},
55                          {NANA,NANA,NANA,NANA,EOT}},
56                 {0x7, "Keyboard Controller",
57                         {0x30, EOT},
58                          {NANA,EOT}},
59                 {0x9, "Mailbox",
60                         {0x30,0x60,0x61, EOT},
61                         {NANA,NANA,NANA,EOT}},
62                 {EOT}}},
63         {EOT}
64 };
65
66 /* same as serverengines */
67 static void enter_conf_mode_ec(uint16_t port)
68 {
69         OUTB(0x5a, port);
70 }
71
72 static void exit_conf_mode_ec(uint16_t port)
73 {
74         OUTB(0xa5, port);
75 }
76
77 uint16_t detect_ec(void)
78 {
79         uint16_t ec_port;
80         struct pci_dev *dev;
81
82         dev = pci_dev_find(0x1002, 0x439d);
83
84         if (!dev) {
85                 return 0;
86         }
87
88         /* is EC disabled ? */
89         if (!(pci_read_byte(dev, 0x40) & (1 << 7)))
90                 return 0;
91
92         ec_port = pci_read_word(dev, 0xa4);
93         
94         if (!(ec_port & 0x1))
95                 return 0;
96
97         ec_port &= ~0x1;
98
99         return ec_port;
100 }
101
102 void probe_idregs_amd(uint16_t port)
103 {
104         uint8_t rev, devid;
105
106         probing_for("AMD EC", "", port);
107
108         if (!(port = detect_ec()))
109                 return;
110
111         enter_conf_mode_ec(port);
112
113         devid = regval(port, DEVICE_ID_REG);
114         rev = regval(port, DEVICE_REV_REG);
115
116         if (superio_unknown(reg_table, devid)) {
117                 if (verbose)
118                         printf(NOTFOUND "id=0x%02x, rev=0x%02x\n", devid, rev);
119                 exit_conf_mode_ec(port);
120                 return;
121         }
122
123         printf("Found AMD EC %s (id=0x%02x, rev=0x%02x) at 0x%x\n",
124                get_superio_name(reg_table, devid), devid, rev, port);
125         chip_found = 1;
126
127         dump_superio("AMD EC", reg_table, port, devid, LDN_SEL);
128
129         exit_conf_mode_ec(port);
130 }
131
132 void print_amd_chips(void)
133 {
134         print_vendor_chips("AMD EC", reg_table);
135 }