xref: /openbmc/u-boot/drivers/pci/aspeed_pcie_phy.c (revision b415f713db4fdd15d0297247a67f4898e6797be3)
1 // SPDX-License-Identifier: GPL-2.0+
2 #include <common.h>
3 #include <dm.h>
4 #include <reset.h>
5 #include <fdtdec.h>
6 #include <pci.h>
7 #include <asm/io.h>
8 #include <asm/arch/ahbc_aspeed.h>
9 #include "pcie_aspeed.h"
10 
11 DECLARE_GLOBAL_DATA_PTR;
12 
13 /* PCI Host Controller registers */
14 #define ASPEED_PCIE_CLASS_CODE		0x04
15 #define ASPEED_PCIE_GLOBAL			0x30
16 #define ASPEED_PCIE_CFG_DIN			0x50
17 #define ASPEED_PCIE_CFG3			0x58
18 #define ASPEED_PCIE_LOCK			0x7C
19 #define ASPEED_PCIE_LINK			0xC0
20 #define ASPEED_PCIE_INT				0xC4
21 #define ASPEED_PCIE_LINK_STS		0xD0
22 
23 /* AST_PCIE_CFG2	0x04 */
24 #define PCIE_CFG_CLASS_CODE(x)	((x) << 8)
25 #define PCIE_CFG_REV_ID(x)		(x)
26 
27 /* AST_PCIE_GLOBAL	0x30 */
28 #define ROOT_COMPLEX_ID(x)		((x) << 4)
29 
30 /* AST_PCIE_LOCK	0x7C */
31 #define PCIE_UNLOCK				0xa8
32 
33 /* AST_PCIE_LINK	0xC0 */
34 #define PCIE_LINK_STS			BIT(5)
35 
36 /* ASPEED_PCIE_LINK_STS	0xD0 */
37 #define PCIE_LINK_5G			BIT(17)
38 #define PCIE_LINK_2_5G			BIT(16)
39 
40 extern int aspeed_pcie_phy_link_status(struct udevice *dev)
41 {
42 	struct aspeed_rc_bridge *rc_bridge = dev_get_priv(dev);
43 	u32 pcie_link = readl(rc_bridge->reg + ASPEED_PCIE_LINK);
44 	int ret = 0;
45 
46 	printf("RC Bridge %s : ", dev->name);
47 	if (pcie_link & PCIE_LINK_STS) {
48 		printf("Link up - ");
49 		if (pcie_link & PCIE_LINK_5G)
50 			printf("5G\n");
51 		if (pcie_link & PCIE_LINK_2_5G)
52 			printf("2.5G\n");
53 		ret = 1;
54 	} else {
55 		printf("Link down\n");
56 		ret = 0;
57 	}
58 
59 	return ret;
60 }
61 
62 static int aspeed_pcie_phy_probe(struct udevice *dev)
63 {
64 	struct reset_ctl reset_ctl;
65 	int ret = 0;
66 	struct aspeed_rc_bridge *rc_bridge = dev_get_priv(dev);
67 
68 	debug("%s(dev=%p)\n", __func__, dev);
69 
70 	ret = reset_get_by_index(dev, 0, &reset_ctl);
71 
72 	if (ret) {
73 		printf("%s(): Failed to get reset signal\n", __func__);
74 		return ret;
75 	}
76 
77 	//reset rc bridge
78 	reset_assert(&reset_ctl);
79 	reset_deassert(&reset_ctl);
80 
81 	rc_bridge->reg = devfdt_get_addr_ptr(dev);
82 	if (IS_ERR(rc_bridge->reg))
83 		return PTR_ERR(rc_bridge->reg);
84 
85 	writel(PCIE_UNLOCK, rc_bridge->reg + ASPEED_PCIE_LOCK);
86 	writel(ROOT_COMPLEX_ID(0x3), rc_bridge->reg + ASPEED_PCIE_GLOBAL);
87 	mdelay(100);
88 
89 	return 0;
90 }
91 
92 static const struct udevice_id aspeed_pcie_phy_ids[] = {
93 	{ .compatible = "aspeed,ast2600-pcie_phy" },
94 	{ }
95 };
96 
97 U_BOOT_DRIVER(aspeed_rc_bridge) = {
98 	.name		= "aspeed_pcie_phy",
99 	.id			= UCLASS_MISC,
100 	.of_match	= aspeed_pcie_phy_ids,
101 	.probe		= aspeed_pcie_phy_probe,
102 	.priv_auto_alloc_size	= sizeof(struct aspeed_rc_bridge),
103 };
104 
105