Skip to content

Commit 17ada56

Browse files
edimoldovanclaude
andcommitted
PCI: apple: T6050 cold train: apply the host tunables
A port trained without the boot loader's tunables comes up, but the PHY tunables are what clear lane bit 28 (and the shared PHY's bit 26); the adopt checks expect that state, and every proxy-trained boot has had it. Apply the host lists the DT carries (apple,tunable-axi2af, -cio3pllcore, -pcieclkgen, -phy, then -phy-ip-pll and -phy-ip-auspma after the PHY clocks), in m1n1's order. The windows may contain windows mapped elsewhere, so they are mapped without claiming them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent d991de7 commit 17ada56

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

‎drivers/pci/controller/pcie-apple.c‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,6 +2078,52 @@ static int apple_pcie_t6050_phy_wait(struct apple_pcie *pcie, u32 mask, u32 valu
20782078
return ret;
20792079
}
20802080

2081+
/*
2082+
* A host tunable list (apple,tunable-<name>, groups of (offset, 4, mask, value)) applied
2083+
* to the host window @win. The window may contain windows mapped elsewhere (the PHY
2084+
* window holds the port and shared PHYs), so it is mapped without claiming it.
2085+
*/
2086+
static int apple_pcie_t6050_tune_host(struct apple_pcie *pcie, const char *name,
2087+
const char *win)
2088+
{
2089+
struct platform_device *pdev = to_platform_device(pcie->dev);
2090+
struct device_node *np = pcie->dev->of_node;
2091+
struct resource *res;
2092+
void __iomem *base;
2093+
char prop[48];
2094+
u32 *cells;
2095+
int count, i, ret;
2096+
2097+
snprintf(prop, sizeof(prop), "apple,tunable-%s", name);
2098+
if (!of_property_present(np, prop))
2099+
return 0;
2100+
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, win);
2101+
count = of_property_count_u32_elems(np, prop);
2102+
if (!res || count <= 0 || count % 4)
2103+
return -EINVAL;
2104+
cells = kmalloc_array(count, sizeof(*cells), GFP_KERNEL);
2105+
if (!cells)
2106+
return -ENOMEM;
2107+
ret = of_property_read_u32_array(np, prop, cells, count);
2108+
for (i = 0; !ret && i < count; i += 4)
2109+
if (cells[i + 1] != 4 || (cells[i] & 3) || cells[i] > resource_size(res) - 4)
2110+
ret = -EINVAL;
2111+
if (!ret) {
2112+
base = ioremap(res->start, resource_size(res));
2113+
if (base) {
2114+
for (i = 0; i < count; i += 4)
2115+
apple_pcie_t6050_rmw(base + cells[i], cells[i + 2], cells[i + 3]);
2116+
iounmap(base);
2117+
} else {
2118+
ret = -ENOMEM;
2119+
}
2120+
}
2121+
kfree(cells);
2122+
if (ret)
2123+
dev_err(pcie->dev, "%s: %d\n", prop, ret);
2124+
return ret;
2125+
}
2126+
20812127
static int apple_pcie_t6050_shared_phy_on(struct apple_pcie *pcie)
20822128
{
20832129
struct platform_device *pdev = to_platform_device(pcie->dev);
@@ -2100,6 +2146,13 @@ static int apple_pcie_t6050_shared_phy_on(struct apple_pcie *pcie)
21002146
if (IS_ERR(cmn))
21012147
return PTR_ERR(cmn);
21022148

2149+
/* Fabric, clock generator and PHY tunables, then the PHY clocks (m1n1's order) */
2150+
ret = apple_pcie_t6050_tune_host(pcie, "axi2af", "axi2af") ?:
2151+
apple_pcie_t6050_tune_host(pcie, "cio3pllcore", "pcieclkgen") ?:
2152+
apple_pcie_t6050_tune_host(pcie, "pcieclkgen", "pcieclkgen") ?:
2153+
apple_pcie_t6050_tune_host(pcie, "phy", "phy-window");
2154+
if (ret)
2155+
return ret;
21032156
apple_pcie_t6050_rmw(phy + T6050_PHY_CTRL, 0, T6050_PHY_CTRL_CLK0REQ);
21042157
ret = apple_pcie_t6050_phy_wait(pcie, T6050_PHY_CTRL_CLK0ACK, T6050_PHY_CTRL_CLK0ACK);
21052158
if (ret)
@@ -2117,6 +2170,10 @@ static int apple_pcie_t6050_shared_phy_on(struct apple_pcie *pcie)
21172170
if (ret)
21182171
return ret;
21192172
apple_pcie_t6050_rmw(phy + T6050_PHY_CFG, 0, BIT(0));
2173+
ret = apple_pcie_t6050_tune_host(pcie, "phy-ip-pll", "phy-ip") ?:
2174+
apple_pcie_t6050_tune_host(pcie, "phy-ip-auspma", "phy-ip");
2175+
if (ret)
2176+
return ret;
21202177
apple_pcie_t6050_rmw(phy + T6050_PHY_CFG, 0, BIT(4));
21212178
apple_pcie_t6050_rmw(cmn + T6050_PHYCMN_CLK, T6050_PHYCMN_CLK_MODE,
21222179
FIELD_PREP(T6050_PHYCMN_CLK_MODE, 1));

0 commit comments

Comments
 (0)