blob: 57ad0a702849ea0dab37df6911547bf6f61dcc9e [file] [log] [blame]
Shawn Nematbakhshebe3b3c2013-09-26 16:44:14 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2013 Google Inc.
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.
Shawn Nematbakhshebe3b3c2013-09-26 16:44:14 -070014 */
15
Shawn Nematbakhshebe3b3c2013-09-26 16:44:14 -070016#include <device/pci.h>
17#include <console/console.h>
Julius Werner18ea2d32014-10-07 16:42:17 -070018#include <soc/gpio.h>
19#include <soc/pmc.h>
20#include <soc/smm.h>
Shawn Nematbakhshebe3b3c2013-09-26 16:44:14 -070021
22/* GPIO-to-Pad LUTs */
23static const u8 gpncore_gpio_to_pad[GPNCORE_COUNT] =
Shawn Nematbakhsh5f5cd722013-11-21 11:00:53 -080024 { 19, 18, 17, 20, 21, 22, 24, 25, /* [ 0: 7] */
25 23, 16, 14, 15, 12, 26, 27, 1, /* [ 8:15] */
26 4, 8, 11, 0, 3, 6, 10, 13, /* [16:23] */
Shawn Nematbakhsh85614602013-10-09 15:29:46 -070027 2, 5, 9 }; /* [24:26] */
Shawn Nematbakhshebe3b3c2013-09-26 16:44:14 -070028
29static const u8 gpscore_gpio_to_pad[GPSCORE_COUNT] =
Shawn Nematbakhsh85614602013-10-09 15:29:46 -070030 { 85, 89, 93, 96, 99, 102, 98, 101, /* [ 0: 7] */
31 34, 37, 36, 38, 39, 35, 40, 84, /* [ 8: 15] */
32 62, 61, 64, 59, 54, 56, 60, 55, /* [16: 23] */
33 63, 57, 51, 50, 53, 47, 52, 49, /* [24: 31] */
34 48, 43, 46, 41, 45, 42, 58, 44, /* [32: 39] */
35 95, 105, 70, 68, 67, 66, 69, 71, /* [40: 47] */
36 65, 72, 86, 90, 88, 92, 103, 77, /* [48: 55] */
37 79, 83, 78, 81, 80, 82, 13, 12, /* [56: 63] */
38 15, 14, 17, 18, 19, 16, 2, 1, /* [64: 71] */
39 0, 4, 6, 7, 9, 8, 33, 32, /* [72: 79] */
40 31, 30, 29, 27, 25, 28, 26, 23, /* [80: 87] */
41 21, 20, 24, 22, 5, 3, 10, 11, /* [88: 95] */
42 106, 87, 91, 104, 97, 100 }; /* [96:101] */
Shawn Nematbakhshebe3b3c2013-09-26 16:44:14 -070043
44static const u8 gpssus_gpio_to_pad[GPSSUS_COUNT] =
Shawn Nematbakhsh85614602013-10-09 15:29:46 -070045 { 29, 33, 30, 31, 32, 34, 36, 35, /* [ 0: 7] */
46 38, 37, 18, 7, 11, 20, 17, 1, /* [ 8:15] */
47 8, 10, 19, 12, 0, 2, 23, 39, /* [16:23] */
48 28, 27, 22, 21, 24, 25, 26, 51, /* [24:31] */
49 56, 54, 49, 55, 48, 57, 50, 58, /* [32:39] */
50 52, 53, 59, 40 }; /* [40:43] */
Shawn Nematbakhshebe3b3c2013-09-26 16:44:14 -070051
52/* GPIO bank descriptions */
53static const struct gpio_bank gpncore_bank = {
Shawn Nematbakhsh85614602013-10-09 15:29:46 -070054 .gpio_count = GPNCORE_COUNT,
55 .gpio_to_pad = gpncore_gpio_to_pad,
56 .legacy_base = GP_LEGACY_BASE_NONE,
57 .pad_base = GPNCORE_PAD_BASE,
58 .has_wake_en = 0,
Shawn Nematbakhsh27351b92013-12-06 16:58:10 -080059 .gpio_f1_range_start = GPNCORE_GPIO_F1_RANGE_START,
60 .gpio_f1_range_end = GPNCORE_GPIO_F1_RANGE_END,
Shawn Nematbakhshebe3b3c2013-09-26 16:44:14 -070061};
62
63static const struct gpio_bank gpscore_bank = {
Shawn Nematbakhsh85614602013-10-09 15:29:46 -070064 .gpio_count = GPSCORE_COUNT,
65 .gpio_to_pad = gpscore_gpio_to_pad,
66 .legacy_base = GPSCORE_LEGACY_BASE,
67 .pad_base = GPSCORE_PAD_BASE,
68 .has_wake_en = 0,
Shawn Nematbakhsh27351b92013-12-06 16:58:10 -080069 .gpio_f1_range_start = GPSCORE_GPIO_F1_RANGE_START,
70 .gpio_f1_range_end = GPSCORE_GPIO_F1_RANGE_END,
Shawn Nematbakhshebe3b3c2013-09-26 16:44:14 -070071};
72
73static const struct gpio_bank gpssus_bank = {
Shawn Nematbakhsh85614602013-10-09 15:29:46 -070074 .gpio_count = GPSSUS_COUNT,
75 .gpio_to_pad = gpssus_gpio_to_pad,
76 .legacy_base = GPSSUS_LEGACY_BASE,
77 .pad_base = GPSSUS_PAD_BASE,
78 .has_wake_en = 1,
Shawn Nematbakhsh27351b92013-12-06 16:58:10 -080079 .gpio_f1_range_start = GPSSUS_GPIO_F1_RANGE_START,
80 .gpio_f1_range_end = GPSSUS_GPIO_F1_RANGE_END,
Shawn Nematbakhshebe3b3c2013-09-26 16:44:14 -070081};
82
83static void setup_gpios(const struct soc_gpio_map *gpios,
84 const struct gpio_bank *bank)
85{
86 const struct soc_gpio_map *config;
87 int gpio = 0;
Shawn Nematbakhsh27351b92013-12-06 16:58:10 -080088 u32 reg, pad_conf0;
Shawn Nematbakhshebe3b3c2013-09-26 16:44:14 -070089 u8 set, bit;
90
91 u32 use_sel[4] = {0};
92 u32 io_sel[4] = {0};
93 u32 gp_lvl[4] = {0};
94 u32 tpe[4] = {0};
95 u32 tne[4] = {0};
96 u32 wake_en[4] = {0};
97
98 if (!gpios)
99 return;
100
101 for (config = gpios; config->pad_conf0 != GPIO_LIST_END;
102 config++, gpio++) {
103 if (gpio > bank->gpio_count)
104 break;
105
106 set = gpio >> 5;
107 bit = gpio % 32;
108
109 if (bank->legacy_base != GP_LEGACY_BASE_NONE) {
110 /* Legacy IO configuration */
111 use_sel[set] |= config->use_sel << bit;
112 io_sel[set] |= config->io_sel << bit;
113 gp_lvl[set] |= config->gp_lvl << bit;
114 tpe[set] |= config->tpe << bit;
115 tne[set] |= config->tne << bit;
116
117 /* Some banks do not have wake_en ability */
118 if (bank->has_wake_en)
119 wake_en[set] |= config->wake_en << bit;
120 }
121
122 /* Pad configuration registers */
123 reg = bank->pad_base + 16 * bank->gpio_to_pad[gpio];
124
Shawn Nematbakhsh27351b92013-12-06 16:58:10 -0800125 /* Add correct func to GPIO pad config */
126 pad_conf0 = config->pad_conf0;
127 if (config->is_gpio)
128 {
129 if (gpio >= bank->gpio_f1_range_start &&
130 gpio <= bank->gpio_f1_range_end)
131 pad_conf0 |= PAD_FUNC1;
132 else
133 pad_conf0 |= PAD_FUNC0;
134 }
135
Shawn Nematbakhshebe3b3c2013-09-26 16:44:14 -0700136#ifdef GPIO_DEBUG
137 printk(BIOS_DEBUG, "Write Pad: Base(%x) - %x %x %x\n",
Shawn Nematbakhsh27351b92013-12-06 16:58:10 -0800138 reg, pad_conf0, config->pad_conf1, config->pad_val);
Shawn Nematbakhshebe3b3c2013-09-26 16:44:14 -0700139#endif
140
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800141 write32((u32 *)(reg + PAD_CONF0_REG), pad_conf0);
142 write32((u32 *)(reg + PAD_CONF1_REG), config->pad_conf1);
143 write32((u32 *)(reg + PAD_VAL_REG), config->pad_val);
Shawn Nematbakhshebe3b3c2013-09-26 16:44:14 -0700144 }
145
146 if (bank->legacy_base != GP_LEGACY_BASE_NONE)
147 for (set = 0; set <= (bank->gpio_count - 1) / 32; ++set) {
148 reg = bank->legacy_base + 0x20 * set;
149
150#ifdef GPIO_DEBUG
151 printk(BIOS_DEBUG,
152 "Write GPIO: Reg(%x) - %x %x %x %x %x\n",
153 reg, use_sel[set], io_sel[set], gp_lvl[set],
154 tpe[set], tne[set]);
155#endif
156
157 outl(use_sel[set], reg + LEGACY_USE_SEL_REG);
158 outl(io_sel[set], reg + LEGACY_IO_SEL_REG);
159 outl(gp_lvl[set], reg + LEGACY_GP_LVL_REG);
160 outl(tpe[set], reg + LEGACY_TPE_REG);
161 outl(tne[set], reg + LEGACY_TNE_REG);
162
163 /* TS registers are WOC */
164 outl(0, reg + LEGACY_TS_REG);
165
166 if (bank->has_wake_en)
167 outl(wake_en[set], reg + LEGACY_WAKE_EN_REG);
168 }
169}
170
Aaron Durbin59a4cd52013-11-11 12:09:28 -0600171static void setup_gpio_route(const struct soc_gpio_map *sus,
172 const struct soc_gpio_map *core)
173{
174 uint32_t route_reg = 0;
175 int i;
176
177 for (i = 0; i < 8; i++) {
178 /* SMI takes precedence and wake_en implies SCI. */
179 if (sus[i].smi) {
180 route_reg |= ROUTE_SMI << (2 * i);
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -0800181 } else if (sus[i].sci) {
Aaron Durbin59a4cd52013-11-11 12:09:28 -0600182 route_reg |= ROUTE_SCI << (2 * i);
183 }
184
185 if (core[i].smi) {
186 route_reg |= ROUTE_SMI << (2 * (i + 8));
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -0800187 } else if (core[i].sci) {
Aaron Durbin59a4cd52013-11-11 12:09:28 -0600188 route_reg |= ROUTE_SCI << (2 * (i + 8));
189 }
190 }
Kein Yuan35110232014-02-22 12:26:55 -0800191 southcluster_smm_save_param(SMM_SAVE_PARAM_GPIO_ROUTE, route_reg);
Aaron Durbin59a4cd52013-11-11 12:09:28 -0600192}
193
Shawn Nematbakhshfb494d62013-11-08 16:43:34 -0800194static void setup_dirqs(const u8 dirq[GPIO_MAX_DIRQS],
195 const struct gpio_bank *bank)
196{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800197 u32 *reg = (u32 *)(bank->pad_base + PAD_BASE_DIRQ_OFFSET);
Shawn Nematbakhshfb494d62013-11-08 16:43:34 -0800198 u32 val;
199 int i;
200
201 /* Write all four DIRQ registers */
202 for (i=0; i<4; ++i) {
203 val = dirq[i * 4 + 3] << 24 | dirq[i * 4 + 2] << 16 |
204 dirq[i * 4 + 1] << 8 | dirq[i * 4];
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800205 write32(reg + i, val);
Shawn Nematbakhshfb494d62013-11-08 16:43:34 -0800206#ifdef GPIO_DEBUG
207 printk(BIOS_DEBUG, "Write DIRQ reg(%x) - %x\n",
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800208 reg + i, val);
Shawn Nematbakhshfb494d62013-11-08 16:43:34 -0800209#endif
210 }
211}
212
Kein Yuan35110232014-02-22 12:26:55 -0800213void setup_soc_gpios(struct soc_gpio_config *config, u8 enable_xdp_tap)
Shawn Nematbakhshebe3b3c2013-09-26 16:44:14 -0700214{
215 if (config) {
216 setup_gpios(config->ncore, &gpncore_bank);
217 setup_gpios(config->score, &gpscore_bank);
218 setup_gpios(config->ssus, &gpssus_bank);
Aaron Durbin59a4cd52013-11-11 12:09:28 -0600219 setup_gpio_route(config->ssus, config->score);
Shawn Nematbakhshfb494d62013-11-08 16:43:34 -0800220
221 if (config->core_dirq)
222 setup_dirqs(*config->core_dirq, &gpscore_bank);
223 if (config->sus_dirq)
224 setup_dirqs(*config->sus_dirq, &gpssus_bank);
Shawn Nematbakhshebe3b3c2013-09-26 16:44:14 -0700225 }
Shawn Nematbakhshfb494d62013-11-08 16:43:34 -0800226
Kein Yuan35110232014-02-22 12:26:55 -0800227 /* Set on die termination feature with pull up value and
228 * drive the pad high for TAP_TDO and TAP_TMS
229 */
230 if (!enable_xdp_tap) {
231 printk(BIOS_DEBUG, "Tri-state TDO and TMS\n");
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800232 write32((u32 *)(GPSSUS_PAD_BASE + 0x2fc), 0xc);
233 write32((u32 *)(GPSSUS_PAD_BASE + 0x2cc), 0xc);
Kein Yuan35110232014-02-22 12:26:55 -0800234 }
Shawn Nematbakhshebe3b3c2013-09-26 16:44:14 -0700235}
236
237struct soc_gpio_config* __attribute__((weak)) mainboard_get_gpios(void)
238{
239 printk(BIOS_DEBUG, "Default/empty GPIO config\n");
240 return NULL;
241}