summaryrefslogtreecommitdiff
path: root/src/mainboard/google/guybrush/variants/baseboard/gpio.c
blob: c45d3a78ce69ba41128a6cffd933a35adec599d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
/* SPDX-License-Identifier: GPL-2.0-or-later */

#include <acpi/acpi.h>
#include <baseboard/gpio.h>
#include <baseboard/variants.h>
#include <commonlib/helpers.h>
#include <delay.h>
#include <gpio.h>
#include <soc/gpio.h>

/* GPIO configuration in ramstage*/
/* Please make sure that *ALL* GPIOs are configured in this table */
static const struct soc_amd_gpio base_gpio_table[] = {
	/* PWR_BTN_L */
	PAD_NF(GPIO_0, PWR_BTN_L, PULL_NONE),
	/* SYS_RESET_L */
	PAD_NF(GPIO_1, SYS_RESET_L, PULL_NONE),
	/* WAKE_L */
	PAD_NF_SCI(GPIO_2, WAKE_L, PULL_NONE, EDGE_LOW),
	/* GSC_SOC_INT_L */
	PAD_INT(GPIO_3, PULL_NONE, EDGE_LOW, STATUS_DELIVERY),
	/* SOC_PEN_DETECT_ODL */
	PAD_WAKE(GPIO_4, PULL_NONE, EDGE_HIGH, S0i3),
	/* SD_AUX_RESET_L  */
	PAD_GPO(GPIO_5, HIGH),
	/* EN_PP3300_WLAN */
	PAD_GPO(GPIO_6, HIGH),
	/* EN_PP3300_TCHPAD */
	PAD_GPO(GPIO_7, HIGH),
	/* EN_PWR_WWAN_X */
	PAD_GPO(GPIO_8, HIGH),
	/* SOC_TCHPAD_INT_ODL */
	PAD_SCI(GPIO_9, PULL_NONE, EDGE_HIGH),
	/* S0A3 */
	PAD_NF(GPIO_10, S0A3, PULL_NONE),
	/* SOC_FP_RST_L - Brought high in finalize */
	PAD_GPO(GPIO_11, LOW),
	/* SLP_S3_GATED */
	PAD_GPO(GPIO_12, LOW),
	/* GPIO_13 - GPIO_15: Not available */
	/* USB_OC0_L */
	PAD_NF(GPIO_16, USB_OC0_L, PULL_NONE),
	/* SOC_SAR_INT_L */
	PAD_SCI(GPIO_17, PULL_NONE, EDGE_LOW),
	/* WWAN_AUX_RESET_L */
	PAD_GPO(GPIO_18, HIGH),
	/* I2C3_SCL */
	PAD_NF(GPIO_19, I2C3_SCL, PULL_NONE),
	/* I2C3_SDA */
	PAD_NF(GPIO_20, I2C3_SDA, PULL_NONE),
	/* SOC_FP_INT_L */
	PAD_SCI(GPIO_21, PULL_NONE, EDGE_LOW),
	/* EC_SOC_WAKE_ODL */
	PAD_SCI(GPIO_22, PULL_NONE, EDGE_LOW),
	/* AC_PRES */
	PAD_NF(GPIO_23, AC_PRES, PULL_UP),
	/* WWAN_RST_L */
	PAD_GPO(GPIO_24, HIGH),
	/* GPIO_25: Not available */
	/* PCIE_RST0_L */
	PAD_NFO(GPIO_26, PCIE_RST_L, HIGH),
	/* PCIE_RST1_L */
	PAD_NFO(GPIO_27, PCIE_RST1_L, HIGH),
	/* GPIO_28: Not available */
	/* WLAN_AUX_RESET (Active HIGH)*/
	PAD_GPO(GPIO_29, LOW),
	/* ESPI_CS_L */
	PAD_NF(GPIO_30, ESPI_CS_L, PULL_NONE),
	/* EN_SPKR */
	PAD_GPO(GPIO_31, HIGH),
	/* EN_PWR_FP */
	PAD_GPO(GPIO_32, HIGH),
	/* GPIO_33 - GPIO_39: Not available */
	/* SSD_AUX_RESET_L */
	PAD_GPO(GPIO_40, HIGH),
	/* GPIO_41: Not available */
	/* WWAN_DPR_SAR_ODL */
	PAD_GPO(GPIO_42, LOW),
	/* GPIO_43 - GPIO_66: Not available */
	/* SOC_BIOS_WP_L */
	PAD_GPI(GPIO_67, PULL_NONE),
	/* EN_PP3300_TCHSCR */
	PAD_GPO(GPIO_68, HIGH),
	/* Unused */
	PAD_NC(GPIO_69),
	/* Unused TP27  */
	PAD_NC(GPIO_70),
	/* GPIO_71 - GPIO_73: Not available */
	/* Unused TP49 */
	PAD_NC(GPIO_74),
	/* RAM_ID_2 / DEV_BEEP_LRCLK */
	PAD_GPI(GPIO_75, PULL_NONE),
	/* EN_PP3300_CAM */
	PAD_GPO(GPIO_76, HIGH),
	/* GPIO_77 - GPIO_83: Not available */
	/* EC_SOC_INT_ODL */
	PAD_GPI(GPIO_84, PULL_NONE),
	/* WWAN_DISABLE */
	PAD_GPO(GPIO_85, LOW),
	/* ESPI_SOC_CLK */
	PAD_NF(GPIO_86, SPI_CLK, PULL_NONE),
	/* RAM_ID_1 / DEV_BEEP_DATA */
	PAD_GPI(GPIO_87, PULL_NONE),
	/* RAM_ID_3 / DEV_BEEP_BCLK */
	PAD_GPI(GPIO_88, PULL_NONE),
	/* TCHSCR_INT_ODL */
	PAD_GPI(GPIO_89, PULL_NONE),
	/* HP_INT_ODL */
	PAD_GPI(GPIO_90, PULL_NONE),
	/* SD_EX_PRSNT_L(Guybrush BoardID 1 only) / EC_IN_RW_OD */
	PAD_GPI(GPIO_91, PULL_NONE),
	/* CLK_REQ0_L */
	PAD_NF(GPIO_92, CLK_REQ0_L, PULL_NONE),
	/* GPIO_93 - GPIO_103: Not available */
	/* ESPI1_DATA0 */
	PAD_NF(GPIO_104, SPI2_DO_ESPI2_D0, PULL_NONE),
	/* ESPI1_DATA1 */
	PAD_NF(GPIO_105, SPI2_DI_ESPI2_D1, PULL_NONE),
	/* ESPI1_DATA2 */
	PAD_NF(GPIO_106, EMMC_SPI2_WP_L_ESPI2_D2, PULL_NONE),
	/* ESPI1_DATA3 */
	PAD_NF(GPIO_107, SPI2_HOLD_L_ESPI2_D3, PULL_NONE),
	/* ESPI_ALERT_L */
	PAD_NF(GPIO_108, ESPI_ALERT_D1, PULL_NONE),
	/* RAM_ID_0 / DEV_BEEP_EN */
	PAD_GPI(GPIO_109, PULL_NONE),
	/* GPIO_110 - GPIO_112: Not available */
	/* I2C2_SCL */
	PAD_NF(GPIO_113, I2C2_SCL, PULL_NONE),
	/* I2C2_SDA */
	PAD_NF(GPIO_114, I2C2_SDA, PULL_NONE),
	/* CLK_REQ1_L */
	PAD_NF(GPIO_115, CLK_REQ1_L, PULL_NONE),
	/* CLK_REQ2_L */
	PAD_NF(GPIO_116, CLK_REQ2_L, PULL_NONE),
	/* GPIO_117 - GPIO_119: Not available */
	/* TCHSCR_REPORT_EN */
	PAD_GPO(GPIO_120, LOW),
	/* TCHSCR_RESET_L */
	PAD_GPO(GPIO_121, LOW),
	/* GPIO_122 - GPIO_128: Not available */
	/* SOC_DISABLE_DISP_BL */
	PAD_GPO(GPIO_129, HIGH),
	/* WLAN_DISABLE */
	PAD_GPO(GPIO_130, LOW),
	/* CLK_REQ3_L */
	PAD_NF(GPIO_131, CLK_REQ3_L, PULL_NONE),
	/* BT_DISABLE */
	PAD_GPO(GPIO_132, LOW),
	/* UART1_TXD */
	PAD_NF(GPIO_140, UART1_TXD, PULL_NONE),
	/* UART0_RXD */
	PAD_NF(GPIO_141, UART0_RXD, PULL_NONE),
	/* UART1_RXD */
	PAD_NF(GPIO_142, UART1_RXD, PULL_NONE),
	/* UART0_TXD */
	PAD_NF(GPIO_143, UART0_TXD, PULL_NONE),
	/* SOC_FPMCU_BOOT0 */
	PAD_GPO(GPIO_144, LOW),
	/* I2C0_SCL */
	PAD_NF(GPIO_145, I2C0_SCL, PULL_NONE),
	/* I2C0_SDA */
	PAD_NF(GPIO_146, I2C0_SDA, PULL_NONE),
	/* I2C1_SCL */
	PAD_NF(GPIO_147, I2C1_SCL, PULL_NONE),
	/* I2C1_SDA */
	PAD_NF(GPIO_148, I2C1_SDA, PULL_NONE),
};

