inteltool: Add Intel i63xx I/O Controller Hub
[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 static const io_register_t i631x_gpio_registers[] = {
207         { 0x00, 4, "GPIO_USE_SEL" },
208         { 0x04, 4, "GP_IO_SEL" },
209         { 0x08, 4, "RESERVED" },
210         { 0x0c, 4, "GP_LVL" },
211         { 0x10, 4, "RESERVED" },
212         { 0x14, 4, "RESERVED" },
213         { 0x18, 4, "GPO_BLINK" },
214         { 0x1c, 4, "RESERVED" },
215         { 0x20, 4, "RESERVED" },
216         { 0x24, 4, "RESERVED" },
217         { 0x28, 4, "RESERVED" },
218         { 0x2c, 4, "GPI_INV" },
219         { 0x30, 4, "GPIO_USE_SEL2" },
220         { 0x34, 4, "GP_IO_SEL2" },
221         { 0x38, 4, "GP_LVL2" },
222 };
223
224 int print_gpios(struct pci_dev *sb)
225 {
226         int i, size;
227         uint16_t gpiobase;
228         const io_register_t *gpio_registers;
229
230         printf("\n============= GPIOS =============\n\n");
231
232         switch (sb->device_id) {
233         case PCI_DEVICE_ID_INTEL_ICH10R:
234                 gpiobase = pci_read_word(sb, 0x48) & 0xfffc;
235                 gpio_registers = ich10_gpio_registers;
236                 size = ARRAY_SIZE(ich10_gpio_registers);
237                 break;
238         case PCI_DEVICE_ID_INTEL_ICH9DH:
239         case PCI_DEVICE_ID_INTEL_ICH9DO:
240         case PCI_DEVICE_ID_INTEL_ICH9R:
241         case PCI_DEVICE_ID_INTEL_ICH9:
242         case PCI_DEVICE_ID_INTEL_ICH9M:
243         case PCI_DEVICE_ID_INTEL_ICH9ME:
244                 gpiobase = pci_read_word(sb, 0x48) & 0xfffc;
245                 gpio_registers = ich9_gpio_registers;
246                 size = ARRAY_SIZE(ich9_gpio_registers);
247                 break;
248         case PCI_DEVICE_ID_INTEL_ICH8:
249         case PCI_DEVICE_ID_INTEL_ICH8M:
250                 gpiobase = pci_read_word(sb, 0x48) & 0xfffc;
251                 gpio_registers = ich8_gpio_registers;
252                 size = ARRAY_SIZE(ich8_gpio_registers);
253                 break;
254         case PCI_DEVICE_ID_INTEL_ICH7:
255         case PCI_DEVICE_ID_INTEL_ICH7M:
256         case PCI_DEVICE_ID_INTEL_ICH7DH:
257         case PCI_DEVICE_ID_INTEL_ICH7MDH:
258         case PCI_DEVICE_ID_INTEL_NM10:
259                 gpiobase = pci_read_word(sb, 0x48) & 0xfffc;
260                 gpio_registers = ich7_gpio_registers;
261                 size = ARRAY_SIZE(ich7_gpio_registers);
262                 break;
263         case PCI_DEVICE_ID_INTEL_ICH6:
264                 gpiobase = pci_read_word(sb, 0x48) & 0xfffc;
265                 gpio_registers = ich6_gpio_registers;
266                 size = ARRAY_SIZE(ich6_gpio_registers);
267                 break;
268         case PCI_DEVICE_ID_INTEL_ICH5:
269                 gpiobase = pci_read_word(sb, 0x58) & 0xfffc;
270                 gpio_registers = ich5_gpio_registers;
271                 size = ARRAY_SIZE(ich5_gpio_registers);
272                 break;
273         case PCI_DEVICE_ID_INTEL_ICH4:
274         case PCI_DEVICE_ID_INTEL_ICH4M:
275                 gpiobase = pci_read_word(sb, 0x58) & 0xfffc;
276                 gpio_registers = ich4_gpio_registers;
277                 size = ARRAY_SIZE(ich4_gpio_registers);
278                 break;
279         case PCI_DEVICE_ID_INTEL_ICH2:
280                 gpiobase = pci_read_word(sb, 0x58) & 0xfffc;
281                 gpio_registers = ich2_gpio_registers;
282                 size = ARRAY_SIZE(ich2_gpio_registers);
283                 break;
284         case PCI_DEVICE_ID_INTEL_ICH:
285         case PCI_DEVICE_ID_INTEL_ICH0:
286                 gpiobase = pci_read_word(sb, 0x58) & 0xfffc;
287                 gpio_registers = ich0_gpio_registers;
288                 size = ARRAY_SIZE(ich0_gpio_registers);
289                 break;
290
291         case PCI_DEVICE_ID_INTEL_I63XX:
292                 gpiobase = pci_read_word(sb, 0x48) & 0xfffc;
293                 gpio_registers = i631x_gpio_registers;
294                 size = ARRAY_SIZE(i631x_gpio_registers);
295                 break;
296
297         case PCI_DEVICE_ID_INTEL_82371XX:
298                 printf("This southbridge has GPIOs in the PM unit.\n");
299                 return 1;
300         case 0x1234: // Dummy for non-existent functionality
301                 printf("This southbridge does not have GPIOBASE.\n");
302                 return 1;
303         default:
304                 printf("Error: Dumping GPIOs on this southbridge is not (yet) supported.\n");
305                 return 1;
306         }
307
308         printf("GPIOBASE = 0x%04x (IO)\n\n", gpiobase);
309
310         for (i = 0; i < size; i++) {
311                 switch (gpio_registers[i].size) {
312                 case 4:
313                         printf("gpiobase+0x%04x: 0x%08x (%s)\n",
314                                 gpio_registers[i].addr,
315                                 inl(gpiobase+gpio_registers[i].addr),
316                                 gpio_registers[i].name);
317                         break;
318                 case 2:
319                         printf("gpiobase+0x%04x: 0x%04x     (%s)\n",
320                                 gpio_registers[i].addr,
321                                 inw(gpiobase+gpio_registers[i].addr),
322                                 gpio_registers[i].name);
323                         break;
324                 case 1:
325                         printf("gpiobase+0x%04x: 0x%02x       (%s)\n",
326                                 gpio_registers[i].addr,
327                                 inb(gpiobase+gpio_registers[i].addr),
328                                 gpio_registers[i].name);
329                         break;
330                 }
331         }
332
333         return 0;
334 }