Since some people disapprove of white space cleanups mixed in regular commits
[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 ich4_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, "GPIO_USE_SEL2" },
56         { 0x34, 4, "GP_IO_SEL2" },
57         { 0x38, 4, "GP_LVL2" },
58         { 0x3C, 4, "RESERVED" }
59 };
60
61 static const io_register_t ich6_gpio_registers[] = {
62         { 0x00, 4, "GPIO_USE_SEL" },
63         { 0x08, 4, "RESERVED" },
64         { 0x0c, 4, "GP_LVL" },
65         { 0x10, 4, "RESERVED" },
66         { 0x14, 4, "RESERVED" },
67         { 0x18, 4, "GPO_BLINK" },
68         { 0x1c, 4, "RESERVED" },
69         { 0x20, 4, "RESERVED" },
70         { 0x24, 4, "RESERVED" },
71         { 0x28, 4, "RESERVED" },
72         { 0x2c, 4, "GPI_INV" },
73         { 0x30, 4, "GPIO_USE_SEL2" },
74         { 0x34, 4, "GP_IO_SEL2" },
75         { 0x38, 4, "GP_LVL2" },
76         { 0x04, 4, "GP_IO_SEL" },
77 };
78
79 static const io_register_t ich7_gpio_registers[] = {
80         { 0x00, 4, "GPIO_USE_SEL" },
81         { 0x04, 4, "GP_IO_SEL" },
82         { 0x08, 4, "RESERVED" },
83         { 0x0c, 4, "GP_LVL" },
84         { 0x10, 4, "RESERVED" },
85         { 0x14, 4, "RESERVED" },
86         { 0x18, 4, "GPO_BLINK" },
87         { 0x1c, 4, "RESERVED" },
88         { 0x20, 4, "RESERVED" },
89         { 0x24, 4, "RESERVED" },
90         { 0x28, 4, "RESERVED" },
91         { 0x2c, 4, "GPI_INV" },
92         { 0x30, 4, "GPIO_USE_SEL2" },
93         { 0x34, 4, "GP_IO_SEL2" },
94         { 0x38, 4, "GP_LVL2" },
95         { 0x3C, 4, "RESERVED" }
96 };
97
98 static const io_register_t ich8_gpio_registers[] = {
99         { 0x00, 4, "GPIO_USE_SEL" },
100         { 0x04, 4, "GP_IO_SEL" },
101         { 0x08, 4, "RESERVED" },
102         { 0x0c, 4, "GP_LVL" },
103         { 0x10, 4, "GPIO_USE_SEL Override (LOW)" },
104         { 0x14, 4, "RESERVED" },
105         { 0x18, 4, "GPO_BLINK" },
106         { 0x1c, 4, "GP_SER_BLINK" },
107         { 0x20, 4, "GP_SB_CMDSTS" },
108         { 0x24, 4, "GP_SB_DATA" },
109         { 0x28, 4, "RESERVED" },
110         { 0x2c, 4, "GPI_INV" },
111         { 0x30, 4, "GPIO_USE_SEL2" },
112         { 0x34, 4, "GP_IO_SEL2" },
113         { 0x38, 4, "GP_LVL2" },
114         { 0x3C, 4, "GPIO_USE_SEL Override (HIGH)" }
115 };
116
117
118 int print_gpios(struct pci_dev *sb)
119 {
120         int i, size;
121         uint16_t gpiobase;
122         const io_register_t *gpio_registers;
123
124         printf("\n============= GPIOS =============\n\n");
125
126         switch (sb->device_id) {
127         case PCI_DEVICE_ID_INTEL_ICH8M:
128                 gpiobase = pci_read_word(sb, 0x48) & 0xfffc;
129                 gpio_registers = ich8_gpio_registers;
130                 size = ARRAY_SIZE(ich8_gpio_registers);
131                 break;
132         case PCI_DEVICE_ID_INTEL_ICH7:
133         case PCI_DEVICE_ID_INTEL_ICH7M:
134         case PCI_DEVICE_ID_INTEL_ICH7DH:
135         case PCI_DEVICE_ID_INTEL_ICH7MDH:
136                 gpiobase = pci_read_word(sb, 0x48) & 0xfffc;
137                 gpio_registers = ich7_gpio_registers;
138                 size = ARRAY_SIZE(ich7_gpio_registers);
139                 break;
140         case PCI_DEVICE_ID_INTEL_ICH6:
141                 gpiobase = pci_read_word(sb, 0x48) & 0xfffc;
142                 gpio_registers = ich6_gpio_registers;
143                 size = ARRAY_SIZE(ich6_gpio_registers);
144                 break;
145         case PCI_DEVICE_ID_INTEL_ICH4:
146         case PCI_DEVICE_ID_INTEL_ICH4M:
147                 gpiobase = pci_read_word(sb, 0x58) & 0xfffc;
148                 gpio_registers = ich4_gpio_registers;
149                 size = ARRAY_SIZE(ich4_gpio_registers);
150                 break;
151         case PCI_DEVICE_ID_INTEL_ICH:
152         case PCI_DEVICE_ID_INTEL_ICH0:
153                 gpiobase = pci_read_word(sb, 0x58) & 0xfffc;
154                 gpio_registers = ich0_gpio_registers;
155                 size = ARRAY_SIZE(ich0_gpio_registers);
156                 break;
157         case PCI_DEVICE_ID_INTEL_82371XX:
158                 printf("This southbridge has GPIOs in the PM unit.\n");
159                 return 1;
160         case 0x1234: // Dummy for non-existent functionality
161                 printf("This southbridge does not have GPIOBASE.\n");
162                 return 1;
163         default:
164                 printf("Error: Dumping GPIOs on this southbridge is not (yet) supported.\n");
165                 return 1;
166         }
167
168         printf("GPIOBASE = 0x%04x (IO)\n\n", gpiobase);
169
170         for (i = 0; i < size; i++) {
171                 switch (gpio_registers[i].size) {
172                 case 4:
173                         printf("gpiobase+0x%04x: 0x%08x (%s)\n",
174                                 gpio_registers[i].addr,
175                                 inl(gpiobase+gpio_registers[i].addr),
176                                 gpio_registers[i].name);
177                         break;
178                 case 2:
179                         printf("gpiobase+0x%04x: 0x%04x     (%s)\n",
180                                 gpio_registers[i].addr,
181                                 inw(gpiobase+gpio_registers[i].addr),
182                                 gpio_registers[i].name);
183                         break;
184                 case 1:
185                         printf("gpiobase+0x%04x: 0x%02x       (%s)\n",
186                                 gpio_registers[i].addr,
187                                 inb(gpiobase+gpio_registers[i].addr),
188                                 gpio_registers[i].name);
189                         break;
190                 }
191         }
192
193         return 0;
194 }
195