Shawn Nematbakhsh | ebe3b3c | 2013-09-26 16:44:14 -0700 | [diff] [blame] | 1 | /* |
| 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 Nematbakhsh | ebe3b3c | 2013-09-26 16:44:14 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
Shawn Nematbakhsh | ebe3b3c | 2013-09-26 16:44:14 -0700 | [diff] [blame] | 16 | #include <device/pci.h> |
| 17 | #include <console/console.h> |
Julius Werner | 18ea2d3 | 2014-10-07 16:42:17 -0700 | [diff] [blame] | 18 | #include <soc/gpio.h> |
| 19 | #include <soc/pmc.h> |
| 20 | #include <soc/smm.h> |
Shawn Nematbakhsh | ebe3b3c | 2013-09-26 16:44:14 -0700 | [diff] [blame] | 21 | |
| 22 | /* GPIO-to-Pad LUTs */ |
| 23 | static const u8 gpncore_gpio_to_pad[GPNCORE_COUNT] = |
Shawn Nematbakhsh | 5f5cd72 | 2013-11-21 11:00:53 -0800 | [diff] [blame] | 24 | { 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 Nematbakhsh | 8561460 | 2013-10-09 15:29:46 -0700 | [diff] [blame] | 27 | 2, 5, 9 }; /* [24:26] */ |
Shawn Nematbakhsh | ebe3b3c | 2013-09-26 16:44:14 -0700 | [diff] [blame] | 28 | |
| 29 | static const u8 gpscore_gpio_to_pad[GPSCORE_COUNT] = |
Shawn Nematbakhsh | 8561460 | 2013-10-09 15:29:46 -0700 | [diff] [blame] | 30 | { 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 Nematbakhsh | ebe3b3c | 2013-09-26 16:44:14 -0700 | [diff] [blame] | 43 | |
| 44 | static const u8 gpssus_gpio_to_pad[GPSSUS_COUNT] = |
Shawn Nematbakhsh | 8561460 | 2013-10-09 15:29:46 -0700 | [diff] [blame] | 45 | { 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 Nematbakhsh | ebe3b3c | 2013-09-26 16:44:14 -0700 | [diff] [blame] | 51 | |
| 52 | /* GPIO bank descriptions */ |
| 53 | static const struct gpio_bank gpncore_bank = { |
Shawn Nematbakhsh | 8561460 | 2013-10-09 15:29:46 -0700 | [diff] [blame] | 54 | .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 Nematbakhsh | 27351b9 | 2013-12-06 16:58:10 -0800 | [diff] [blame] | 59 | .gpio_f1_range_start = GPNCORE_GPIO_F1_RANGE_START, |
| 60 | .gpio_f1_range_end = GPNCORE_GPIO_F1_RANGE_END, |
Shawn Nematbakhsh | ebe3b3c | 2013-09-26 16:44:14 -0700 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | static const struct gpio_bank gpscore_bank = { |
Shawn Nematbakhsh | 8561460 | 2013-10-09 15:29:46 -0700 | [diff] [blame] | 64 | .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 Nematbakhsh | 27351b9 | 2013-12-06 16:58:10 -0800 | [diff] [blame] | 69 | .gpio_f1_range_start = GPSCORE_GPIO_F1_RANGE_START, |
| 70 | .gpio_f1_range_end = GPSCORE_GPIO_F1_RANGE_END, |
Shawn Nematbakhsh | ebe3b3c | 2013-09-26 16:44:14 -0700 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | static const struct gpio_bank gpssus_bank = { |
Shawn Nematbakhsh | 8561460 | 2013-10-09 15:29:46 -0700 | [diff] [blame] | 74 | .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 Nematbakhsh | 27351b9 | 2013-12-06 16:58:10 -0800 | [diff] [blame] | 79 | .gpio_f1_range_start = GPSSUS_GPIO_F1_RANGE_START, |
| 80 | .gpio_f1_range_end = GPSSUS_GPIO_F1_RANGE_END, |
Shawn Nematbakhsh | ebe3b3c | 2013-09-26 16:44:14 -0700 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | static 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 Nematbakhsh | 27351b9 | 2013-12-06 16:58:10 -0800 | [diff] [blame] | 88 | u32 reg, pad_conf0; |
Shawn Nematbakhsh | ebe3b3c | 2013-09-26 16:44:14 -0700 | [diff] [blame] | 89 | 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 Nematbakhsh | 27351b9 | 2013-12-06 16:58:10 -0800 | [diff] [blame] | 125 | /* 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 Nematbakhsh | ebe3b3c | 2013-09-26 16:44:14 -0700 | [diff] [blame] | 136 | #ifdef GPIO_DEBUG |
| 137 | printk(BIOS_DEBUG, "Write Pad: Base(%x) - %x %x %x\n", |
Shawn Nematbakhsh | 27351b9 | 2013-12-06 16:58:10 -0800 | [diff] [blame] | 138 | reg, pad_conf0, config->pad_conf1, config->pad_val); |
Shawn Nematbakhsh | ebe3b3c | 2013-09-26 16:44:14 -0700 | [diff] [blame] | 139 | #endif |
| 140 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 141 | 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 Nematbakhsh | ebe3b3c | 2013-09-26 16:44:14 -0700 | [diff] [blame] | 144 | } |
| 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 Durbin | 59a4cd5 | 2013-11-11 12:09:28 -0600 | [diff] [blame] | 171 | static 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 Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 181 | } else if (sus[i].sci) { |
Aaron Durbin | 59a4cd5 | 2013-11-11 12:09:28 -0600 | [diff] [blame] | 182 | route_reg |= ROUTE_SCI << (2 * i); |
| 183 | } |
| 184 | |
| 185 | if (core[i].smi) { |
| 186 | route_reg |= ROUTE_SMI << (2 * (i + 8)); |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 187 | } else if (core[i].sci) { |
Aaron Durbin | 59a4cd5 | 2013-11-11 12:09:28 -0600 | [diff] [blame] | 188 | route_reg |= ROUTE_SCI << (2 * (i + 8)); |
| 189 | } |
| 190 | } |
Kein Yuan | 3511023 | 2014-02-22 12:26:55 -0800 | [diff] [blame] | 191 | southcluster_smm_save_param(SMM_SAVE_PARAM_GPIO_ROUTE, route_reg); |
Aaron Durbin | 59a4cd5 | 2013-11-11 12:09:28 -0600 | [diff] [blame] | 192 | } |
| 193 | |
Shawn Nematbakhsh | fb494d6 | 2013-11-08 16:43:34 -0800 | [diff] [blame] | 194 | static void setup_dirqs(const u8 dirq[GPIO_MAX_DIRQS], |
| 195 | const struct gpio_bank *bank) |
| 196 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 197 | u32 *reg = (u32 *)(bank->pad_base + PAD_BASE_DIRQ_OFFSET); |
Shawn Nematbakhsh | fb494d6 | 2013-11-08 16:43:34 -0800 | [diff] [blame] | 198 | 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 Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 205 | write32(reg + i, val); |
Shawn Nematbakhsh | fb494d6 | 2013-11-08 16:43:34 -0800 | [diff] [blame] | 206 | #ifdef GPIO_DEBUG |
| 207 | printk(BIOS_DEBUG, "Write DIRQ reg(%x) - %x\n", |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 208 | reg + i, val); |
Shawn Nematbakhsh | fb494d6 | 2013-11-08 16:43:34 -0800 | [diff] [blame] | 209 | #endif |
| 210 | } |
| 211 | } |
| 212 | |
Kein Yuan | 3511023 | 2014-02-22 12:26:55 -0800 | [diff] [blame] | 213 | void setup_soc_gpios(struct soc_gpio_config *config, u8 enable_xdp_tap) |
Shawn Nematbakhsh | ebe3b3c | 2013-09-26 16:44:14 -0700 | [diff] [blame] | 214 | { |
| 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 Durbin | 59a4cd5 | 2013-11-11 12:09:28 -0600 | [diff] [blame] | 219 | setup_gpio_route(config->ssus, config->score); |
Shawn Nematbakhsh | fb494d6 | 2013-11-08 16:43:34 -0800 | [diff] [blame] | 220 | |
| 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 Nematbakhsh | ebe3b3c | 2013-09-26 16:44:14 -0700 | [diff] [blame] | 225 | } |
Shawn Nematbakhsh | fb494d6 | 2013-11-08 16:43:34 -0800 | [diff] [blame] | 226 | |
Kein Yuan | 3511023 | 2014-02-22 12:26:55 -0800 | [diff] [blame] | 227 | /* 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 Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 232 | write32((u32 *)(GPSSUS_PAD_BASE + 0x2fc), 0xc); |
| 233 | write32((u32 *)(GPSSUS_PAD_BASE + 0x2cc), 0xc); |
Kein Yuan | 3511023 | 2014-02-22 12:26:55 -0800 | [diff] [blame] | 234 | } |
Shawn Nematbakhsh | ebe3b3c | 2013-09-26 16:44:14 -0700 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | struct soc_gpio_config* __attribute__((weak)) mainboard_get_gpios(void) |
| 238 | { |
| 239 | printk(BIOS_DEBUG, "Default/empty GPIO config\n"); |
| 240 | return NULL; |
| 241 | } |