1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <bootblock_common.h>
4 #include <device/mmio.h>
5 #include <gpio.h>
6 #include <soc/i2c.h>
7 #include <soc/pcie.h>
8 #include <soc/spi.h>
9
10 #include "gpio.h"
11
12 struct pad_func {
13 u8 pin_id;
14 u8 func;
15 };
16
17 #define PAD_FUNC(name, func) {PAD_##name##_ID, PAD_##name##_FUNC_##func}
18
nor_set_gpio_pinmux(void)19 static void nor_set_gpio_pinmux(void)
20 {
21 const struct pad_func *ptr = NULL;
22
23 /* GPIO 140 ~ 143 */
24 struct pad_func nor_pinmux[] = {
25 PAD_FUNC(SPIM2_CSB, SPINOR_CS),
26 PAD_FUNC(SPIM2_CLK, SPINOR_CK),
27 PAD_FUNC(SPIM2_MO, SPINOR_IO0),
28 PAD_FUNC(SPIM2_MI, SPINOR_IO1),
29 };
30
31 ptr = nor_pinmux;
32 for (size_t i = 0; i < ARRAY_SIZE(nor_pinmux); i++) {
33 gpio_set_pull((gpio_t){.id = ptr[i].pin_id},
34 GPIO_PULL_ENABLE, GPIO_PULL_UP);
35 gpio_set_mode((gpio_t){.id = ptr[i].pin_id}, ptr[i].func);
36 }
37 }
38
usb3_hub_reset(void)39 static void usb3_hub_reset(void)
40 {
41 gpio_output(GPIO(DGI_D7), 1);
42 }
43
bootblock_mainboard_init(void)44 void bootblock_mainboard_init(void)
45 {
46 /*
47 * Initialize PCIe pinmux and assert PERST# early to reduce
48 * the impact of 100ms delay.
49 */
50 if (CONFIG(PCI))
51 mtk_pcie_pre_init();
52
53 mtk_i2c_bus_init(CONFIG_DRIVER_TPM_I2C_BUS, I2C_SPEED_FAST);
54 mtk_spi_init(CONFIG_EC_GOOGLE_CHROMEEC_SPI_BUS, SPI_PAD0_MASK, 3 * MHz, 0);
55 nor_set_gpio_pinmux();
56 setup_chromeos_gpios();
57 gpio_eint_configure(GPIO_GSC_AP_INT, IRQ_TYPE_EDGE_RISING);
58 usb3_hub_reset();
59 }
60