6b56ec43a18f89b128c5f0dfa5f8beba45aae056
[coreboot.git] / util / inteltool / gpio.c
1 /*
2  * inteltool - dump all registers on an Intel CPU + chipset based system.
3  *
4  * Copyright (C) 2008 by coresystems GmbH
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; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19
20 #include <stdio.h>
21 #include "inteltool.h"
22
23 static const io_register_t ich0_gpio_registers[] = {
24         { 0x00, 4, "GPIO_USE_SEL" },
25         { 0x04, 4, "GP_IO_SEL" },
26         { 0x08, 4, "RESERVED" },
27         { 0x0c, 4, "GP_LVL" },
28         { 0x10, 4, "RESERVED" },
29         { 0x14, 4, "GPO_TTL" },
30         { 0x18, 4, "GPO_BLINK" },
31         { 0x1c, 4, "RESERVED" },
32         { 0x20, 4, "RESERVED" },
33         { 0x24, 4, "RESERVED" },
34         { 0x28, 4, "RESERVED" },
35         { 0x2c, 4, "GPI_INV" },
36         { 0x30, 4, "RESERVED" },
37         { 0x34, 4, "RESERVED" },
38         { 0x38, 4, "RESERVED" },
39         { 0x3C, 4, "RESERVED" }
40 };
41
42 static const io_register_t ich2_gpio_registers[] = {
43         { 0x00, 4, "GPIO_USE_SEL" },
44         { 0x04, 4, "GP_IO_SEL" },
45         { 0x08, 4, "RESERVED" },
46         { 0x0c, 4, "GP_LVL" },
47         { 0x10, 4, "RESERVED" },
48         { 0x14, 4, "GPO_TTL" },
49         { 0x18, 4, "GPO_BLINK" },
50         { 0x1c, 4, "RESERVED" },
51         { 0x20, 4, "RESERVED" },
52         { 0x24, 4, "RESERVED" },
53         { 0x28, 4, "RESERVED" },
54         { 0x2c, 4, "GPI_INV" },
55         { 0x30, 4, "RESERVED" },
56         { 0x34, 4, "RESERVED" },
57         { 0x38, 4, "RESERVED" },
58         { 0x3C, 4, "RESERVED" }
59 };
60
61 static const io_register_t ich4_gpio_registers[] = {
62         { 0x00, 4, "GPIO_USE_SEL" },
63         { 0x04, 4, "GP_IO_SEL" },
64         { 0x08, 4, "RESERVED" },
65         { 0x0c, 4, "GP_LVL" },
66         { 0x10, 4, "RESERVED" },
67         { 0x14, 4, "GPO_TTL" },
68         { 0x18, 4, "GPO_BLINK" },
69         { 0x1c, 4, "RESERVED" },
70         { 0x20, 4, "RESERVED" },
71         { 0x24, 4, "RESERVED" },
72         { 0x28, 4, "RESERVED" },
73         { 0x2c, 4, "GPI_INV" },
74         { 0x30, 4, "GPIO_USE_SEL2" },
75         { 0x34, 4, "GP_IO_SEL2" },
76         { 0x38, 4, "GP_LVL2" },
77         { 0x3C, 4, "RESERVED" }
78 };
79
80 static const io_register_t ich5_gpio_registers[] = {
81         { 0x00, 4, "GPIO_USE_SEL" },
82         { 0x04, 4, "GP_IO_SEL" },
83         { 0x08, 4, "RESERVED" },
84         { 0x0c, 4, "GP_LVL" },
85         { 0x10, 4, "RESERVED" },
86         { 0x14, 4, "GPO_TTL"},
87         { 0x18, 4, "GPO_BLINK"},
88         { 0x1c, 4, "RESERVED" },
89         { 0x20, 4, "RESERVED" },
90         { 0x2c, 4, "GPI_INV" },
91         { 0x30, 4, "GPIO_USE_SEL2" },
92         { 0x34, 4, "GP_IO_SEL2" },
93         { 0x38, 4, "GP_LVL2" },
94 };
95
96 static const io_register_t ich6_gpio_registers[] = {
97         { 0x00, 4, "GPIO_USE_SEL" },
98         { 0x08, 4, "RESERVED" },
99         { 0x0c, 4, "GP_LVL" },
100         { 0x10, 4, "RESERVED" },
101         { 0x14, 4, "RESERVED" },
102         { 0x18, 4, "GPO_BLINK" },
103         { 0x1c, 4, "RESERVED" },
104         { 0x20, 4, "RESERVED" },
105         { 0x24, 4, "RESERVED" },
106         { 0x28, 4, "RESERVED" },
107         { 0x2c, 4, "GPI_INV" },
108         { 0x30, 4, "GPIO_USE_SEL2" },
109         { 0x34, 4, "GP_IO_SEL2" },
110         { 0x38, 4, "GP_LVL2" },
111         { 0x04, 4, "GP_IO_SEL" },
112 };
113
114 static const io_register_t ich7_gpio_registers[] = {
115         { 0x00, 4, "GPIO_USE_SEL" },
116         { 0x04, 4, "GP_IO_SEL" },
117         { 0x08, 4, "RESERVED" },
118         { 0x0c, 4, "GP_LVL" },
119         { 0x10, 4, "RESERVED" },
120         { 0x14, 4, "RESERVED" },
121         { 0x18, 4, "GPO_BLINK" },
122         { 0x1c, 4, "RESERVED" },
123         { 0x20, 4, "RESERVED" },
124         { 0x24, 4, "RESERVED" },
125         { 0x28, 4, "RESERVED" },
126         { 0x2c, 4, "GPI_INV" },
127         { 0x30, 4, "GPIO_USE_SEL2" },
128         { 0x34, 4, "GP_IO_SEL2" },
129         { 0x38, 4, "GP_LVL2" },
130         { 0x3C, 4, "RESERVED" }
131 };
132
133 static const io_register_t ich8_gpio_registers[] = {
134         { 0x00, 4, "GPIO_USE_SEL" },
135         { 0x04, 4, "GP_IO_SEL" },
136         { 0x08, 4, "RESERVED" },
137         { 0x0c, 4, "GP_LVL" },
138         { 0x10, 4, "GPIO_USE_SEL Override (LOW)" },
139         { 0x14, 4, "RESERVED" },
140         { 0x18, 4, "GPO_BLINK" },
141         { 0x1c, 4, "GP_SER_BLINK" },
142         { 0x20, 4, "GP_SB_CMDSTS" },
143         { 0x24, 4, "GP_SB_DATA" },
144         { 0x28, 4, "RESERVED" },
145         { 0x2c, 4, "GPI_INV" },
146         { 0x30, 4, "GPIO_USE_SEL2" },
147         { 0x34, 4, "GP_IO_SEL2" },
148         { 0x38, 4, "GP_LVL2" },
149         { 0x3C, 4, "GPIO_USE_SEL Override (HIGH)" }
150 };
151
152 static const io_register_t ich9_gpio_registers[] = {
153         { 0x00, 4, "GPIO_USE_SEL" },
154         { 0x04, 4, "GP_IO_SEL" },
155         { 0x08, 4, "RESERVED" },
156         { 0x0c, 4, "GP_LVL" },
157         { 0x10, 4, "RESERVED" },
158         { 0x14, 4, "RESERVED" },
159         { 0x18, 4, "GPO_BLINK" },
160         { 0x1c, 4, "GP_SER_BLINK" },
161         { 0x20, 4, "GP_SB_CMDSTS" },
162         { 0x24, 4, "GP_SB_DATA" },
163         { 0x28, 4, "RESERVED" },
164         { 0x2c, 4, "GPI_INV" },
165         { 0x30, 4, "GPIO_USE_SEL2" },
166         { 0x34, 4, "GP_IO_SEL2" },
167         { 0x38, 4, "GP_LVL2" },
168         { 0x3C, 4, "RESERVED" }
169 };
170
171 static const io_register_t ich10_gpio_registers[] = {
172         { 0x00, 4, "GPIO_USE_SEL" },
173         { 0x04, 4, "GP_IO_SEL" },
174         { 0x08, 4, "RESERVED" },
175         { 0x0c, 4, "GP_LVL" },
176         { 0x10, 4, "RESERVED" },
177         { 0x14, 4, "RESERVED" },
178         { 0x18, 4, "GPO_BLINK" },
179         { 0x1c, 4, "GP_SER_BLINK" },
180         { 0x20, 4, "GP_SB_CMDSTS" },
181         { 0x24, 4, "GP_SB_DATA" },
182         { 0x28, 4, "RESERVED" },
183         { 0x2c, 4, "GPI_INV" },
184         { 0x30, 4, "GPIO_USE_SEL2" },
185         { 0x34, 4, "GP_IO_SEL2" },
186         { 0x38, 4, "GP_LVL2" },
187         { 0x3C, 4, "RESERVED" },
188         { 0x40, 4, "GPIO_USE_SEL3" },
189         { 0x44, 4, "GPIO_SEL3" },
190         { 0x48, 4, "GPIO_LVL3" },
191         { 0x4c, 4, "RESERVED" },
192         { 0x50, 4, "RESERVED" },
193         { 0x54, 4, "RESERVED" },
194         { 0x58, 4, "RESERVED" },
195         { 0x5c, 4, "RESERVED" },
196         { 0x60, 4, "GP_RST_SEL" },
197         { 0x64, 4, "RESERVED" },
198         { 0x68, 4, "RESERVED" },
199         { 0x6c, 4, "RESERVED" },
200         { 0x70, 4, "RESERVED" },
201         { 0x74, 4, "RESERVED" },
202         { 0x78, 4, "RESERVED" },
203         { 0x7c, 4, "RESERVED" },
204 };
205
206 int print_gpios(struct pci_dev *sb)
207 {
208         int i, size;
209         uint16_t gpiobase;
210         const io_register_t *gpio_registers;
211
212         printf("\n============= GPIOS =============\n\n");
213
214         switch (sb->device_id) {
215         case PCI_DEVICE_ID_INTEL_ICH10R:
216                 gpiobase = pci_read_word(sb, 0x48) & 0xfffc;
217                 gpio_registers = ich10_gpio_registers;
218                 size = ARRAY_SIZE(ich10_gpio_registers);
219                 break;
220         case PCI_DEVICE_ID_INTEL_ICH9DH:
221         case PCI_DEVICE_ID_INTEL_ICH9DO:
222         case PCI_DEVICE_ID_INTEL_ICH9R:
223         case PCI_DEVICE_ID_INTEL_ICH9:
224         case PCI_DEVICE_ID_INTEL_ICH9M:
225         case PCI_DEVICE_ID_INTEL_ICH9ME:
226                 gpiobase = pci_read_word(sb, 0x48) & 0xfffc;
227                 gpio_registers = ich9_gpio_registers;
228                 size = ARRAY_SIZE(ich9_gpio_registers);
229                 break;
230         case PCI_DEVICE_ID_INTEL_ICH8:
231         case PCI_DEVICE_ID_INTEL_ICH8M:
232                 gpiobase = pci_read_word(sb, 0x48) & 0xfffc;
233                 gpio_registers = ich8_gpio_registers;
234                 size = ARRAY_SIZE(ich8_gpio_registers);
235                 break;
236         case PCI_DEVICE_ID_INTEL_ICH7:
237         case PCI_DEVICE_ID_INTEL_ICH7M:
238         case PCI_DEVICE_ID_INTEL_ICH7DH:
239         case PCI_DEVICE_ID_INTEL_ICH7MDH:
240         case PCI_DEVICE_ID_INTEL_NM10:
241                 gpiobase = pci_read_word(sb, 0x48) & 0xfffc;
242                 gpio_registers = ich7_gpio_registers;
243                 size = ARRAY_SIZE(ich7_gpio_registers);
244                 break;
245         case PCI_DEVICE_ID_INTEL_ICH6:
246                 gpiobase = pci_read_word(sb, 0x48) & 0xfffc;
247                 gpio_registers = ich6_gpio_registers;
248                 size = ARRAY_SIZE(ich6_gpio_registers);
249                 break;
250         case PCI_DEVICE_ID_INTEL_ICH5:
251                 gpiobase = pci_read_word(sb, 0x58) & 0xfffc;
252                 gpio_registers = ich5_gpio_registers;
253                 size = ARRAY_SIZE(ich5_gpio_registers);
254                 break;
255         case PCI_DEVICE_ID_INTEL_ICH4:
256         case PCI_DEVICE_ID_INTEL_ICH4M:
257                 gpiobase = pci_read_word(sb, 0x58) & 0xfffc;
258                 gpio_registers = ich4_gpio_registers;
259                 size = ARRAY_SIZE(ich4_gpio_registers);
260                 break;
261         case PCI_DEVICE_ID_INTEL_ICH2:
262                 gpiobase = pci_read_word(sb, 0x58) & 0xfffc;
263                 gpio_registers = ich2_gpio_registers;
264                 size = ARRAY_SIZE(ich2_gpio_registers);
265                 break;
266         case PCI_DEVICE_ID_INTEL_ICH:
267         case PCI_DEVICE_ID_INTEL_ICH0:
268                 gpiobase = pci_read_word(sb, 0x58) & 0xfffc;
269                 gpio_registers = ich0_gpio_registers;
270                 size = ARRAY_SIZE(ich0_gpio_registers);
271                 break;
272         case PCI_DEVICE_ID_INTEL_82371XX:
273                 printf("This southbridge has GPIOs in the PM unit.\n");
274                 return 1;
275         case 0x1234: // Dummy for non-existent functionality
276                 printf("This southbridge does not have GPIOBASE.\n");
277                 return 1;
278         default:
279                 printf("Error: Dumping GPIOs on this southbridge is not (yet) supported.\n");
280                 return 1;
281         }
282
283         printf("GPIOBASE = 0x%04x (IO)\n\n", gpiobase);
284
285         for (i = 0; i < size; i++) {
286                 switch (gpio_registers[i].size) {
287                 case 4:
288                         printf("gpiobase+0x%04x: 0x%08x (%s)\n",
289                                 gpio_registers[i].addr,
290                                 inl(gpiobase+gpio_registers[i].addr),
291                                 gpio_registers[i].name);
292                         break;
293                 case 2:
294                         printf("gpiobase+0x%04x: 0x%04x     (%s)\n",
295                                 gpio_registers[i].addr,
296                                 inw(gpiobase+gpio_registers[i].addr),
297                                 gpio_registers[i].name);
298                         break;
299                 case 1:
300                         printf("gpiobase+0x%04x: 0x%02x       (%s)\n",
301                                 gpio_registers[i].addr,
302                                 inb(gpiobase+gpio_registers[i].addr),
303                                 gpio_registers[i].name);
304                         break;
305                 }
306         }
307
308         return 0;
309 }