• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-only OR MIT */
2 
3 #include <device/mmio.h>
4 #include <device/resource.h>
5 #include <gpio.h>
6 #include <soc/addressmap.h>
7 #include <soc/early_init.h>
8 #include <soc/pcie.h>
9 #include <soc/pcie_common.h>
10 
11 #define PCIE_REG_BASE_PORT0	0x112f0000
12 #define PCIE_RST_CTRL_REG	(PCIE_REG_BASE_PORT0 + 0x148)
13 #define PCIE_MAC_RSTB		BIT(0)
14 #define PCIE_PHY_RSTB		BIT(1)
15 #define PCIE_BRG_RSTB		BIT(2)
16 #define PCIE_PE_RSTB		BIT(3)
17 
18 struct pad_func {
19 	gpio_t gpio;
20 	u8 func;
21 };
22 
23 #define PAD_FUNC(name, func) {GPIO(name), PAD_##name##_FUNC_##func}
24 
25 static const struct pad_func pcie_pins[2][3] = {
26 	{
27 		PAD_FUNC(PCIE_WAKE_N, WAKEN),
28 		PAD_FUNC(PCIE_PERESET_N, PERSTN),
29 		PAD_FUNC(PCIE_CLKREQ_N, CLKREQN),
30 	},
31 	{
32 		PAD_FUNC(CMMCLK0, PERSTN_1),
33 		PAD_FUNC(CMMCLK1, CLKREQN_1),
34 		PAD_FUNC(CMMCLK2, WAKEN_1),
35 	},
36 };
37 
mtk_pcie_set_pinmux(uint8_t port)38 static void mtk_pcie_set_pinmux(uint8_t port)
39 {
40 	const struct pad_func *pins = pcie_pins[port];
41 	size_t i;
42 
43 	for (i = 0; i < ARRAY_SIZE(pcie_pins[port]); i++) {
44 		gpio_set_mode(pins[i].gpio, pins[i].func);
45 		gpio_set_pull(pins[i].gpio, GPIO_PULL_ENABLE, GPIO_PULL_UP);
46 	}
47 }
48 
mtk_pcie_reset(uintptr_t reg,bool enable)49 void mtk_pcie_reset(uintptr_t reg, bool enable)
50 {
51 	uint32_t val;
52 
53 	val = read32p(reg);
54 
55 	if (enable)
56 		val |= PCIE_MAC_RSTB | PCIE_PHY_RSTB | PCIE_BRG_RSTB |
57 		       PCIE_PE_RSTB;
58 	else
59 		val &= ~(PCIE_MAC_RSTB | PCIE_PHY_RSTB | PCIE_BRG_RSTB |
60 			 PCIE_PE_RSTB);
61 
62 	write32p(reg, val);
63 }
64 
mtk_pcie_pre_init(void)65 void mtk_pcie_pre_init(void)
66 {
67 	mtk_pcie_set_pinmux(0);
68 
69 	/* Assert all reset signals at early stage */
70 	mtk_pcie_reset(PCIE_RST_CTRL_REG, true);
71 
72 	early_init_save_time(EARLY_INIT_PCIE);
73 }
74