/* Early GPIO configuration */
static const struct soc_amd_gpio early_gpio_table[] = {
	/* Assert all AUX reset lines */
	/* SD_AUX_RESET_L  */
	PAD_GPO(GPIO_5, LOW),
	/* WWAN_AUX_RESET_L */
	PAD_GPO(GPIO_18, LOW),
	/* WLAN_AUX_RESET (ACTIVE HIGH) */
	PAD_GPO(GPIO_29, HIGH),
	/* SSD_AUX_RESET_L */
	PAD_GPO(GPIO_40, LOW),
	/* Guybrush BID >= 2: SD_AUX_RESET_L, Other variants: Unused */
	PAD_NC(GPIO_69),
	/* Guybrush BID>1, Other variants : Unused TP27; BID==1: SD_AUX_RESET_L */
	PAD_NC(GPIO_70),

	/* Deassert PCIe Reset lines */
	/* PCIE_RST0_L */
	PAD_NFO(GPIO_26, PCIE_RST_L, HIGH),
	/* PCIE_RST1_L */
	PAD_NFO(GPIO_27, PCIE_RST1_L, HIGH),

/* Power on WLAN & WWAN */
	/* EN_PP3300_WLAN */
	PAD_GPO(GPIO_6, HIGH),
	/* EN_PWR_WWAN_X */
	PAD_GPO(GPIO_8, HIGH),

/* Put WWAN into reset */
	/* WWAN_RST_L */
	PAD_GPO(GPIO_24, LOW),
	/* WWAN_DISABLE */
	PAD_GPO(GPIO_85, HIGH),

/* Enable ESPI, GSC Interrupt & I2C Communication */
	/* GSC_SOC_INT_L */
	PAD_INT(GPIO_3, PULL_NONE, EDGE_LOW, STATUS_DELIVERY),
	/* I2C3_SCL */
	PAD_NF(GPIO_19, I2C3_SCL, PULL_NONE),
	/* I2C3_SDA */
	PAD_NF(GPIO_20, I2C3_SDA, PULL_NONE),
	/* ESPI_CS_L */
	PAD_NF(GPIO_30, ESPI_CS_L, PULL_NONE),
	/* ESPI_SOC_CLK */
	PAD_NF(GPIO_86, SPI_CLK, PULL_NONE),
	/* ESPI1_DATA0 */
	PAD_NF(GPIO_104, SPI2_DO_ESPI2_D0, PULL_NONE),
	/* ESPI1_DATA1 */
	PAD_NF(GPIO_105, SPI2_DI_ESPI2_D1, PULL_NONE),
	/* ESPI1_DATA2 */
	PAD_NF(GPIO_106, EMMC_SPI2_WP_L_ESPI2_D2, PULL_NONE),
	/* ESPI1_DATA3 */
	PAD_NF(GPIO_107, SPI2_HOLD_L_ESPI2_D3, PULL_NONE),
	/* ESPI_ALERT_L */
	PAD_NF(GPIO_108, ESPI_ALERT_D1, PULL_NONE),

/* Enable UART 0 */
	/* UART0_RXD */
	PAD_NF(GPIO_141, UART0_RXD, PULL_NONE),
	/* UART0_TXD */
	PAD_NF(GPIO_143, UART0_TXD, PULL_NONE),

/* Support EC trusted */
	/* SD_EX_PRSNT_L(Guybrush BoardID 1 only) / EC_IN_RW_OD */
	PAD_GPI(GPIO_91, PULL_NONE),
};

