blob: eb7ad8725eeebae7e4bb3db56a4d512482491316 [file] [log] [blame]
Macpaul Lin5d16f8d2022-08-11 16:27:10 +08001/* SPDX-License-Identifier: GPL-2.0-only OR MIT */
Jianjun Wangac1410d2021-07-14 15:39:40 +08002
Jianjun Wangac1410d2021-07-14 15:39:40 +08003#include <device/mmio.h>
4#include <device/resource.h>
Elyes Haouas5316abe2023-01-11 09:46:57 +01005#include <gpio.h>
Jianjun Wangac1410d2021-07-14 15:39:40 +08006#include <soc/addressmap.h>
Jianjun Wangaa751cc2022-03-23 15:38:56 +08007#include <soc/early_init.h>
Jianjun Wangac1410d2021-07-14 15:39:40 +08008#include <soc/pcie.h>
9#include <soc/pcie_common.h>
Jianjun Wangac1410d2021-07-14 15:39:40 +080010
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
Jianjun Wangac1410d2021-07-14 15:39:40 +080018struct pad_func {
19 gpio_t gpio;
20 u8 func;
21};
22
23#define PAD_FUNC(name, func) {GPIO(name), PAD_##name##_FUNC_##func}
24
25static 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
38static 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
Jianjun Wangc0808b62022-03-14 20:38:18 +080049void mtk_pcie_reset(uintptr_t reg, bool enable)
Jianjun Wangac1410d2021-07-14 15:39:40 +080050{
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
65void 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);
Jianjun Wangaa751cc2022-03-23 15:38:56 +080071
72 early_init_save_time(EARLY_INIT_PCIE);
Jianjun Wangac1410d2021-07-14 15:39:40 +080073}