1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Rockchip PCIe Headers
5 * Copyright (c) 2016 Rockchip, Inc.
6 * Copyright (c) 2020 Amarula Solutions(India)
7 * Copyright (c) 2020 Jagan Teki <jagan@amarulasolutions.com>
8 * Copyright (c) 2019 Patrick Wildt <patrick@blueri.se>
12 #include <generic-phy.h>
14 #define HIWORD_UPDATE(mask, val) (((mask) << 16) | (val))
15 #define HIWORD_UPDATE_BIT(val) HIWORD_UPDATE(val, val)
17 #define ENCODE_LANES(x) ((((x) >> 1) & 3) << 4)
18 #define PCIE_CLIENT_BASE 0x0
19 #define PCIE_CLIENT_CONFIG (PCIE_CLIENT_BASE + 0x00)
20 #define PCIE_CLIENT_CONF_ENABLE HIWORD_UPDATE_BIT(0x0001)
21 #define PCIE_CLIENT_LINK_TRAIN_ENABLE HIWORD_UPDATE_BIT(0x0002)
22 #define PCIE_CLIENT_MODE_RC HIWORD_UPDATE_BIT(0x0040)
23 #define PCIE_CLIENT_GEN_SEL_1 HIWORD_UPDATE(0x0080, 0)
24 #define PCIE_CLIENT_BASIC_STATUS1 0x0048
25 #define PCIE_CLIENT_LINK_STATUS_UP GENMASK(21, 20)
26 #define PCIE_CLIENT_LINK_STATUS_MASK GENMASK(21, 20)
27 #define PCIE_LINK_UP(x) \
28 (((x) & PCIE_CLIENT_LINK_STATUS_MASK) == PCIE_CLIENT_LINK_STATUS_UP)
29 #define PCIE_RC_NORMAL_BASE 0x800000
30 #define PCIE_LM_BASE 0x900000
31 #define PCIE_LM_VENDOR_ID (PCIE_LM_BASE + 0x44)
32 #define PCIE_LM_VENDOR_ROCKCHIP 0x1d87
33 #define PCIE_LM_RCBAR (PCIE_LM_BASE + 0x300)
34 #define PCIE_LM_RCBARPIE BIT(19)
35 #define PCIE_LM_RCBARPIS BIT(20)
36 #define PCIE_RC_BASE 0xa00000
37 #define PCIE_RC_CONFIG_DCR (PCIE_RC_BASE + 0x0c4)
38 #define PCIE_RC_CONFIG_DCR_CSPL_SHIFT 18
39 #define PCIE_RC_CONFIG_DCR_CPLS_SHIFT 26
40 #define PCIE_RC_PCIE_LCAP (PCIE_RC_BASE + 0x0cc)
41 #define PCIE_RC_PCIE_LCAP_APMS_L0S BIT(10)
42 #define PCIE_ATR_BASE 0xc00000
43 #define PCIE_ATR_OB_ADDR0(i) (PCIE_ATR_BASE + 0x000 + (i) * 0x20)
44 #define PCIE_ATR_OB_ADDR1(i) (PCIE_ATR_BASE + 0x004 + (i) * 0x20)
45 #define PCIE_ATR_OB_DESC0(i) (PCIE_ATR_BASE + 0x008 + (i) * 0x20)
46 #define PCIE_ATR_OB_DESC1(i) (PCIE_ATR_BASE + 0x00c + (i) * 0x20)
47 #define PCIE_ATR_IB_ADDR0(i) (PCIE_ATR_BASE + 0x800 + (i) * 0x8)
48 #define PCIE_ATR_IB_ADDR1(i) (PCIE_ATR_BASE + 0x804 + (i) * 0x8)
49 #define PCIE_ATR_HDR_MEM 0x2
50 #define PCIE_ATR_HDR_IO 0x6
51 #define PCIE_ATR_HDR_CFG_TYPE0 0xa
52 #define PCIE_ATR_HDR_CFG_TYPE1 0xb
53 #define PCIE_ATR_HDR_RID BIT(23)
55 #define PCIE_ATR_OB_REGION0_SIZE (32 * 1024 * 1024)
56 #define PCIE_ATR_OB_REGION_SIZE (1 * 1024 * 1024)
59 * The higher 16-bit of this register is used for write protection
60 * only if BIT(x + 16) set to 1 the BIT(x) can be written.
62 #define HIWORD_UPDATE_MASK(val, mask, shift) \
63 ((val) << (shift) | (mask) << ((shift) + 16))
65 #define PHY_CFG_DATA_SHIFT 7
66 #define PHY_CFG_ADDR_SHIFT 1
67 #define PHY_CFG_DATA_MASK 0xf
68 #define PHY_CFG_ADDR_MASK 0x3f
69 #define PHY_CFG_RD_MASK 0x3ff
70 #define PHY_CFG_WR_ENABLE 1
71 #define PHY_CFG_WR_DISABLE 1
72 #define PHY_CFG_WR_SHIFT 0
73 #define PHY_CFG_WR_MASK 1
74 #define PHY_CFG_PLL_LOCK 0x10
75 #define PHY_CFG_CLK_TEST 0x10
76 #define PHY_CFG_CLK_SCC 0x12
77 #define PHY_CFG_SEPE_RATE BIT(3)
78 #define PHY_CFG_PLL_100M BIT(3)
79 #define PHY_PLL_LOCKED BIT(9)
80 #define PHY_PLL_OUTPUT BIT(10)
81 #define PHY_LANE_IDLE_OFF 0x1
82 #define PHY_LANE_IDLE_MASK 0x1
83 #define PHY_LANE_IDLE_A_SHIFT 3
84 #define PHY_LANE_IDLE_B_SHIFT 4
85 #define PHY_LANE_IDLE_C_SHIFT 5
86 #define PHY_LANE_IDLE_D_SHIFT 6
88 #define PCIE_PHY_CONF 0xe220
89 #define PCIE_PHY_STATUS 0xe2a4
90 #define PCIE_PHY_LANEOFF 0xe214
92 struct rockchip_pcie_phy {
95 struct reset_ctl phy_rst;
96 struct rockchip_pcie_phy_ops *ops;
99 struct rockchip_pcie_phy_ops {
100 int (*init)(struct rockchip_pcie_phy *phy);
101 int (*exit)(struct rockchip_pcie_phy *phy);
102 int (*power_on)(struct rockchip_pcie_phy *phy);
103 int (*power_off)(struct rockchip_pcie_phy *phy);
106 struct rockchip_pcie {
111 struct rockchip_pcie_phy rk_phy;
112 struct rockchip_pcie_phy *phy;
115 struct reset_ctl core_rst;
116 struct reset_ctl mgmt_rst;
117 struct reset_ctl mgmt_sticky_rst;
118 struct reset_ctl pipe_rst;
119 struct reset_ctl pm_rst;
120 struct reset_ctl pclk_rst;
121 struct reset_ctl aclk_rst;
124 struct gpio_desc ep_gpio;
126 /* vpcie regulators */
127 struct udevice *vpcie12v;
128 struct udevice *vpcie3v3;
129 struct udevice *vpcie1v8;
130 struct udevice *vpcie0v9;
136 int rockchip_pcie_phy_get(struct udevice *dev);
138 static inline struct rockchip_pcie_phy *pcie_get_phy(struct rockchip_pcie *pcie)
143 static inline struct rockchip_pcie_phy_ops *phy_get_ops(struct rockchip_pcie_phy *phy)
145 return (struct rockchip_pcie_phy_ops *)phy->ops;