/* Power-on timing requirements:
 * Fibocom 350-GL:
 *   FCP0# goes high (GPIO 6)	to	Reset# high (GPIO 24):	20ms min
 *   FCP0# goes high (GPIO 6)	to	PERST# high (GPIO 26):	100ms min
 *   PERST# high (GPIO 26)	to	PCIE Training (FSP-M):	23ms min
 *
 * Realtek RTL8852AE:
 *   Power (3.3 V) valid	to	PERST# high (GPIO_26):	50ms min
 *
 * Qualcomm WCN6856:
 *   Power (3.3 V) valid	to	PERST# high (GPIO_26):	50ms min
 *
 * RTS5250S / RTS5227S / RTS5261S
 *   Power (3.3 V) valid	to	PERST# high (GPIO_69/70):	1ms min
 *
 * PCIe spec:
 *   Power (3.3 V) valid	to	PERST# high (GPIO_26):	50ms min (SUGGESTED)
 *
 * NVME adapters planned for Guybrush:
 *   No power on timings specified - Assumed to require PCIe Spec suggested
 *   guidelines.  Testing seems to bear out this assumption.
 */

static const struct soc_amd_gpio bootblock_gpio_table[] = {
	/* Enable WWAN, Deassert WWAN reset, keep WWAN PCIe Aux reset asserted */
	/* WWAN_RST_L */
	PAD_GPO(GPIO_24, HIGH),
	/* WWAN_DISABLE */
	PAD_GPO(GPIO_85, LOW),

	/* Enable WLAN */
	/* WLAN_DISABLE */
	PAD_GPO(GPIO_130, LOW),
};

