blob: 854d4b5ca7b6773c12cf8f3056fa2a93f7d7211b [file] [log] [blame]
Angel Ponsba38f372020-04-05 15:46:45 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Lee Leahy77ff0b12015-05-05 15:07:29 -07002
Lee Leahy77ff0b12015-05-05 15:07:29 -07003#include <console/console.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02004#include <arch/io.h>
5#include <device/mmio.h>
Lee Leahy32471722015-04-20 15:20:28 -07006#include <device/pci.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -07007#include <soc/gpio.h>
Lee Leahy32471722015-04-20 15:20:28 -07008#include <soc/pm.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -07009#include <soc/smm.h>
10
Lee Leahy32471722015-04-20 15:20:28 -070011#define GPIO_DEBUG
Lee Leahy77ff0b12015-05-05 15:07:29 -070012
Lee Leahy32471722015-04-20 15:20:28 -070013/* gpio map to pad number LUTs */
Lee Leahy77ff0b12015-05-05 15:07:29 -070014
Lee Leahy32471722015-04-20 15:20:28 -070015static const u8 gpncommunity_gpio_to_pad[GP_NORTH_COUNT] = {
16 0, 1, 2, 3, 4, 5, 6, 7, 8, 15,
17 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
18 26, 27, 30, 31, 32, 33, 34, 35, 36, 37,
19 38, 39, 40, 41, 45, 46, 47, 48, 49, 50,
20 51, 52, 53, 54, 55, 56, 60, 61, 62, 63,
21 64, 65, 66, 67, 68, 69, 70, 71, 72 };
Lee Leahy77ff0b12015-05-05 15:07:29 -070022
Lee Leahy32471722015-04-20 15:20:28 -070023static const u8 gpsecommunity_gpio_to_pad[GP_SOUTHEAST_COUNT] = {
24 0, 1, 2, 3, 4, 5, 6, 7, 15, 16,
25 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
26 30, 31, 32, 33, 34, 35, 45, 46, 47, 48,
27 49, 50, 51, 52, 60, 61, 62, 63, 64, 65,
28 66, 67, 68, 69, 75, 76, 77, 78, 79, 80,
29 81, 82, 83, 84, 85 };
Lee Leahy77ff0b12015-05-05 15:07:29 -070030
Lee Leahy32471722015-04-20 15:20:28 -070031static const u8 gpswcommunity_gpio_to_pad[GP_SOUTHWEST_COUNT] = {
32 0, 1, 2, 3, 4, 5, 6, 7, 15, 16,
33 17, 18, 19, 20, 21, 22, 30, 31, 32, 33,
34 34, 35, 36, 37, 45, 46, 47, 48, 49, 50,
35 51, 52, 60, 61, 62, 63, 64, 65, 66, 67,
36 75, 76, 77, 78, 79, 80, 81, 82, 90, 91,
37 92, 93, 94, 95, 96, 97 };
38
39static const u8 gpecommunity_gpio_to_pad[GP_EAST_COUNT] = {
40 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
41 10, 11, 15, 16, 17, 18, 19, 20, 21, 22,
42 23, 24, 25, 26 };
43
44/* GPIO Community descriptions */
45static const struct gpio_bank gpnorth_community = {
Angel Ponsaee7ab22020-03-19 00:31:58 +010046 .gpio_count = GP_NORTH_COUNT,
Lee Leahy6598b912017-03-16 17:30:09 -070047 .gpio_to_pad = gpncommunity_gpio_to_pad,
Angel Ponsaee7ab22020-03-19 00:31:58 +010048 .pad_base = COMMUNITY_GPNORTH_BASE,
49 .has_gpe_en = GPE_CAPABLE,
Lee Leahy77ff0b12015-05-05 15:07:29 -070050 .has_wake_en = 1,
Lee Leahy77ff0b12015-05-05 15:07:29 -070051};
52
Lee Leahy32471722015-04-20 15:20:28 -070053static const struct gpio_bank gpsoutheast_community = {
Angel Ponsaee7ab22020-03-19 00:31:58 +010054 .gpio_count = GP_SOUTHEAST_COUNT,
Lee Leahy32471722015-04-20 15:20:28 -070055 .gpio_to_pad = gpsecommunity_gpio_to_pad,
Angel Ponsaee7ab22020-03-19 00:31:58 +010056 .pad_base = COMMUNITY_GPSOUTHEAST_BASE,
57 .has_gpe_en = GPE_CAPABLE_NONE,
Lee Leahy32471722015-04-20 15:20:28 -070058 .has_wake_en = 1,
59};
60
61static const struct gpio_bank gpsouthwest_community = {
Angel Ponsaee7ab22020-03-19 00:31:58 +010062 .gpio_count = GP_SOUTHWEST_COUNT,
Lee Leahy32471722015-04-20 15:20:28 -070063 .gpio_to_pad = gpswcommunity_gpio_to_pad,
Angel Ponsaee7ab22020-03-19 00:31:58 +010064 .pad_base = COMMUNITY_GPSOUTHWEST_BASE,
65 .has_gpe_en = GPE_CAPABLE,
Lee Leahy32471722015-04-20 15:20:28 -070066 .has_wake_en = 1,
67};
68
69static const struct gpio_bank gpeast_community = {
Angel Ponsaee7ab22020-03-19 00:31:58 +010070 .gpio_count = GP_EAST_COUNT,
Lee Leahy32471722015-04-20 15:20:28 -070071 .gpio_to_pad = gpecommunity_gpio_to_pad,
Angel Ponsaee7ab22020-03-19 00:31:58 +010072 .pad_base = COMMUNITY_GPEAST_BASE,
73 .has_gpe_en = GPE_CAPABLE_NONE,
Lee Leahy32471722015-04-20 15:20:28 -070074 .has_wake_en = 1,
75};
76
77static void setup_gpio_route(const struct soc_gpio_map *sw_gpios,
Angel Ponsaee7ab22020-03-19 00:31:58 +010078 const struct soc_gpio_map *n_gpios)
Lee Leahy77ff0b12015-05-05 15:07:29 -070079{
Lee Leahy32471722015-04-20 15:20:28 -070080 const struct soc_gpio_map *n_config;
81 const struct soc_gpio_map *sw_config;
Lee Leahy77ff0b12015-05-05 15:07:29 -070082 uint32_t route_reg = 0;
Lee Leahy32471722015-04-20 15:20:28 -070083 uint32_t int_selection = 0;
84 uint32_t alt_gpio_smi = 0;
85 uint32_t gpe0a_en = 0;
86 int gpio = 0;
87 int north_done = 0;
88 int south_done = 0;
Lee Leahy77ff0b12015-05-05 15:07:29 -070089
Lee Leahy32471722015-04-20 15:20:28 -070090 for (sw_config = sw_gpios, n_config = n_gpios;
91 (!north_done || !south_done); sw_config++, n_config++, gpio++) {
92
Angel Ponsaee7ab22020-03-19 00:31:58 +010093 /* When north config is done */
94 if ((gpio > GP_NORTH_COUNT) || (n_config->pad_conf0 == GPIO_LIST_END))
Lee Leahy32471722015-04-20 15:20:28 -070095 north_done = 1;
96
Angel Ponsaee7ab22020-03-19 00:31:58 +010097 /* When southwest config is done */
98 if ((gpio > GP_SOUTHWEST_COUNT) || (sw_config->pad_conf0 == GPIO_LIST_END))
Lee Leahy32471722015-04-20 15:20:28 -070099 south_done = 1;
100
Angel Ponsaee7ab22020-03-19 00:31:58 +0100101 /* Route north gpios */
Lee Leahy32471722015-04-20 15:20:28 -0700102 if (!north_done) {
103 /* Int select from 8 to 15 */
104 int_selection = ((n_config->pad_conf0 >> 28) & 0xf);
Angel Ponsaee7ab22020-03-19 00:31:58 +0100105
Lee Leahy32471722015-04-20 15:20:28 -0700106 if (n_config->gpe == SMI) {
Angel Ponsaee7ab22020-03-19 00:31:58 +0100107 /* Set the corresponding bits (01) as per the interrupt line */
Lee Leahy32471722015-04-20 15:20:28 -0700108 route_reg |= (1 << ((int_selection - 8) * 2));
Angel Ponsaee7ab22020-03-19 00:31:58 +0100109
110 /* Reset the higher bit */
111 route_reg &= ~(1 << ((int_selection - 8) * 2 + 1));
112 alt_gpio_smi |= (1 << (int_selection + 8));
113
Lee Leahy32471722015-04-20 15:20:28 -0700114 } else if (n_config->gpe == SCI) {
Angel Ponsaee7ab22020-03-19 00:31:58 +0100115 /* Set the corresponding bits as per the interrupt line */
116 route_reg |= (1 << (((int_selection - 8) * 2) + 1));
117
118 /* Reset the bit */
Lee Leahy32471722015-04-20 15:20:28 -0700119 route_reg &= ~(1 << ((int_selection - 8) * 2));
Angel Ponsaee7ab22020-03-19 00:31:58 +0100120 gpe0a_en |= (1 << (int_selection + 8));
Lee Leahy32471722015-04-20 15:20:28 -0700121 }
Lee Leahy77ff0b12015-05-05 15:07:29 -0700122 }
123
Angel Ponsaee7ab22020-03-19 00:31:58 +0100124 /* Route southwest gpios */
Lee Leahy32471722015-04-20 15:20:28 -0700125 if (!south_done) {
126 /* Int select from 8 to 15 */
127 int_selection = ((sw_config->pad_conf0 >> 28) & 0xf);
Angel Ponsaee7ab22020-03-19 00:31:58 +0100128
Lee Leahy32471722015-04-20 15:20:28 -0700129 if (sw_config->gpe == SMI) {
Angel Ponsaee7ab22020-03-19 00:31:58 +0100130 /* Set the corresponding bits (10) as per the interrupt line */
131 route_reg |= (1 << (int_selection * 2));
132 route_reg &= ~(1 << (int_selection * 2 + 1));
133 alt_gpio_smi |= (1 << (int_selection + 16));
134
Lee Leahy32471722015-04-20 15:20:28 -0700135 } else if (sw_config->gpe == SCI) {
Angel Ponsaee7ab22020-03-19 00:31:58 +0100136 /* Set the corresponding bits as per the interrupt line */
Lee Leahy32471722015-04-20 15:20:28 -0700137 route_reg |= (1 << ((int_selection * 2) + 1));
Angel Ponsaee7ab22020-03-19 00:31:58 +0100138
139 /* Reset the bit */
Lee Leahy32471722015-04-20 15:20:28 -0700140 route_reg &= ~(1 << (int_selection * 2));
Angel Ponsaee7ab22020-03-19 00:31:58 +0100141 gpe0a_en |= (1 << (int_selection + 16));
Lee Leahy32471722015-04-20 15:20:28 -0700142 }
Lee Leahy77ff0b12015-05-05 15:07:29 -0700143 }
144 }
Lee Leahy32471722015-04-20 15:20:28 -0700145
Angel Ponsaee7ab22020-03-19 00:31:58 +0100146 /* Enable gpe bits in GPE0A_EN_REG */
Lee Leahy32471722015-04-20 15:20:28 -0700147 outl(gpe0a_en, ACPI_BASE_ADDRESS + GPE0A_EN_REG);
148
149#ifdef GPIO_DEBUG
150 printk(BIOS_DEBUG, "gpio_rout = %x alt_gpio_smi = %x gpe0a_en = %x\n",
151 route_reg, alt_gpio_smi, gpe0a_en);
152#endif
Angel Ponsaee7ab22020-03-19 00:31:58 +0100153 /* Save as an SMM param */
Kyösti Mälkkifaf20d32019-08-14 05:41:41 +0300154 smm_southcluster_save_param(SMM_SAVE_PARAM_GPIO_ROUTE, route_reg);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700155}
156
Angel Ponsaee7ab22020-03-19 00:31:58 +0100157static void setup_gpios(const struct soc_gpio_map *gpios, const struct gpio_bank *community)
Lee Leahy32471722015-04-20 15:20:28 -0700158{
159 const struct soc_gpio_map *config;
160 int gpio = 0;
161 u32 reg, family, internal_pad_num;
162 u32 mmio_addr, int_selection;
163 u32 gpio_wake0 = 0;
164 u32 gpio_wake1 = 0;
165 u32 gpio_int_mask = 0;
166
167 if (!gpios)
168 return;
Angel Ponsaee7ab22020-03-19 00:31:58 +0100169
170 for (config = gpios; config->pad_conf0 != GPIO_LIST_END; config++, gpio++) {
Lee Leahy32471722015-04-20 15:20:28 -0700171 if (gpio > community->gpio_count)
172 break;
173
174 /* Pad configuration registers */
175 family = community->gpio_to_pad[gpio] / MAX_FAMILY_PAD_GPIO_NO;
Angel Ponsaee7ab22020-03-19 00:31:58 +0100176 internal_pad_num = community->gpio_to_pad[gpio] % MAX_FAMILY_PAD_GPIO_NO;
Lee Leahy32471722015-04-20 15:20:28 -0700177
178 /*
Angel Ponsaee7ab22020-03-19 00:31:58 +0100179 * Calculate the MMIO Address for GPIO pin control register pointed by index.
180 * REG = IOBASE + COMMUNITY_BASE + 0x4400 + (0x400 * FAMILY_NUM) + (8 * PAD_NUM)
Lee Leahy32471722015-04-20 15:20:28 -0700181 */
Angel Ponsaee7ab22020-03-19 00:31:58 +0100182 mmio_addr = FAMILY_PAD_REGS_OFF + (FAMILY_PAD_REGS_SIZE * family) +
183 (GPIO_REGS_SIZE * internal_pad_num);
Lee Leahy32471722015-04-20 15:20:28 -0700184
185 reg = community->pad_base + mmio_addr;
186
Angel Ponsaee7ab22020-03-19 00:31:58 +0100187 /* Get int selection value */
Lee Leahy32471722015-04-20 15:20:28 -0700188 int_selection = ((config->pad_conf0 >> 28) & 0xf);
189
Angel Ponsaee7ab22020-03-19 00:31:58 +0100190 /* Get int mask register value */
Lee Leahy32471722015-04-20 15:20:28 -0700191 gpio_int_mask |= (config->int_mask << int_selection);
192
Angel Ponsaee7ab22020-03-19 00:31:58 +0100193 /* Wake capable programming, some communities have 2 wake regs */
Lee Leahy32471722015-04-20 15:20:28 -0700194 if (gpio > 31)
195 gpio_wake1 |= config->wake_mask << (gpio % 32);
196 else
197 gpio_wake0 |= config->wake_mask << gpio;
198
199 if (!config->skip_config) {
Lee Leahy77ff0b12015-05-05 15:07:29 -0700200#ifdef GPIO_DEBUG
Lee Leahy32471722015-04-20 15:20:28 -0700201 printk(BIOS_DEBUG,
202 "Write Pad: Base(%x) - conf0 = %x conf1= %x gpio #- %d pad # = %d\n",
203 reg, config->pad_conf0, config->pad_conf1,
204 community->gpio_to_pad[gpio], gpio);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700205#endif
Angel Ponsaee7ab22020-03-19 00:31:58 +0100206 /* Write pad configurations to conf0 and conf1 register */
207 write32((void *)(reg + PAD_CONF0_REG), config->pad_conf0);
208 write32((void *)(reg + PAD_CONF1_REG), config->pad_conf1);
Lee Leahy32471722015-04-20 15:20:28 -0700209 }
Lee Leahy77ff0b12015-05-05 15:07:29 -0700210 }
Lee Leahy32471722015-04-20 15:20:28 -0700211
212#ifdef GPIO_DEBUG
Angel Ponsaee7ab22020-03-19 00:31:58 +0100213 printk(BIOS_DEBUG, "gpio_wake_mask0 = %x gpio_wake_mask1 = %x gpio_int_mask = %x\n",
Lee Leahy32471722015-04-20 15:20:28 -0700214 gpio_wake0, gpio_wake1, gpio_int_mask);
215#endif
216
217 /* Wake */
Angel Ponsaee7ab22020-03-19 00:31:58 +0100218 write32((void *)(community->pad_base + GPIO_WAKE_MASK_REG0), gpio_wake0);
Lee Leahy32471722015-04-20 15:20:28 -0700219
Angel Ponsaee7ab22020-03-19 00:31:58 +0100220 /* Wake mask config for communities with 2 regs */
Lee Leahy32471722015-04-20 15:20:28 -0700221 if (community->gpio_count > 32)
Angel Ponsaee7ab22020-03-19 00:31:58 +0100222 write32((void *)(community->pad_base + GPIO_WAKE_MASK_REG1), gpio_wake1);
Lee Leahy32471722015-04-20 15:20:28 -0700223
224 /* Interrupt */
Angel Ponsaee7ab22020-03-19 00:31:58 +0100225 write32((void *)(community->pad_base + GPIO_INTERRUPT_MASK), gpio_int_mask);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700226}
227
228void setup_soc_gpios(struct soc_gpio_config *config, u8 enable_xdp_tap)
229{
Lee Leahy32471722015-04-20 15:20:28 -0700230 if (config) {
231
232 /*
Angel Ponsaee7ab22020-03-19 00:31:58 +0100233 * Write the default value 0xffffff to the SW write_access_policy_interrupt_reg
234 * to allow the SW interrupt mask register to be set
Lee Leahy32471722015-04-20 15:20:28 -0700235 */
Angel Ponsaee7ab22020-03-19 00:31:58 +0100236 write32((void *)(COMMUNITY_GPSOUTHWEST_BASE + 0x108), 0xffffffff);
Lee Leahy32471722015-04-20 15:20:28 -0700237
238 printk(BIOS_DEBUG, "north\n");
239 setup_gpios(config->north, &gpnorth_community);
240
241 printk(BIOS_DEBUG, "southwest\n");
242 setup_gpios(config->southwest, &gpsouthwest_community);
243
244 printk(BIOS_DEBUG, "southeast\n");
245 setup_gpios(config->southeast, &gpsoutheast_community);
246
247 printk(BIOS_DEBUG, "east\n");
248 setup_gpios(config->east, &gpeast_community);
249
250 printk(BIOS_DEBUG, "Routing SW and N gpios\n");
251 setup_gpio_route(config->southwest, config->north);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700252 }
253
Lee Leahy32471722015-04-20 15:20:28 -0700254 /*
Angel Ponsaee7ab22020-03-19 00:31:58 +0100255 * Set on die termination feature with pull up value
256 * and drive the pad high for TAP_TDO and TAP_TMS
Lee Leahy77ff0b12015-05-05 15:07:29 -0700257 */
Lee Leahy32471722015-04-20 15:20:28 -0700258 if (!enable_xdp_tap)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700259 printk(BIOS_DEBUG, "Tri-state TDO and TMS\n");
Lee Leahy77ff0b12015-05-05 15:07:29 -0700260}
261
Aaron Durbin64031672018-04-21 14:45:32 -0600262__weak struct soc_gpio_config *mainboard_get_gpios(void)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700263{
264 printk(BIOS_DEBUG, "Default/empty GPIO config\n");
265 return NULL;
266}