coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
gpio_baseboard_trembyle.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include <acpi/acpi.h>
4 #include <baseboard/variants.h>
5 #include <delay.h>
7 #include <gpio.h>
8 #include <soc/gpio.h>
9 #include <soc/smi.h>
10 #include <variant/gpio.h>
11 
12 static const struct soc_amd_gpio gpio_set_stage_ram[] = {
13  /* PWR_BTN_L */
14  PAD_NF(GPIO_0, PWR_BTN_L, PULL_NONE),
15  /* SYS_RESET_L */
16  PAD_NF(GPIO_1, SYS_RESET_L, PULL_NONE),
17  /* WIFI_PCIE_WAKE_ODL */
18  PAD_NF_SCI(GPIO_2, WAKE_L, PULL_NONE, EDGE_LOW),
19  /* H1_FCH_INT_ODL */
20  PAD_INT(GPIO_3, PULL_NONE, EDGE_LOW, STATUS_DELIVERY),
21  /* PEN_DETECT_ODL */
22  PAD_WAKE(GPIO_4, PULL_NONE, EDGE_HIGH, S3),
23  /* PEN_POWER_EN - Enabled*/
24  PAD_GPO(GPIO_5, HIGH),
25  /* FPMCU_INT_L */
26  PAD_SCI(GPIO_6, PULL_NONE, LEVEL_LOW),
27  /* I2S_SDIN */
28  PAD_NF(GPIO_7, ACP_I2S_SDIN, PULL_NONE),
29  /* I2S_LRCLK - Bit banged in depthcharge */
30  PAD_NF(GPIO_8, ACP_I2S_LRCLK, PULL_NONE),
31  /* TOUCHPAD_INT_ODL */
32  PAD_SCI(GPIO_9, PULL_NONE, LEVEL_LOW),
33  /* S0iX SLP - goes to EC & FPMCU */
34  PAD_GPO(GPIO_10, HIGH),
35  /* USI_INT_ODL */
37  /* EN_PWR_TOUCHPAD_PS2 */
38  PAD_GPO(GPIO_13, HIGH),
39  /* BT_DISABLE */
40  PAD_GPO(GPIO_14, LOW),
41  /* GPIO_15: Not available */
42  /* USB_OC0_L - USB C0 + USB A0 */
43  PAD_NF(GPIO_16, USB_OC0_L, PULL_NONE),
44  /* USB_OC1_L - USB C1 + USB A1 */
45  PAD_NF(GPIO_17, USB_OC1_L, PULL_NONE),
46  /* WIFI_DISABLE */
47  PAD_GPO(GPIO_18, LOW),
48  /* I2C3_SCL - H1 */
49  PAD_NF(GPIO_19, I2C3_SCL, PULL_NONE),
50  /* I2C3_SDA - H1 */
51  PAD_NF(GPIO_20, I2C3_SDA, PULL_NONE),
52  /* EMMC_CMD */
53  PAD_NF(GPIO_21, EMMC_CMD, PULL_NONE),
54  /* EC_FCH_SCI_ODL */
55  PAD_SCI(GPIO_22, PULL_NONE, EDGE_LOW),
56  /* AC_PRES */
57  PAD_NF(GPIO_23, AC_PRES, PULL_UP),
58  /* EC_FCH_WAKE_L */
59  PAD_SCI(GPIO_24, PULL_NONE, EDGE_LOW),
60  /* GPIO_25: Not available */
61  /* PCIE_RST0_L - Fixed timings */
62  PAD_NF(GPIO_26, PCIE_RST_L, PULL_NONE),
63  /* PCIE_RST1_L (unused) */
64  PAD_NC(GPIO_27),
65  /* GPIO_28: Not available */
66  /* GPIO_29: HP_INT_ODL */
68  /* FCH_ESPI_EC_CS_L */
69  PAD_NF(GPIO_30, ESPI_CS_L, PULL_NONE),
70  /* EC_AP_INT_ODL (Sensor Framesync) */
72  /* GPIO_33 - GPIO_39: Not available */
73  /* NVME_AUX_RESET_L */
74  PAD_GPO(GPIO_40, HIGH),
75  /* GPIO_41: Not available */
76  /* GPIO_42: Handled in bootblock for wifi power/reset control. */
77  /* GPIO_43 - GPIO_66: Not available */
78  /* DMIC SEL */
79  /*
80  * Make sure Ext ROM Sharing is disabled before using this GPIO. Otherwise SPI flash
81  * access will be very slow.
82  */
83  PAD_GPO(GPIO_67, LOW), // Select Camera 1 Dmic
84  /* EMMC_RESET_L */
85  PAD_GPO(GPIO_68, HIGH),
86  /* FPMCU_BOOT0 */
87  PAD_GPO(GPIO_69, LOW),
88  /* EMMC_CLK */
89  PAD_NF(GPIO_70, EMMC_CLK, PULL_NONE),
90  /* GPIO_71 - GPIO_73: Not available */
91  /* EMMC_DATA4 */
92  PAD_NF(GPIO_74, EMMC_DATA4, PULL_NONE),
93  /* EMMC_DATA6 */
94  PAD_NF(GPIO_75, EMMC_DATA6, PULL_NONE),
95  /* EN_PWR_CAMERA */
96  PAD_GPO(GPIO_76, HIGH),
97  /* GPIO_77 - GPIO_83: Not available */
98  /* RAM_ID_4 */
100  /* APU_EDP_BL_DISABLE */
101  PAD_GPO(GPIO_85, LOW),
102  /* WIFI_AUX_RESET_L */
103  PAD_GPO(GPIO_86, HIGH),
104  /* EMMC_DATA7 */
105  PAD_NF(GPIO_87, EMMC_DATA7, PULL_NONE),
106  /* EMMC_DATA5 */
107  PAD_NF(GPIO_88, EMMC_DATA5, PULL_NONE),
108  /* GPIO_89 - unused */
109  PAD_NC(GPIO_89),
110  /* EN_PWR_TOUCHSCREEN */
111  PAD_GPO(GPIO_90, LOW),
112  /* EN_SPKR */
113  PAD_GPO(GPIO_91, LOW),
114  /* CLK_REQ0_L - WIFI */
115  PAD_NF(GPIO_92, CLK_REQ0_L, PULL_NONE),
116  /* GPIO_93 - GPIO_103: Not available */
117  /* EMMC_DATA0 */
118  PAD_NF(GPIO_104, EMMC_DATA0, PULL_NONE),
119  /* EMMC_DATA1 */
120  PAD_NF(GPIO_105, EMMC_DATA1, PULL_NONE),
121  /* EMMC_DATA2 */
122  PAD_NF(GPIO_106, EMMC_DATA2, PULL_NONE),
123  /* EMMC_DATA3 */
124  PAD_NF(GPIO_107, EMMC_DATA3, PULL_NONE),
125  /* ESPI_ALERT_L */
126  PAD_NF(GPIO_108, ESPI_ALERT_L, PULL_UP),
127  /* EMMC_DS */
128  PAD_NF(GPIO_109, EMMC_DS, PULL_NONE),
129  /* GPIO_110 - GPIO112: Not available */
130  /* I2C2_SCL - USI/Touchpad */
131  PAD_NF(GPIO_113, I2C2_SCL, PULL_NONE),
132  /* I2C2_SDA - USI/Touchpad */
133  PAD_NF(GPIO_114, I2C2_SDA, PULL_NONE),
134  /* CLK_REQ1_L - SD Card */
135  PAD_NF(GPIO_115, CLK_REQ1_L, PULL_NONE),
136  /* RAM_ID_3 */
138  /* GPIO_117 - GPIO_119: Not available */
139  /* RAM_ID_1 */
141  /* RAM_ID_0 */
143  /* GPIO_122 - GPIO_128: Not available */
144  /* KBRST_L */
145  PAD_NF(GPIO_129, KBRST_L, PULL_NONE),
146  /* EC_IN_RW_OD */
148  /* RAM_ID_2 */
150  /* CLK_REQ4_L - SSD */
151  PAD_NF(GPIO_132, CLK_REQ4_L, PULL_NONE),
152  /* GPIO_133 - GPIO_134: Not available */
153  /* DEV_BEEP_CODEC_IN (Dev beep Data out) */
155  /* UART0_RXD - DEBUG */
156  PAD_NF(GPIO_136, UART0_RXD, PULL_NONE),
157  /* BIOS_FLASH_WP_ODL */
159  /* UART0_TXD - DEBUG */
160  PAD_NF(GPIO_138, UART0_TXD, PULL_NONE),
161  /* DEV_BEEP_BCLK */
163  /* USI_RESET_L */
164  PAD_GPO(GPIO_140, LOW),
165  /* UART1_RXD - FPMCU */
166  PAD_NF(GPIO_141, UART1_RXD, PULL_NONE),
167  /* SD_AUX_RESET_L */
168  PAD_GPO(GPIO_142, HIGH),
169  /* UART1_TXD - FPMCU */
170  PAD_NF(GPIO_143, UART1_TXD, PULL_NONE),
171  /* USI_REPORT_EN */
172  PAD_GPO(GPIO_144, LOW),
173 };
174 
175 const __weak
177 {
179  return gpio_set_stage_ram;
180 }
181 
183 {
184  /*
185  * Configure WiFi GPIOs such that:
186  * - WIFI_AUX_RESET_L is configured first to assert PERST# to WiFi device.
187  * - Enable power to WiFi using EN_PWR_WIFI_L.
188  * - Wait for >50ms after power to WiFi is enabled. (Time between bootblock & ramstage)
189  * - WIFI_AUX_RESET_L gets deasserted later in mainboard_configure_gpios in ramstage
190  */
191  static const struct soc_amd_gpio v3_wifi_table[] = {
192  /* WIFI_AUX_RESET_L */
193  PAD_GPO(GPIO_86, LOW),
194  /* EN_PWR_WIFI_L */
195  PAD_GPO(GPIO_42, LOW),
196  };
197  gpio_configure_pads(v3_wifi_table, ARRAY_SIZE(v3_wifi_table));
198 
199 }
200 
202 {
203  /*
204  * When GPIO_42 is configured as active high for enabling WiFi power, WIFI_AUX_RESET_L
205  * gets pulled high because of external PU to PP3300_WIFI. Thus, EN_PWR_WIFI needs to be
206  * set low before driving it high to trigger a WiFi power cycle to meet PCIe
207  * requirements. Thus, configura GPIOs such that:
208  * - WIFI_AUX_RESET_L is configured first to assert PERST# to WiFi device
209  * - Disable power to WiFi.
210  * - Wait 10ms for WiFi power to go low.
211  * - Enable power to WiFi using EN_PWR_WIFI.
212  * - Deassert WIFI_AUX_RESET_L.
213  */
214  static const struct soc_amd_gpio v3_wifi_table[] = {
215  /* WIFI_AUX_RESET_L */
216  PAD_GPO(GPIO_86, LOW),
217  /* EN_PWR_WIFI */
218  PAD_GPO(GPIO_42, LOW),
219  };
220  gpio_configure_pads(v3_wifi_table, ARRAY_SIZE(v3_wifi_table));
221 
222  mdelay(10);
223  gpio_set(GPIO_42, 1);
224  mdelay(50);
225  gpio_set(GPIO_86, 1);
226 }
227 
229 {
232  else
234 }
235 
237 {
238  /*
239  * Configure WiFi GPIOs such that:
240  * - WIFI_AUX_RESET_L is configured first to assert PERST# to WiFi device.
241  * - Disable power to WiFi since GPIO_29 goes high on PWRGOOD but has a glitch on RESET#
242  * deassertion causing WiFi to enter a bad state.
243  * - Wait 10ms for WiFi power to go low.
244  * - Enable power to WiFi using EN_PWR_WIFI.
245  * - Wait for 50ms after power to WiFi is enabled.
246  * - Deassert WIFI_AUX_RESET_L.
247  */
248  static const struct soc_amd_gpio pre_v3_wifi_table[] = {
249  /* WIFI_AUX_RESET_L */
250  PAD_GPO(GPIO_42, LOW),
251  /* EN_PWR_WIFI */
252  PAD_GPO(GPIO_29, LOW),
253  };
254  gpio_configure_pads(pre_v3_wifi_table, ARRAY_SIZE(pre_v3_wifi_table));
255 
256  mdelay(10);
257  gpio_set(GPIO_29, 1);
258  mdelay(50);
259  gpio_set(GPIO_42, 1);
260 }
261 
263 {
264  static const struct soc_amd_gpio pcie_gpio_table[] = {
265  /* NVME_AUX_RESET_L */
266  PAD_GPO(GPIO_40, HIGH),
267  /* CLK_REQ0_L - WIFI */
268  PAD_NF(GPIO_92, CLK_REQ0_L, PULL_NONE),
269  /* CLK_REQ1_L - SD Card */
270  PAD_NF(GPIO_115, CLK_REQ1_L, PULL_NONE),
271  /* CLK_REQ4_L - SSD */
272  PAD_NF(GPIO_132, CLK_REQ4_L, PULL_NONE),
273  /* SD_AUX_RESET_L */
274  PAD_GPO(GPIO_142, HIGH),
275  };
276 
278 
281  else
283 }
284 
285 __weak void finalize_gpios(int slp_typ)
286 {
287  if (variant_has_fingerprint() && slp_typ != ACPI_S3) {
288 
289  if (fpmcu_needs_delay())
290  mdelay(550);
291 
292  /*
293  * Enable the FPMCU by enabling EN_PWR_FP, then bringing it out
294  * of reset by setting FPMCU_RST_L high 3ms later.
295  */
296  gpio_set(GPIO_32, 1);
297  mdelay(3);
298  gpio_set(GPIO_11, 1);
299  }
300 }
301 
302 static const struct soc_amd_gpio gpio_fingerprint_bootblock_table[] = {
303  /* FPMCU_RST_L */
304  PAD_GPO(GPIO_11, LOW),
305  /* EN_PWR_FP */
306  PAD_GPO(GPIO_32, LOW),
307 };
308 
309 static const struct soc_amd_gpio gpio_no_fingerprint_bootblock_table[] = {
310  /* FPMCU_RST_L */
311  PAD_NC(GPIO_11),
312  /* EN_PWR_FP */
313  PAD_NC(GPIO_32),
314 };
315 
316 const __weak struct soc_amd_gpio *variant_bootblock_gpio_table(size_t *size, int slp_typ)
317 {
318  if (variant_has_fingerprint()) {
319  if (slp_typ == ACPI_S3)
320  return NULL;
321 
324  }
325 
328 }
329 
330 static const struct soc_amd_gpio gpio_sleep_table[] = {
331  /* S0iX SLP */
332  PAD_GPO(GPIO_10, LOW),
333  /* NVME_AUX_RESET_L */
334  PAD_GPO(GPIO_40, LOW),
335  /* EN_PWR_CAMERA */
336  PAD_GPO(GPIO_76, LOW),
337 };
338 
339 static const struct soc_amd_gpio gpio_fp_shutdown_table[] = {
340  /* NVME_AUX_RESET_L */
341  PAD_GPO(GPIO_40, LOW),
342  /* EN_PWR_CAMERA */
343  PAD_GPO(GPIO_76, LOW),
344 
345  /* FPMCU_RST_L */
346  PAD_GPO(GPIO_11, LOW),
347  /* EN_PWR_FP */
348  PAD_GPO(GPIO_32, LOW),
349 };
350 
351 const __weak struct soc_amd_gpio *variant_sleep_gpio_table(size_t *size, int slp_typ)
352 {
353  if (slp_typ == SLP_TYP_S5) {
355  return gpio_fp_shutdown_table;
356  }
357 
358  *size = ARRAY_SIZE(gpio_sleep_table);
359  return gpio_sleep_table;
360 }
361 
362 static const struct soc_amd_gpio espi_gpio_table[] = {
363  /* PCIE_RST0_L - Fixed timings */
364  PAD_NF(GPIO_26, PCIE_RST_L, PULL_NONE),
365  /* FCH_ESPI_EC_CS_L */
366  PAD_NF(GPIO_30, ESPI_CS_L, PULL_NONE),
367  /* ESPI_ALERT_L */
368  PAD_NF(GPIO_108, ESPI_ALERT_L, PULL_NONE),
369 };
370 
371 const struct soc_amd_gpio *variant_espi_gpio_table(size_t *size)
372 {
373  *size = ARRAY_SIZE(espi_gpio_table);
374  return espi_gpio_table;
375 }
376 
377 static const struct soc_amd_gpio tpm_gpio_table[] = {
378  /* H1_FCH_INT_ODL */
379  PAD_INT(GPIO_3, PULL_NONE, EDGE_LOW, STATUS),
380  /* I2C3_SCL - H1 */
381  PAD_NF(GPIO_19, I2C3_SCL, PULL_NONE),
382  /* I2C3_SDA - H1 */
383  PAD_NF(GPIO_20, I2C3_SDA, PULL_NONE),
384  /* EC_IN_RW_OD */
386 };
387 
388 const struct soc_amd_gpio *variant_tpm_gpio_table(size_t *size)
389 {
390  *size = ARRAY_SIZE(tpm_gpio_table);
391  return tpm_gpio_table;
392 }
393 
394 static const struct soc_amd_gpio early_gpio_table[] = {
395  /* UART0_RXD - DEBUG */
396  PAD_NF(GPIO_136, UART0_RXD, PULL_NONE),
397  /* UART0_TXD - DEBUG */
398  PAD_NF(GPIO_138, UART0_TXD, PULL_NONE),
399 };
400 
401 const struct soc_amd_gpio *variant_early_gpio_table(size_t *size)
402 {
403  *size = ARRAY_SIZE(early_gpio_table);
404  return early_gpio_table;
405 }
#define GPIO_10
Definition: gpio_ftns.h:12
#define GPIO_18
Definition: gpio_ftns.h:17
#define GPIO_17
Definition: gpio_ftns.h:16
#define GPIO_16
Definition: gpio_ftns.h:15
#define GPIO_11
Definition: gpio_ftns.h:13
#define GPIO_22
Definition: gpio_ftns.h:14
#define GPIO_32
Definition: gpio_ftns.h:15
#define GPIO_68
Definition: gpio_ftns.h:26
#define ARRAY_SIZE(a)
Definition: helpers.h:12
void mdelay(unsigned int msecs)
Definition: delay.c:2
static const struct soc_amd_gpio tpm_gpio_table[]
__weak void finalize_gpios(int slp_typ)
const __weak struct soc_amd_gpio * variant_bootblock_gpio_table(size_t *size, int slp_typ)
const __weak struct soc_amd_gpio * variant_base_gpio_table(size_t *size)
static const struct soc_amd_gpio early_gpio_table[]
static const struct soc_amd_gpio gpio_no_fingerprint_bootblock_table[]
const struct soc_amd_gpio * variant_tpm_gpio_table(size_t *size)
const struct soc_amd_gpio * variant_early_gpio_table(size_t *size)
static const struct soc_amd_gpio gpio_fp_shutdown_table[]
static const struct soc_amd_gpio gpio_sleep_table[]
const struct soc_amd_gpio * variant_espi_gpio_table(size_t *size)
const __weak struct soc_amd_gpio * variant_sleep_gpio_table(size_t *size, int slp_typ)
static void wifi_power_reset_configure_active_low_power(void)
static void wifi_power_reset_configure_v3(void)
static void wifi_power_reset_configure_active_high_power(void)
static const struct soc_amd_gpio espi_gpio_table[]
__weak void variant_pcie_gpio_configure(void)
static const struct soc_amd_gpio gpio_set_stage_ram[]
static void wifi_power_reset_configure_pre_v3(void)
static const struct soc_amd_gpio gpio_fingerprint_bootblock_table[]
#define PULL_UP
Definition: buildOpts.c:70
#define PULL_NONE
Definition: buildOpts.c:72
@ ACPI_S3
Definition: acpi.h:1383
void gpio_set(gpio_t gpio, int value)
Definition: gpio.c:174
#define SLP_TYP_S5
Definition: pmc.h:69
static const struct soc_amd_gpio pcie_gpio_table[]
Definition: gpio.c:276
@ S3
Definition: smihandler.c:21
const struct smm_save_state_ops *legacy_ops __weak
Definition: save_state.c:8
#define GPIO_91
Definition: gpio.h:67
#define GPIO_30
Definition: gpio.h:46
#define GPIO_121
Definition: gpio.h:80
#define GPIO_76
Definition: gpio.h:59
#define GPIO_27
Definition: gpio.h:44
#define GPIO_0
Definition: gpio.h:21
#define GPIO_7
Definition: gpio.h:28
#define GPIO_90
Definition: gpio.h:66
#define GPIO_143
Definition: gpio.h:90
#define GPIO_89
Definition: gpio.h:65
#define GPIO_69
Definition: gpio.h:55
#define GPIO_12
Definition: gpio.h:33
#define GPIO_1
Definition: gpio.h:22
#define GPIO_5
Definition: gpio.h:26
#define GPIO_113
Definition: gpio.h:75
#define GPIO_104
Definition: gpio.h:69
#define GPIO_130
Definition: gpio.h:84
#define GPIO_88
Definition: gpio.h:64
#define GPIO_84
Definition: gpio.h:60
#define GPIO_105
Definition: gpio.h:70
#define GPIO_8
Definition: gpio.h:29
#define GPIO_141
Definition: gpio.h:88
#define GPIO_67
Definition: gpio.h:53
#define GPIO_24
Definition: gpio.h:42
#define GPIO_132
Definition: gpio.h:86
#define GPIO_4
Definition: gpio.h:25
#define GPIO_107
Definition: gpio.h:72
#define GPIO_129
Definition: gpio.h:83
#define GPIO_140
Definition: gpio.h:87
#define GPIO_20
Definition: gpio.h:38
#define GPIO_92
Definition: gpio.h:68
#define GPIO_19
Definition: gpio.h:37
#define GPIO_70
Definition: gpio.h:56
#define GPIO_116
Definition: gpio.h:78
#define GPIO_115
Definition: gpio.h:77
#define GPIO_108
Definition: gpio.h:73
#define GPIO_109
Definition: gpio.h:74
#define GPIO_31
Definition: gpio.h:47
#define GPIO_9
Definition: gpio.h:30
#define GPIO_26
Definition: gpio.h:43
#define GPIO_131
Definition: gpio.h:85
#define GPIO_29
Definition: gpio.h:45
#define GPIO_75
Definition: gpio.h:58
#define GPIO_86
Definition: gpio.h:62
#define GPIO_87
Definition: gpio.h:63
#define GPIO_3
Definition: gpio.h:24
#define GPIO_142
Definition: gpio.h:89
#define GPIO_144
Definition: gpio.h:91
#define GPIO_120
Definition: gpio.h:79
#define GPIO_106
Definition: gpio.h:71
#define GPIO_85
Definition: gpio.h:61
#define GPIO_2
Definition: gpio.h:23
#define GPIO_21
Definition: gpio.h:39
#define GPIO_40
Definition: gpio.h:49
#define GPIO_42
Definition: gpio.h:50
#define GPIO_114
Definition: gpio.h:76
#define GPIO_23
Definition: gpio.h:41
#define GPIO_74
Definition: gpio.h:57
#define GPIO_6
Definition: gpio.h:27
void gpio_configure_pads(const struct soc_amd_gpio *gpio_list_ptr, size_t size)
program a particular set of GPIO
Definition: gpio.c:307
#define PAD_WAKE(pin, pull, trigger, type)
Definition: gpio_defs.h:247
#define PAD_SCI(pin, pull, trigger)
Definition: gpio_defs.h:229
#define PAD_NC(pin)
Definition: gpio_defs.h:263
#define PAD_NF_SCI(pin, func, pull, trigger)
Definition: gpio_defs.h:241
#define PAD_GPO(pin, direction)
Definition: gpio_defs.h:220
#define PAD_NF(pin, func, pull)
Definition: gpio_defs.h:208
#define PAD_INT(pin, pull, trigger, action)
Definition: gpio_defs.h:224
#define PAD_GPI(pin, pull)
Definition: gpio_defs.h:216
#define GPIO_139
Definition: gpio.h:94
#define GPIO_14
Definition: gpio.h:35
#define GPIO_136
Definition: gpio.h:91
#define GPIO_137
Definition: gpio.h:92
#define GPIO_138
Definition: gpio.h:93
#define GPIO_13
Definition: gpio.h:34
#define GPIO_135
Definition: gpio.h:90
#define NULL
Definition: stddef.h:19
bool variant_uses_v3_schematics(void)
Definition: helpers.c:124
bool variant_has_active_low_wifi_power(void)
Definition: helpers.c:165
bool fpmcu_needs_delay(void)
Definition: helpers.c:194
bool variant_has_fingerprint(void)
Definition: helpers.c:186