Skip to content

Commit 80b31fb

Browse files
marcanMani-Sadhasivam
authored andcommitted
PCI: apple: Move port PHY registers to their own reg items
T602x PCIe cores move these registers around. Instead of hardcoding in another offset, let's move them into their own reg entries. This matches what Apple does on macOS device trees too. Maintains backwards compatibility with old DTs by using the old offsets. Note that we open code devm_platform_ioremap_resource_byname() to avoid error messages on older platforms with missing resources in the pcie node. ("pcie-apple 590000000.pcie: invalid resource (null)" on probe) Co-developed-by: Janne Grunau <[email protected]> Signed-off-by: Janne Grunau <[email protected]> Signed-off-by: Hector Martin <[email protected]> Signed-off-by: Alyssa Rosenzweig <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Signed-off-by: Manivannan Sadhasivam <[email protected]> Tested-by: Janne Grunau <[email protected]> Reviewed-by: Rob Herring (Arm) <[email protected]> Reviewed-by: Manivannan Sadhasivam <[email protected]> Acked-by: Alyssa Rosenzweig <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 7fa9fbf commit 80b31fb

File tree

1 file changed

+37
-18
lines changed

1 file changed

+37
-18
lines changed

drivers/pci/controller/pcie-apple.c

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,18 @@
3939
#define CORE_RC_STAT_READY BIT(0)
4040
#define CORE_FABRIC_STAT 0x04000
4141
#define CORE_FABRIC_STAT_MASK 0x001F001F
42-
#define CORE_LANE_CFG(port) (0x84000 + 0x4000 * (port))
43-
#define CORE_LANE_CFG_REFCLK0REQ BIT(0)
44-
#define CORE_LANE_CFG_REFCLK1REQ BIT(1)
45-
#define CORE_LANE_CFG_REFCLK0ACK BIT(2)
46-
#define CORE_LANE_CFG_REFCLK1ACK BIT(3)
47-
#define CORE_LANE_CFG_REFCLKEN (BIT(9) | BIT(10))
48-
#define CORE_LANE_CTL(port) (0x84004 + 0x4000 * (port))
49-
#define CORE_LANE_CTL_CFGACC BIT(15)
42+
43+
#define CORE_PHY_DEFAULT_BASE(port) (0x84000 + 0x4000 * (port))
44+
45+
#define PHY_LANE_CFG 0x00000
46+
#define PHY_LANE_CFG_REFCLK0REQ BIT(0)
47+
#define PHY_LANE_CFG_REFCLK1REQ BIT(1)
48+
#define PHY_LANE_CFG_REFCLK0ACK BIT(2)
49+
#define PHY_LANE_CFG_REFCLK1ACK BIT(3)
50+
#define PHY_LANE_CFG_REFCLKEN (BIT(9) | BIT(10))
51+
#define PHY_LANE_CFG_REFCLKCGEN (BIT(30) | BIT(31))
52+
#define PHY_LANE_CTL 0x00004
53+
#define PHY_LANE_CTL_CFGACC BIT(15)
5054

5155
#define PORT_LTSSMCTL 0x00080
5256
#define PORT_LTSSMCTL_START BIT(0)
@@ -146,6 +150,7 @@ struct apple_pcie_port {
146150
struct apple_pcie *pcie;
147151
struct device_node *np;
148152
void __iomem *base;
153+
void __iomem *phy;
149154
struct irq_domain *domain;
150155
struct list_head entry;
151156
unsigned long *sid_map;
@@ -476,26 +481,26 @@ static int apple_pcie_setup_refclk(struct apple_pcie *pcie,
476481
if (res < 0)
477482
return res;
478483

479-
rmw_set(CORE_LANE_CTL_CFGACC, pcie->base + CORE_LANE_CTL(port->idx));
480-
rmw_set(CORE_LANE_CFG_REFCLK0REQ, pcie->base + CORE_LANE_CFG(port->idx));
484+
rmw_set(PHY_LANE_CTL_CFGACC, port->phy + PHY_LANE_CTL);
485+
rmw_set(PHY_LANE_CFG_REFCLK0REQ, port->phy + PHY_LANE_CFG);
481486

482-
res = readl_relaxed_poll_timeout(pcie->base + CORE_LANE_CFG(port->idx),
483-
stat, stat & CORE_LANE_CFG_REFCLK0ACK,
487+
res = readl_relaxed_poll_timeout(port->phy + PHY_LANE_CFG,
488+
stat, stat & PHY_LANE_CFG_REFCLK0ACK,
484489
100, 50000);
485490
if (res < 0)
486491
return res;
487492

488-
rmw_set(CORE_LANE_CFG_REFCLK1REQ, pcie->base + CORE_LANE_CFG(port->idx));
489-
res = readl_relaxed_poll_timeout(pcie->base + CORE_LANE_CFG(port->idx),
490-
stat, stat & CORE_LANE_CFG_REFCLK1ACK,
493+
rmw_set(PHY_LANE_CFG_REFCLK1REQ, port->phy + PHY_LANE_CFG);
494+
res = readl_relaxed_poll_timeout(port->phy + PHY_LANE_CFG,
495+
stat, stat & PHY_LANE_CFG_REFCLK1ACK,
491496
100, 50000);
492497

493498
if (res < 0)
494499
return res;
495500

496-
rmw_clear(CORE_LANE_CTL_CFGACC, pcie->base + CORE_LANE_CTL(port->idx));
501+
rmw_clear(PHY_LANE_CTL_CFGACC, port->phy + PHY_LANE_CTL);
497502

498-
rmw_set(CORE_LANE_CFG_REFCLKEN, pcie->base + CORE_LANE_CFG(port->idx));
503+
rmw_set(PHY_LANE_CFG_REFCLKEN, port->phy + PHY_LANE_CFG);
499504
rmw_set(PORT_REFCLK_EN, port->base + PORT_REFCLK);
500505

501506
return 0;
@@ -515,6 +520,8 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie,
515520
struct platform_device *platform = to_platform_device(pcie->dev);
516521
struct apple_pcie_port *port;
517522
struct gpio_desc *reset;
523+
struct resource *res;
524+
char name[16];
518525
u32 stat, idx;
519526
int ret, i;
520527

@@ -542,10 +549,22 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie,
542549

543550
raw_spin_lock_init(&port->lock);
544551

545-
port->base = devm_platform_ioremap_resource(platform, port->idx + 2);
552+
snprintf(name, sizeof(name), "port%d", port->idx);
553+
res = platform_get_resource_byname(platform, IORESOURCE_MEM, name);
554+
if (!res)
555+
res = platform_get_resource(platform, IORESOURCE_MEM, port->idx + 2);
556+
557+
port->base = devm_ioremap_resource(&platform->dev, res);
546558
if (IS_ERR(port->base))
547559
return PTR_ERR(port->base);
548560

561+
snprintf(name, sizeof(name), "phy%d", port->idx);
562+
res = platform_get_resource_byname(platform, IORESOURCE_MEM, name);
563+
if (res)
564+
port->phy = devm_ioremap_resource(&platform->dev, res);
565+
else
566+
port->phy = pcie->base + CORE_PHY_DEFAULT_BASE(port->idx);
567+
549568
rmw_set(PORT_APPCLK_EN, port->base + PORT_APPCLK);
550569

551570
/* Assert PERST# before setting up the clock */

0 commit comments

Comments
 (0)