Skip to content

Commit e7a0ed3

Browse files
marcanjannau
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. Signed-off-by: Hector Martin <marcan@marcan.st>
1 parent dd816ae commit e7a0ed3

1 file changed

Lines changed: 33 additions & 18 deletions

File tree

drivers/pci/controller/pcie-apple.c

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

5256
#define PORT_LTSSMCTL 0x00080
5357
#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
DECLARE_BITMAP(sid_map, MAX_RID2SID);
@@ -474,26 +479,26 @@ static int apple_pcie_setup_refclk(struct apple_pcie *pcie,
474479
if (res < 0)
475480
return res;
476481

477-
rmw_set(CORE_LANE_CTL_CFGACC, pcie->base + CORE_LANE_CTL(port->idx));
478-
rmw_set(CORE_LANE_CFG_REFCLK0REQ, pcie->base + CORE_LANE_CFG(port->idx));
482+
rmw_set(PHY_LANE_CTL_CFGACC, port->phy + PHY_LANE_CTL);
483+
rmw_set(PHY_LANE_CFG_REFCLK0REQ, port->phy + PHY_LANE_CFG);
479484

480-
res = readl_relaxed_poll_timeout(pcie->base + CORE_LANE_CFG(port->idx),
481-
stat, stat & CORE_LANE_CFG_REFCLK0ACK,
485+
res = readl_relaxed_poll_timeout(port->phy + PHY_LANE_CFG,
486+
stat, stat & PHY_LANE_CFG_REFCLK0ACK,
482487
100, 50000);
483488
if (res < 0)
484489
return res;
485490

486-
rmw_set(CORE_LANE_CFG_REFCLK1REQ, pcie->base + CORE_LANE_CFG(port->idx));
487-
res = readl_relaxed_poll_timeout(pcie->base + CORE_LANE_CFG(port->idx),
488-
stat, stat & CORE_LANE_CFG_REFCLK1ACK,
491+
rmw_set(PHY_LANE_CFG_REFCLK1REQ, port->phy + PHY_LANE_CFG);
492+
res = readl_relaxed_poll_timeout(port->phy + PHY_LANE_CFG,
493+
stat, stat & PHY_LANE_CFG_REFCLK1ACK,
489494
100, 50000);
490495

491496
if (res < 0)
492497
return res;
493498

494-
rmw_clear(CORE_LANE_CTL_CFGACC, pcie->base + CORE_LANE_CTL(port->idx));
499+
rmw_clear(PHY_LANE_CTL_CFGACC, port->phy + PHY_LANE_CTL);
495500

496-
rmw_set(CORE_LANE_CFG_REFCLKEN, pcie->base + CORE_LANE_CFG(port->idx));
501+
rmw_set(PHY_LANE_CFG_REFCLKEN, port->phy + PHY_LANE_CFG);
497502
rmw_set(PORT_REFCLK_EN, port->base + PORT_REFCLK);
498503

499504
return 0;
@@ -539,6 +544,7 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie,
539544
struct gpio_desc *reset, *pwren = NULL;
540545
u32 stat, idx;
541546
int ret, i;
547+
char name[16];
542548

543549
reset = devm_fwnode_gpiod_get(pcie->dev, of_fwnode_handle(np), "reset",
544550
GPIOD_OUT_LOW, "PERST#");
@@ -567,9 +573,18 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie,
567573
port->pcie = pcie;
568574
port->np = np;
569575

570-
port->base = devm_platform_ioremap_resource(platform, port->idx + 2);
576+
snprintf(name, sizeof(name), "port%d", port->idx);
577+
port->base = devm_platform_ioremap_resource_byname(platform, name);
571578
if (IS_ERR(port->base))
579+
port->base = devm_platform_ioremap_resource(platform, port->idx + 2);
580+
if (IS_ERR(port->base)) {
572581
return PTR_ERR(port->base);
582+
}
583+
584+
snprintf(name, sizeof(name), "phy%d", port->idx);
585+
port->phy = devm_platform_ioremap_resource_byname(platform, name);
586+
if (IS_ERR(port->phy))
587+
port->phy = pcie->base + CORE_PHY_DEFAULT_BASE(port->idx);
573588

574589
rmw_set(PORT_APPCLK_EN, port->base + PORT_APPCLK);
575590

0 commit comments

Comments
 (0)