/* GPIO configuration for sleep */
static const struct soc_amd_gpio sleep_gpio_table[] = {
	/* TODO: Fill sleep gpio configuration */
};

/* PCIE_RST needs to be brought high before FSP-M runs */
static const struct soc_amd_gpio pcie_gpio_table[] = {
	/* Deassert all AUX_RESET lines & PCIE_RST */
	/* SD_AUX_RESET_L  */
	PAD_GPO(GPIO_5, HIGH),
	/* WWAN_AUX_RESET_L */
	PAD_GPO(GPIO_18, HIGH),
	/* WLAN_AUX_RESET (ACTIVE HIGH) */
	PAD_GPO(GPIO_29, LOW),
	/* SSD_AUX_RESET_L */
	PAD_GPO(GPIO_40, HIGH),
	/* Guybrush BID >= 2: SD_AUX_RESET_L, Other variants: Unused */
	PAD_NC(GPIO_69),
	/* Guybrush BID>1, Other variants : Unused TP27; BID==1: SD_AUX_RESET_L */
	PAD_NC(GPIO_70),
	/* PCIE_RST0_L */
	PAD_NFO(GPIO_26, PCIE_RST_L, HIGH),
};

static const struct soc_amd_gpio gpio_fp_shutdown_table[] = {
	/* FPMCU_RST_L */
	PAD_GPO(GPIO_11, LOW),
	/* EN_PWR_FP */
	PAD_GPO(GPIO_32, LOW),
};

const struct soc_amd_gpio *__weak variant_pcie_gpio_table(size_t *size)
{
	*size = ARRAY_SIZE(pcie_gpio_table);
	return pcie_gpio_table;
}

const struct soc_amd_gpio *__weak variant_bootblock_gpio_table(size_t *size)
{
	*size = ARRAY_SIZE(bootblock_gpio_table);
	return bootblock_gpio_table;
}

const struct soc_amd_gpio *__weak variant_base_gpio_table(size_t *size)
{
	*size = ARRAY_SIZE(base_gpio_table);
	return base_gpio_table;
}
const struct soc_amd_gpio *__weak variant_override_gpio_table(size_t *size)
{
	*size = 0;
	return NULL;
}

const struct soc_amd_gpio * __weak variant_early_override_gpio_table(size_t *size)
{
	/* Note that when overriding this, board ID & CBI is not available */
	*size = 0;
	return NULL;
}

const struct soc_amd_gpio * __weak variant_bootblock_override_gpio_table(size_t *size)
{
	*size = 0;
	return NULL;
}

const struct soc_amd_gpio * __weak variant_pcie_override_gpio_table(size_t *size)
{
	*size = 0;
	return NULL;
}

const struct soc_amd_gpio *__weak variant_early_gpio_table(size_t *size)
{
	*size = ARRAY_SIZE(early_gpio_table);
	return early_gpio_table;
}

const __weak struct soc_amd_gpio *variant_sleep_gpio_table(size_t *size)
{
	if (acpi_get_sleep_type() == ACPI_S5) {
		*size = ARRAY_SIZE(gpio_fp_shutdown_table);
		return gpio_fp_shutdown_table;
	}

	*size = ARRAY_SIZE(sleep_gpio_table);
	return sleep_gpio_table;
}

__weak void variant_fpmcu_reset(void)
{
	if (acpi_get_sleep_type() == ACPI_S3)
		return;
	/* If the system is not resuming from S3, power off the FPMCU */
	static const struct soc_amd_gpio fpmcu_bootblock_table[] = {
		/* SOC_FP_RST_L */
		PAD_GPO(GPIO_11, LOW),
		/* EN_PWR_FP */
		PAD_GPO(GPIO_32, LOW),
	};
	gpio_configure_pads(fpmcu_bootblock_table, ARRAY_SIZE(fpmcu_bootblock_table));
}

__weak void variant_finalize_gpios(void)
{
	static const struct soc_amd_gpio disable_fpmcu_table[] = {
		/* FPMCU_RST_L */
		PAD_NC(GPIO_11),
		/* EN_PWR_FP */
		PAD_NC(GPIO_32),
	};

	if (variant_has_fpmcu()) {
		if (acpi_get_sleep_type() == ACPI_S3)
			return;
		/* Deassert the FPMCU reset to enable the FPMCU */
		gpio_set(GPIO_11, 1); /* FPMCU_RST_L */
	} else {
		gpio_configure_pads(disable_fpmcu_table, ARRAY_SIZE(disable_fpmcu_table));
	}
}