Debian Codegraph @

src/mainboard/google/zork/variants/baseboard/trembyle/gpio.c

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