pci: Add Rockchip PCIe controller driver
[oweals/u-boot.git] / drivers / pci / pcie_rockchip.h
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Rockchip PCIe Headers
4  *
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>
9  *
10  */
11
12 #define HIWORD_UPDATE(mask, val)        (((mask) << 16) | (val))
13 #define HIWORD_UPDATE_BIT(val)          HIWORD_UPDATE(val, val)
14
15 #define ENCODE_LANES(x)                 ((((x) >> 1) & 3) << 4)
16 #define PCIE_CLIENT_BASE                0x0
17 #define PCIE_CLIENT_CONFIG              (PCIE_CLIENT_BASE + 0x00)
18 #define PCIE_CLIENT_CONF_ENABLE         HIWORD_UPDATE_BIT(0x0001)
19 #define PCIE_CLIENT_LINK_TRAIN_ENABLE   HIWORD_UPDATE_BIT(0x0002)
20 #define PCIE_CLIENT_MODE_RC             HIWORD_UPDATE_BIT(0x0040)
21 #define PCIE_CLIENT_GEN_SEL_1           HIWORD_UPDATE(0x0080, 0)
22 #define PCIE_CLIENT_BASIC_STATUS1       0x0048
23 #define PCIE_CLIENT_LINK_STATUS_UP      GENMASK(21, 20)
24 #define PCIE_CLIENT_LINK_STATUS_MASK    GENMASK(21, 20)
25 #define PCIE_LINK_UP(x) \
26         (((x) & PCIE_CLIENT_LINK_STATUS_MASK) == PCIE_CLIENT_LINK_STATUS_UP)
27 #define PCIE_RC_NORMAL_BASE             0x800000
28 #define PCIE_LM_BASE                    0x900000
29 #define PCIE_LM_VENDOR_ID              (PCIE_LM_BASE + 0x44)
30 #define PCIE_LM_VENDOR_ROCKCHIP         0x1d87
31 #define PCIE_LM_RCBAR                   (PCIE_LM_BASE + 0x300)
32 #define PCIE_LM_RCBARPIE                BIT(19)
33 #define PCIE_LM_RCBARPIS                BIT(20)
34 #define PCIE_RC_BASE                    0xa00000
35 #define PCIE_RC_CONFIG_DCR              (PCIE_RC_BASE + 0x0c4)
36 #define PCIE_RC_CONFIG_DCR_CSPL_SHIFT   18
37 #define PCIE_RC_CONFIG_DCR_CPLS_SHIFT   26
38 #define PCIE_RC_PCIE_LCAP               (PCIE_RC_BASE + 0x0cc)
39 #define PCIE_RC_PCIE_LCAP_APMS_L0S      BIT(10)
40 #define PCIE_ATR_BASE                   0xc00000
41 #define PCIE_ATR_OB_ADDR0(i)            (PCIE_ATR_BASE + 0x000 + (i) * 0x20)
42 #define PCIE_ATR_OB_ADDR1(i)            (PCIE_ATR_BASE + 0x004 + (i) * 0x20)
43 #define PCIE_ATR_OB_DESC0(i)            (PCIE_ATR_BASE + 0x008 + (i) * 0x20)
44 #define PCIE_ATR_OB_DESC1(i)            (PCIE_ATR_BASE + 0x00c + (i) * 0x20)
45 #define PCIE_ATR_IB_ADDR0(i)            (PCIE_ATR_BASE + 0x800 + (i) * 0x8)
46 #define PCIE_ATR_IB_ADDR1(i)            (PCIE_ATR_BASE + 0x804 + (i) * 0x8)
47 #define PCIE_ATR_HDR_MEM                0x2
48 #define PCIE_ATR_HDR_IO                 0x6
49 #define PCIE_ATR_HDR_CFG_TYPE0          0xa
50 #define PCIE_ATR_HDR_CFG_TYPE1          0xb
51 #define PCIE_ATR_HDR_RID                BIT(23)
52
53 #define PCIE_ATR_OB_REGION0_SIZE        (32 * 1024 * 1024)
54 #define PCIE_ATR_OB_REGION_SIZE         (1 * 1024 * 1024)
55
56 struct rockchip_pcie {
57         fdt_addr_t axi_base;
58         fdt_addr_t apb_base;
59         int first_busno;
60         struct udevice *dev;
61
62         /* resets */
63         struct reset_ctl core_rst;
64         struct reset_ctl mgmt_rst;
65         struct reset_ctl mgmt_sticky_rst;
66         struct reset_ctl pipe_rst;
67         struct reset_ctl pm_rst;
68         struct reset_ctl pclk_rst;
69         struct reset_ctl aclk_rst;
70
71         /* gpio */
72         struct gpio_desc ep_gpio;
73
74         /* vpcie regulators */
75         struct udevice *vpcie12v;
76         struct udevice *vpcie3v3;
77         struct udevice *vpcie1v8;
78         struct udevice *vpcie0v9;
79 };