From bd18722fd04817f2bc7f033c70264e0f764de5bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Mon, 16 Nov 2026 10:06:19 +0100 Subject: [PATCH 01/10] phy: apple: t6040: DP tunnel pixel clock MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In CIO mode the T6040 ATC PHY's AUSPLL feeds the pixel clocks of the router's DP IN adapters: one fixed AUSPLL frequency, a divider select per link rate in TX_DP_CTRL0 (RBR 4, HBR 3, HBR2 1, HBR3 0), the clock switch gate in the cfg bank, and the stop. DP IN 0 uses PCLK1 and switch 1; DP IN 1 uses PCLK2 and switch 2 and needs PCLK1 running as well. appledrm drives it through apple_t6040_dp_tunnel_rate(), a symbol of its own as for T6050, so phy-apple-atc and phy-apple-t6040-usb2 can both be built. The PHY stops the tunnel clocks when it leaves CIO. [petr: taken from fbalazsy/linux j616s/split-display (the tunnel clock, 432f1ec86 "give the DP tunnel pixel clock a symbol of its own" and 346a417f7 "give DP IN 1 of a tunnel its PCLK1 prerequisite") onto integration/aurora. Tested on the J614s with a Studio Display (2022) on Thunderbolt up to 5120x2880@60, aurora-silicon/linux#1589.] Signed-off-by: František Balázsy Signed-off-by: Petr Škuta <20834920+petrskuta@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 --- drivers/gpu/drm/apple/dcp-fabric.c | 43 +++- drivers/phy/apple/t6040-usb2.c | 306 ++++++++++++++++++++++++++++ include/linux/soc/apple/dp-tunnel.h | 6 + 3 files changed, 350 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp-fabric.c b/drivers/gpu/drm/apple/dcp-fabric.c index 25fadf4739c1f..5862d6f3336de 100644 --- a/drivers/gpu/drm/apple/dcp-fabric.c +++ b/drivers/gpu/drm/apple/dcp-fabric.c @@ -456,6 +456,12 @@ bool dcp_is_typec_only(struct platform_device *pdev) return !dcp->fixed_phy; } +static bool dcp_fabric_t6040_tunnel_clock(void) +{ + return of_machine_is_compatible("apple,t6040") || + of_machine_is_compatible("apple,t6041"); +} + static int dcp_route_clock_rate(struct apple_dcp_typec_route *route, struct phy *phy, unsigned int dpin, u8 rate) { @@ -479,6 +485,20 @@ static int dcp_route_clock_rate(struct apple_dcp_typec_route *route, return ret; } + /* T6040: the PHY's own AUSPLL feeds the pixel clock of DP IN 0 and 1. */ + if (dcp_fabric_t6040_tunnel_clock()) { + typeof(apple_t6040_dp_tunnel_rate) *fn = + symbol_get(apple_t6040_dp_tunnel_rate); + + if (!fn) + return rate ? -EOPNOTSUPP : 0; + ret = fn(phy, dpin, rate); + symbol_put(apple_t6040_dp_tunnel_rate); + if (!ret) + route->tunnel_rate = rate; + return ret; + } + /* A T8132 dcpext names its source (2 or 4), as T6030 does. */ if (of_machine_is_compatible("apple,t6030") || t8132) { typeof(apple_atc_dp_tunnel_rate_source) *fn; @@ -2266,6 +2286,9 @@ static void dcp_tunnel_prepare(struct apple_dcp_typec_route *route, if (ret && ret != -EOPNOTSUPP) dev_warn(dcp->dev, "DP tunnel crossbar preselect failed: %d\n", ret); + /* The clock call starts everything on T6040. */ + if (dcp_fabric_t6040_tunnel_clock()) + return; open = symbol_get(apple_atc_dp_tunnel_open); if (!open) return; @@ -3066,12 +3089,22 @@ static int dcp_tb_split_teardown_locked(struct apple_dcp_typec_port *port, /* Retire the callback before dropping its clock reference. */ dcp->split.active = false; if (dcp->phy) { - typeof(apple_atc_dp_tunnel_rate) *stop = - symbol_get(apple_atc_dp_tunnel_rate); + if (dcp_fabric_t6040_tunnel_clock()) { + typeof(apple_t6040_dp_tunnel_rate) *stop = + symbol_get(apple_t6040_dp_tunnel_rate); + + if (stop) { + stop(dcp->phy, 1, 0); + symbol_put(apple_t6040_dp_tunnel_rate); + } + } else { + typeof(apple_atc_dp_tunnel_rate) *stop = + symbol_get(apple_atc_dp_tunnel_rate); - if (stop) { - stop(dcp->phy, 1, 0); - symbol_put(apple_atc_dp_tunnel_rate); + if (stop) { + stop(dcp->phy, 1, 0); + symbol_put(apple_atc_dp_tunnel_rate); + } } } if (dcp->split.xbar) { diff --git a/drivers/phy/apple/t6040-usb2.c b/drivers/phy/apple/t6040-usb2.c index 50d82116aac2d..9b4a9262e1b9c 100644 --- a/drivers/phy/apple/t6040-usb2.c +++ b/drivers/phy/apple/t6040-usb2.c @@ -293,6 +293,9 @@ struct t6040_usb2_phy { bool usb3_lent; /* DP mode took the lanes of this Type-C port */ bool pipe_switched; /* the controller's PIPE runs on this PHY */ bool cio_up; /* the lanes run USB4/Thunderbolt */ + u8 tun_rate[2]; /* DP tunnel link rate per DP IN adapter, 0 = off */ + bool tun_pre; /* switch 1 is held for DP IN 1 alone */ + bool tun_pll; /* AUSPLL programmed for DP tunnels */ /* DisplayPort; dp_ok is false when the DT lacks a DP route */ struct phy *dp; @@ -1769,11 +1772,14 @@ static int t6040_cio_up_locked(struct t6040_usb2_phy *tphy) return ret; } +static void t6040_tun_stop_all_locked(struct t6040_usb2_phy *tphy); + static void t6040_cio_down_locked(struct t6040_usb2_phy *tphy) { lockdep_assert_held(&tphy->lock); if (!tphy->cio_up) return; + t6040_tun_stop_all_locked(tphy); t6040_phy_tx_cmn_down(tphy); t6040_cio_rx_down(tphy); fsleep(200); @@ -1949,6 +1955,306 @@ static const struct phy_ops t6040_dp_phy_ops = { .set_mode = t6040_dp_set_mode, }; +/* ---- DP tunnels: the pixel clocks of the router's DP IN adapters (PHY in CIO) ---- + * + * The DP 1.4 tunnel's init, update and shutdown and the DP clock + * configuration: one fixed AUSPLL frequency feeds the DPTX pixel clocks, + * whose select field divides it per link rate. DP IN adapter 0 is taken to + * use PCLK1 and clock switch 1, adapter 1 PCLK2 and switch 2 (the PHY does + * not choose: the index is the display controller's). Driven only by + * appledrm through apple_t6040_dp_tunnel_rate(), and only while the PHY is in + * CIO. + */ +#define T6040_CORE_RCAL1 0x804 /* AUS40CMN_DIG RCAL1 */ +#define T6040_CORE_RCAL1_DONE BIT(0) +#define T6040_CORE_AUSPLL_CMD 0x3000 /* AUSPLL_TOP_APB_CMD_CMDOVERRIDE */ +#define T6040_CORE_AUSPLL_CMD_REQ BIT(0) +#define T6040_CORE_AUSPLL_CMD_ACK BIT(1) +#define T6040_CORE_AUSPLL_FREQDESC_A 0x3080 +#define T6040_CORE_AUSPLL_FREQDESC_B 0x3084 +#define T6040_CORE_AUSPLL_FREQDESC_C 0x3088 +#define T6040_CORE_AUSPLL_CLKOUT_MASTER 0x3200 +#define T6040_CORE_AUSPLL_CLKOUT_DIV 0x3208 +#define T6040_CORE_AUSPLL_BGR 0x3218 +#define T6040_CORE_AUSPLL_FREQINIT_1 0x3234 +#define T6040_CORE_TX_DP_CTRL0 0x7000 +#define T6040_CORE_TX_DP_CTRL0_ENABLES GENMASK(18, 16) +#define T6040_CORE_DP_PCLK_STATUS 0x7034 +#define T6040_CORE_DP_PCLK_STATUS_LOCK BIT(3) /* AUSPLL_LOCK */ + +static const struct t6040_tun_pclk { + u8 sel_shift; /* TX_DP_CTRL0 select field */ + u32 en; /* TX_DP_CTRL0 enable */ + u32 sw_mask, sw_gate, sw_on; /* clock switch: cleared, set, status when on */ + u32 req[2], req_stat[2], sw_off; /* PMGR requests, their status, cleared at off */ +} t6040_tun_pclk[2] = { + { 4, BIT(16), 0x473, 0x10, BIT(0), { 0x20, 0x40 }, { BIT(1), BIT(2) }, 0x403 }, + { 8, BIT(17), 0xb8c, 0x80, BIT(3), { 0x100, 0x200 }, { BIT(4), BIT(5) }, 0x80c }, +}; + +/* The pixel clock select: RBR, HBR, HBR2, HBR3; UHBR is not tunnelled on this path. */ +static int t6040_tun_select(u8 rate) +{ + switch (rate) { + case 0x06: + return 4; + case 0x0a: + return 3; + case 0x14: + return 1; + case 0x1e: + return 0; + default: + return -EINVAL; + } +} + +/* DP IN 1 runs on PCLK2 and needs PCLK1 as well: without it its video stops. */ +static u32 t6040_tun_enables(struct t6040_usb2_phy *tphy) +{ + return ((tphy->tun_rate[0] || tphy->tun_rate[1]) ? t6040_tun_pclk[0].en : 0) | + (tphy->tun_rate[1] ? t6040_tun_pclk[1].en : 0); +} + +/* AUSPLL_TOP command override: request @req with the toggle protocol, then wait for @ack. */ +static int t6040_tun_pll_cmd(struct t6040_usb2_phy *tphy, u32 val, bool ack_set) +{ + void __iomem *cmd = t6040_core(tphy) + T6040_CORE_AUSPLL_CMD; + u32 v; + + writel((readl(cmd) & 0xe0000006) | val, cmd); + return readl_poll_timeout(cmd, v, !!(v & T6040_CORE_AUSPLL_CMD_ACK) == ack_set, + 10, 500 * USEC_PER_MSEC); +} + +/* The DP 1.4 tunnel shutdown: pixel clocks off, AUSPLL released. */ +static void t6040_tun_pll_stop(struct t6040_usb2_phy *tphy) +{ + void __iomem *core = t6040_core(tphy); + bool ack = readl(core + T6040_CORE_AUSPLL_CMD) & T6040_CORE_AUSPLL_CMD_ACK; + u32 v; + + t6040_usb2_clear32(core + T6040_CORE_TX_DP_CTRL0, T6040_CORE_TX_DP_CTRL0_ENABLES); + t6040_usb2_clear32(core + T6040_CORE_TX_DP_CTRL0, 0xc); + if (t6040_tun_pll_cmd(tphy, (ack ? 0 : T6040_CORE_AUSPLL_CMD_REQ) | 0x10000000, !ack) || + t6040_tun_pll_cmd(tphy, (ack ? T6040_CORE_AUSPLL_CMD_REQ : 0) | 0x10000018, ack) || + readl_poll_timeout(core + T6040_CORE_DP_PCLK_STATUS, v, + !(v & T6040_CORE_DP_PCLK_STATUS_LOCK), 10, 500 * USEC_PER_MSEC)) + dev_warn(tphy->dev, "DP tunnel: AUSPLL release timed out (cmd %#x, pclk status %#x)\n", + readl(core + T6040_CORE_AUSPLL_CMD), + readl(core + T6040_CORE_DP_PCLK_STATUS)); + t6040_usb2_clear32(core + T6040_CORE_AUSPLL_CLKOUT_MASTER, 0x8); + tphy->tun_pll = false; +} + +/* The common block's init, then the fixed AUSPLL program of the DP 1.4 tunnel init. */ +static int t6040_tun_pll_start(struct t6040_usb2_phy *tphy) +{ + void __iomem *core = t6040_core(tphy); + bool ack; + u32 v; + + if ((readl(core + T6040_CORE_AUSPLL_CLKOUT_MASTER) & 0x808) || + (readl(core + T6040_CORE_AUSPLL_CMD) & T6040_CORE_AUSPLL_CMD_REQ)) { + dev_warn(tphy->dev, "DP tunnel: AUSPLL already in use (master %#x, cmd %#x)\n", + readl(core + T6040_CORE_AUSPLL_CLKOUT_MASTER), + readl(core + T6040_CORE_AUSPLL_CMD)); + return -EBUSY; + } + t6040_usb2_clear32(core + T6040_CORE_TX_DP_CTRL0, T6040_CORE_TX_DP_CTRL0_ENABLES); + + t6040_usb2_set32(core + T6040_CORE_CMN_OVRD, 0x4); + t6040_usb2_set32(core + T6040_CORE_CMN_OVRD, 0x8); + udelay(1); + t6040_usb2_set32(core + T6040_CORE_CMN_OVRD, 0x1); + t6040_usb2_set32(core + T6040_CORE_CMN_OVRD, 0x2); + udelay(1); + t6040_usb2_clear32(core + T6040_CORE_CMN_OVRD, T6040_CORE_CMN_OVRD_CLAMP); + t6040_usb2_set32(core + T6040_CORE_CMN_OVRD, 0x20); + udelay(1); + t6040_usb2_set32(core + T6040_CORE_CMN_BIAS, T6040_CORE_CMN_BIAS_BGBIAS_EN_OV); + udelay(15); + if (readl_poll_timeout(core + T6040_CORE_RCAL1, v, v & T6040_CORE_RCAL1_DONE, 1, 100)) + dev_dbg(tphy->dev, "DP tunnel: RCAL not done (%#x)\n", v); + + t6040_usb2_clear32(core + T6040_CORE_AUSPLL_FREQINIT_1, 0x3); + writel(0x1e0e021c, core + T6040_CORE_AUSPLL_FREQDESC_A); + t6040_usb2_mask32(core + T6040_CORE_AUSPLL_FREQDESC_B, 0x0fffffff, 0); + t6040_usb2_mask32(core + T6040_CORE_AUSPLL_FREQDESC_C, 0x007fffff, 0x644a00); + t6040_usb2_mask32(core + T6040_CORE_AUSPLL_CLKOUT_DIV, 0x001f0000, 0x10000); + t6040_usb2_set32(core + T6040_CORE_AUSPLL_BGR, 0x1); + t6040_usb2_set32(core + T6040_CORE_AUSPLL_CLKOUT_MASTER, 0x808); + tphy->tun_pll = true; + + ack = readl(core + T6040_CORE_AUSPLL_CMD) & T6040_CORE_AUSPLL_CMD_ACK; + if (t6040_tun_pll_cmd(tphy, (ack ? 0 : T6040_CORE_AUSPLL_CMD_REQ) | 0x10000000, true) || + readl_poll_timeout(core + T6040_CORE_DP_PCLK_STATUS, v, + !!(v & T6040_CORE_DP_PCLK_STATUS_LOCK) == !ack, + 10, 500 * USEC_PER_MSEC) || + t6040_tun_pll_cmd(tphy, (ack ? T6040_CORE_AUSPLL_CMD_REQ : 0) | 0x10010000, ack)) { + dev_err(tphy->dev, "DP tunnel: AUSPLL did not lock (cmd %#x, pclk status %#x)\n", + readl(core + T6040_CORE_AUSPLL_CMD), + readl(core + T6040_CORE_DP_PCLK_STATUS)); + t6040_tun_pll_stop(tphy); + return -ETIMEDOUT; + } + t6040_usb2_set32(core + T6040_CORE_TX_DP_CTRL0, 0xc); + return 0; +} + +static void t6040_tun_select_field(u32 *v, const struct t6040_tun_pclk *p, int sel, bool en) +{ + if (!!(*v & p->en) != en || ((*v >> p->sel_shift) & 0xf) != sel) + *v = (*v & ~(p->en | (0xf << p->sel_shift))) | (sel << p->sel_shift); +} + +/* The DP 1.4 tunnel update for one pclk: select with its enable off, then the enables. */ +static void t6040_tun_select_write(struct t6040_usb2_phy *tphy, unsigned int dpin, int sel) +{ + void __iomem *ctrl0 = t6040_core(tphy) + T6040_CORE_TX_DP_CTRL0; + u32 v = readl(ctrl0); + + t6040_tun_select_field(&v, &t6040_tun_pclk[dpin], sel, !!tphy->tun_rate[dpin]); + /* PCLK1 is DP IN 1's prerequisite at its own rate, unless DP IN 0 runs on it. */ + if (dpin == 1 && !tphy->tun_rate[0]) + t6040_tun_select_field(&v, &t6040_tun_pclk[0], sel, true); + writel(v, ctrl0); + writel((v & ~T6040_CORE_TX_DP_CTRL0_ENABLES) | t6040_tun_enables(tphy), ctrl0); +} + +/* The DP clock configuration for one DP 1.x switch: pixel-clock gate on, or off. */ +static int t6040_tun_switch(struct t6040_usb2_phy *tphy, unsigned int dpin, bool on) +{ + const struct t6040_tun_pclk *p = &t6040_tun_pclk[dpin]; + void __iomem *cfg = t6040_cfg(tphy); + unsigned int i; + u32 s; + + if (on) { + t6040_usb2_mask32(cfg + T6040_CFG_DP_CLKSWITCH_CTRL, p->sw_mask, p->sw_gate); + return readl_poll_timeout(cfg + T6040_CFG_DP_CLKSWITCH_STAT, s, s & p->sw_on, + 10, 5 * USEC_PER_MSEC); + } + t6040_usb2_set32(cfg + T6040_CFG_DP_CLKSWITCH_CTRL, p->sw_gate); + for (i = 0; i < 2; i++) { + if (!(readl(cfg + T6040_CFG_DP_CLKSWITCH_CTRL) & p->req[i])) + continue; + t6040_usb2_clear32(cfg + T6040_CFG_DP_CLKSWITCH_CTRL, p->req[i]); + if (readl_poll_timeout(cfg + T6040_CFG_DP_CLKSWITCH_STAT, s, !(s & p->req_stat[i]), + 10, 5 * USEC_PER_MSEC)) + dev_dbg(tphy->dev, "DP tunnel %u: request %#x not released (%#x)\n", + dpin, p->req[i], s); + } + t6040_usb2_clear32(cfg + T6040_CFG_DP_CLKSWITCH_CTRL, p->sw_off); + return 0; +} + +/* All tunnel clocks down, which the PHY's shutdown of mode 2 starts with. */ +static void t6040_tun_stop_all_locked(struct t6040_usb2_phy *tphy) +{ + unsigned int dpin; + + lockdep_assert_held(&tphy->lock); + if (!tphy->tun_pll) + return; + for (dpin = 0; dpin < 2; dpin++) { + if (!tphy->tun_rate[dpin]) + continue; + tphy->tun_rate[dpin] = 0; + t6040_tun_switch(tphy, dpin, false); + } + if (tphy->tun_pre) { + tphy->tun_pre = false; + t6040_tun_switch(tphy, 0, false); + } + t6040_tun_pll_stop(tphy); + dev_info(tphy->dev, "DP tunnel clocks off\n"); +} + +static int t6040_tun_rate_locked(struct t6040_usb2_phy *tphy, unsigned int dpin, u8 rate) +{ + int sel, ret; + u8 old = tphy->tun_rate[dpin]; + + lockdep_assert_held(&tphy->lock); + if (!rate) { + if (!old) + return 0; + tphy->tun_rate[dpin] = 0; + if (dpin == 0 && tphy->tun_rate[1]) { + /* DP IN 1 keeps PCLK1 and its switch, now at its own rate. */ + tphy->tun_pre = true; + t6040_tun_select_write(tphy, 1, t6040_tun_select(tphy->tun_rate[1])); + } else { + t6040_tun_switch(tphy, dpin, false); + if (dpin == 1 && tphy->tun_pre) { + tphy->tun_pre = false; + t6040_tun_switch(tphy, 0, false); + } + } + t6040_usb2_mask32(t6040_core(tphy) + T6040_CORE_TX_DP_CTRL0, + T6040_CORE_TX_DP_CTRL0_ENABLES, t6040_tun_enables(tphy)); + if (!tphy->tun_rate[!dpin]) + t6040_tun_pll_stop(tphy); + dev_dbg(tphy->dev, "DP tunnel %u off\n", dpin); + return 0; + } + sel = t6040_tun_select(rate); + if (sel < 0) + return sel; + if (!tphy->cio_up) + return -EBUSY; + if (old == rate) + return 0; + if (!tphy->tun_pll) { + ret = t6040_tun_pll_start(tphy); + if (ret) + return ret; + } + tphy->tun_rate[dpin] = rate; + t6040_tun_select_write(tphy, dpin, sel); + /* DP IN 1 alone: switch 1 passes PCLK1, its prerequisite. */ + if (dpin == 1 && !tphy->tun_rate[0] && !tphy->tun_pre) { + ret = t6040_tun_switch(tphy, 0, true); + if (ret) + goto switch_failed; + tphy->tun_pre = true; + } else if (dpin == 0) { + tphy->tun_pre = false; /* DP IN 0 owns switch 1 again */ + } + ret = t6040_tun_switch(tphy, dpin, true); +switch_failed: + if (ret) { + dev_err(tphy->dev, "DP tunnel %u: clock switch timed out (ctrl %#x status %#x)\n", + dpin, readl(t6040_cfg(tphy) + T6040_CFG_DP_CLKSWITCH_CTRL), + readl(t6040_cfg(tphy) + T6040_CFG_DP_CLKSWITCH_STAT)); + t6040_tun_rate_locked(tphy, dpin, 0); + return ret; + } + dev_info(tphy->dev, "DP tunnel %u: rate %#x, select %d (ctrl0 %#x, pclk status %#x)\n", + dpin, rate, sel, readl(t6040_core(tphy) + T6040_CORE_TX_DP_CTRL0), + readl(t6040_core(tphy) + T6040_CORE_DP_PCLK_STATUS)); + return 0; +} + +/* + * The pixel clock of a DP tunnel for appledrm, which looks it up with symbol_get(): start the + * clock of DP IN adapter @dpin (0 or 1) at DP link rate code @rate, or stop it with 0. The + * PHY must be in CIO. A symbol of its own, as for T6050: phy-apple-atc exports + * apple_atc_dp_tunnel_rate() for the older SoCs, and both can be built into one kernel. + */ +int apple_t6040_dp_tunnel_rate(struct phy *phy, unsigned int dpin, u8 rate) +{ + struct t6040_usb2_phy *tphy; + + if (!phy || phy->ops != &t6040_dp_phy_ops || dpin > 1) + return -EINVAL; + tphy = phy_get_drvdata(phy); + guard(mutex)(&tphy->lock); + return t6040_tun_rate_locked(tphy, dpin, rate); +} +EXPORT_SYMBOL_GPL(apple_t6040_dp_tunnel_rate); + /* ---- Type-C mode switch: the Type-C controller asks for DP on a USB-C port ---- */ static int t6040_dp_mux_set(struct typec_mux_dev *mux, struct typec_mux_state *state) diff --git a/include/linux/soc/apple/dp-tunnel.h b/include/linux/soc/apple/dp-tunnel.h index 09afceeda7000..03399c9da3f2b 100644 --- a/include/linux/soc/apple/dp-tunnel.h +++ b/include/linux/soc/apple/dp-tunnel.h @@ -67,6 +67,12 @@ int apple_dcp_tb_dp_event(struct device_node *connector_np, unsigned int dpin, */ int apple_atc_dp_tunnel_rate(struct phy *phy, unsigned int dpin, u8 rate); +/* + * T6040 ATC PHY: the same for DP IN adapter @dpin (0 or 1), a symbol of its own because + * phy-apple-atc and phy-apple-t6040-usb2 can both be built. + */ +int apple_t6040_dp_tunnel_rate(struct phy *phy, unsigned int dpin, u8 rate); + /* T6030's external DPTX port 0 sources feed DP IN0/1 through PCLK1/2. */ static inline int apple_dp_tunnel_t6030_pclk(unsigned int source, unsigned int dpin) { From 196241b4d3aa3b20dc6d95d701805865ce07e3d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Mon, 16 Nov 2026 10:06:28 +0100 Subject: [PATCH 02/10] mux: apple-display-crossbar: enable the T604X ATC for a DP IN tunnel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On T6040/T6041 the crossbar's 0x34 is a per-clock UHBR select (bit n set when the link rate is UHBR) and the ATC enable of a DP IN output is at 0x38. The T6030 link wrote the ATC enable to 0x34, which set the UHBR select of an HBR2 stream and left the ATC disabled: the tunnel trained but no pixel data reached the DP IN. DP IN tunnels carry DP 1.x rates only, so clear the UHBR select and set the enable at 0x38; the DP alt mode output keeps the T6030 write. Resume checks the same register. [petr: split out of fbalazsy/linux 5e6657513 "drm/apple: T6041 display coprocessors across hibernation and S2R" (with its comment from ed490dd5f). On the J614s this took the Studio Display's video path from ~480 to ~976,000 packets/s at 1080p60, aurora-silicon/linux#1589.] Signed-off-by: František Balázsy Signed-off-by: Petr Škuta <20834920+petrskuta@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 --- drivers/mux/apple-display-crossbar.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/drivers/mux/apple-display-crossbar.c b/drivers/mux/apple-display-crossbar.c index f45d296eebef4..12e1f8a1cf789 100644 --- a/drivers/mux/apple-display-crossbar.c +++ b/drivers/mux/apple-display-crossbar.c @@ -106,6 +106,8 @@ struct apple_dpxbar_hw { bool t6030_flow; /* no UNK_TUNABLE write at probe */ bool no_tunable; + /* DP IN tunnels enable the ATC at 0x38; 0x34 selects UHBR (T604X) */ + bool t604x_dpin_atc; /* power domain held only while an output is selected */ bool runtime_pm; /* T8142 layout: a connection status still busy after its poll is only logged */ @@ -236,6 +238,14 @@ static void t602x_dump(struct apple_dpxbar *xbar, const char *tag) #define T602X_DISPEXT_ENABLE 0x02c #define T602X_MUX_SELECT 0x030 #define T602X_ATC_ENABLE 0x034 +/* + * T604X, when a connection comes up: 0x34 holds a per-clock UHBR select + * (bit n set when the link rate is UHBR, cleared when it is not) and the ATC + * is enabled at 0x38 (its bit ORed in); neither is cleared at teardown. Used + * for DP IN tunnels only: the DP alt mode output keeps the T6030 write. + */ +#define T604X_ATC_UHBR_SELECT 0x034 +#define T604X_ATC_ENABLE 0x038 /* * Field of a T6030 output in the gate, select and enable registers. DP IN 0, @@ -285,7 +295,13 @@ static void apple_dpxbar_t6030_link(struct apple_dpxbar *xbar, dpxbar_set32(xbar, T602X_FIFO_WR_DPTX_CLK_EN, u); dpxbar_set32(xbar, rd, u); dpxbar_set32(xbar, out, d); - dpxbar_set32(xbar, T602X_ATC_ENABLE, d); + if (xbar->hw->t604x_dpin_atc && index != MUX_DPPHY) { + /* DP IN tunnels carry DP 1.x rates only: no UHBR select. */ + dpxbar_clear32(xbar, T604X_ATC_UHBR_SELECT, d); + dpxbar_set32(xbar, T604X_ATC_ENABLE, d); + } else { + dpxbar_set32(xbar, T602X_ATC_ENABLE, d); + } dpxbar_set32(xbar, T602X_DISPEXT_ENABLE, u); } else { dpxbar_clear32(xbar, T602X_DISPEXT_ENABLE, u); @@ -1380,6 +1396,9 @@ static int apple_dpxbar_resume(struct device *dev) u32 shift = apple_dpxbar_t6030_shift(i); u32 mask = (0xfU << shift) | (0xfU << (shift + 12)); u32 route = (state << shift) | (state << (shift + 12)); + /* Where apple_dpxbar_t6030_link() set the ATC enable of this output. */ + u32 atc_enable_reg = xbar->hw->t604x_dpin_atc && i != MUX_DPPHY ? + T604X_ATC_ENABLE : T602X_ATC_ENABLE; if (state < 0) continue; @@ -1388,7 +1407,7 @@ static int apple_dpxbar_resume(struct device *dev) restored |= BIT(i); } if (xbar->tunnel_link_up[i] && - (!(readl(xbar->regs + T602X_ATC_ENABLE) & BIT(shift)) || + (!(readl(xbar->regs + atc_enable_reg) & BIT(shift)) || !(readl(xbar->regs + T602X_DISPEXT_ENABLE) & BIT(state)))) { xbar->tunnel_link_up[i] = false; restored |= BIT(i); @@ -1445,6 +1464,7 @@ static const struct apple_dpxbar_hw apple_dpxbar_hw_t6041 = { .ops = &apple_dpxbar_t602x_ops, .t6030_flow = true, .no_tunable = true, + .t604x_dpin_atc = true, }; /* From 0de02d8990df19ad9837a41240ff906e17c78437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0kuta?= <20834920+petrskuta@users.noreply.github.com> Date: Mon, 16 Nov 2026 10:06:41 +0100 Subject: [PATCH 03/10] thunderbolt: apple: drive displays behind T6040/T6041 DP tunnels MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Give the T6040 ACIO the M4 (T8132) DP IN policy and qualify T6040 and T6041 for DP tunnels. Their DP IN adapters take the t8103 handshake and the M3 flow, as on T8132; the pixel clock is the ATC PHY's AUSPLL (apple_t6040_dp_tunnel_rate()). Tested on the J614s (M4 Pro) with a Studio Display (2022) on the left Thunderbolt port: 1920x1080, 2560x1440 and 5120x2880 at 60 Hz, extended desktop, aurora-silicon/linux#1589. Signed-off-by: Petr Škuta <20834920+petrskuta@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 --- drivers/thunderbolt/apple.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/thunderbolt/apple.c b/drivers/thunderbolt/apple.c index be0c647b30de4..39548ce1f0e68 100644 --- a/drivers/thunderbolt/apple.c +++ b/drivers/thunderbolt/apple.c @@ -245,7 +245,8 @@ static const struct apple_cio_hw apple_cio_t6040_hw = { .lstx_after_boot = true, .strict_fw_ready = true, .no_host_clx = true, - .dp = &apple_dpin_disabled, + /* The T8132 (M4) DP IN flow; the PHY's AUSPLL is the pixel clock. */ + .dp = &apple_dpin_m4, }; #define APPLE_CIO_NHI_HOP_COUNT 0x0 @@ -630,6 +631,9 @@ static const struct of_device_id apple_dpin_qualified_soc[] = { { .compatible = "apple,t6021" }, { .compatible = "apple,t6030" }, { .compatible = "apple,t8132" }, + /* T6040/T6041 (M4 Pro/Max): M4 DP IN flow, PHY tunnel pixel clock */ + { .compatible = "apple,t6040" }, + { .compatible = "apple,t6041" }, /* T6050: t8103 DP IN handshake, M3 flow, four DP IN adapters */ { .compatible = "apple,t6050" }, {}, From d8a300c5aacbfd5e6adca9c61bb385d49635393b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0kuta?= <20834920+petrskuta@users.noreply.github.com> Date: Mon, 16 Nov 2026 10:06:48 +0100 Subject: [PATCH 04/10] drm/apple: enable a T6041 tunnel's crossbar at its first link up MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit dcp_tunnel_crossbar_up() routes the mux at the first DidChangeLinkConfiguration and enables the connection only for dcp_t602x_tunnel_route(), which never matches the T6041 crossbar on 26.6. Its clocks then stay off until a retrain runs the up path again. 1080p and 1440p got video only because the firmware retrained after the mode set; 5120x2880 keeps the trained link ("Forcing link status to true for synched-pipe config") and stayed dark with the crossbar's FIFO and pixel clocks off. Also enable the connection at the first link up for the T6041 crossbar. Tested on the J614s with a Studio Display (2022): 5120x2880@60, aurora-silicon/linux#1589. Signed-off-by: Petr Škuta <20834920+petrskuta@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 --- drivers/gpu/drm/apple/dcp-fabric.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp-fabric.c b/drivers/gpu/drm/apple/dcp-fabric.c index 5862d6f3336de..5cbad80ca42a7 100644 --- a/drivers/gpu/drm/apple/dcp-fabric.c +++ b/drivers/gpu/drm/apple/dcp-fabric.c @@ -2474,8 +2474,16 @@ int dcp_tunnel_crossbar_up(struct apple_dcp *dcp, u32 unit) ret = mux_control_try_select(route->active_xbar, route->mux_index); if (!ret) route->xbar_up = true; - /* T602X DP IN selection reserves and routes the mux only. */ - if (!ret && dcp_t602x_tunnel_route(route)) { + /* + * T602X DP IN selection reserves and routes the mux only, so the + * first link up also enables the connection. The T6041 crossbar + * (M4 Pro/Max) takes the same T6030 flow on every firmware: without + * this its clocks stay off until a retrain, and a mode set that + * keeps the trained link (5K on 26.6) never gets any video. + */ + if (!ret && (dcp_t602x_tunnel_route(route) || + of_device_is_compatible(route->active_xbar->chip->dev.parent->of_node, + "apple,t6041-display-crossbar"))) { ret = dcp_tunnel_xbar_configure(route); if (!ret) ret = dcp_dpxbar_link(route->active_xbar, true); From 07375891752a2d18e5d7c9451dd38ce3240edb4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0kuta?= <20834920+petrskuta@users.noreply.github.com> Date: Mon, 16 Nov 2026 10:16:16 +0100 Subject: [PATCH 05/10] thunderbolt: apple: run T6040's TMU in bi-directional HiFi MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit macOS runs the host router's TMU in mode 3 (bi-directional HiFi) with a Studio Display attached, and the display's router and DP OUT adapter report "Min Required TMU Mode" 3. Linux put the J614s host in uni-directional LowRes and left the display's router alone because it already read as bi-directional HiFi, so the host's time was never posted to it. The display then dropped HPD one second into 5120x2880@60 ("IOAVVideoInterface terminated ... display HPD removed"). Add QUIRK_TMU_HIFI_BI: the host router configured for bi-directional HiFi, and every device router configured, disabled, given the host's time and enabled again. Set it for T6040/T6041. Signed-off-by: Petr Škuta <20834920+petrskuta@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 --- drivers/thunderbolt/apple.c | 10 ++++++++++ drivers/thunderbolt/nhi.h | 6 ++++++ drivers/thunderbolt/tb.c | 25 +++++++++++++++++++++++-- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/drivers/thunderbolt/apple.c b/drivers/thunderbolt/apple.c index 39548ce1f0e68..12b85380c8c91 100644 --- a/drivers/thunderbolt/apple.c +++ b/drivers/thunderbolt/apple.c @@ -171,6 +171,8 @@ struct apple_cio_hw { bool gen4_link_recovery; /* Leave the host router's TMU to its firmware; host TMU constants. */ bool host_tmu; + /* Every router's TMU in bi-directional HiFi, as macOS runs it. */ + bool tmu_hifi_bi; const struct apple_dpin_policy *dp; }; @@ -245,6 +247,12 @@ static const struct apple_cio_hw apple_cio_t6040_hw = { .lstx_after_boot = true, .strict_fw_ready = true, .no_host_clx = true, + /* + * macOS runs the host's TMU in bi-directional HiFi with a Studio + * Display attached, whose DP OUT adapter requires it (Min Required TMU + * Mode 3); without it the display drops HPD a second into 5K. + */ + .tmu_hifi_bi = true, /* The T8132 (M4) DP IN flow; the PHY's AUSPLL is the pixel clock. */ .dp = &apple_dpin_m4, }; @@ -2710,6 +2718,8 @@ static int apple_nhi_probe(struct platform_device *pdev) anhi->nhi.quirks |= QUIRK_GEN4_LINK_RECOVERY; if (acio->hw->host_tmu) anhi->nhi.quirks |= QUIRK_HOST_TMU; + if (acio->hw->tmu_hifi_bi) + anhi->nhi.quirks |= QUIRK_TMU_HIFI_BI; /* * TEST: T6050 takes the vendor sleep and the state transfer as the J713 does (macOS, diff --git a/drivers/thunderbolt/nhi.h b/drivers/thunderbolt/nhi.h index 8770e398acb03..d4b9374c8d1e3 100644 --- a/drivers/thunderbolt/nhi.h +++ b/drivers/thunderbolt/nhi.h @@ -256,6 +256,12 @@ struct tb_nhi_ops { * and routers are enumerated with a 10 ms notification timeout. */ #define QUIRK_CIO_MACOS_FRAMES BIT(14) +/* + * The host router and every device router run their TMU in bi-directional + * HiFi mode, as macOS does: a DP OUT adapter may require it to recover its + * stream clock. + */ +#define QUIRK_TMU_HIFI_BI BIT(15) /* Host display policies are independent of which optional hooks are installed. */ #define TB_HOST_DP_NOTIFY BIT(0) diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c index 074ce00efdf1c..d04c86e07a270 100644 --- a/drivers/thunderbolt/tb.c +++ b/drivers/thunderbolt/tb.c @@ -363,6 +363,24 @@ static int tb_enable_tmu(struct tb_switch *sw) { int ret; + /* + * Bi-directional HiFi everywhere (host router set in tb_start()). A + * device router may already read as bi-directional HiFi without the + * host's time: enable it from scratch with the time posted. + */ + if ((sw->tb->nhi->quirks & QUIRK_TMU_HIFI_BI) && tb_route(sw)) { + ret = tb_switch_tmu_configure(sw, TB_SWITCH_TMU_MODE_HIFI_BI); + if (ret) + return ret; + ret = tb_switch_tmu_disable(sw); + if (ret) + return ret; + ret = tb_switch_tmu_post_time(sw); + if (ret) + return ret; + return tb_switch_tmu_enable(sw); + } + /* The host router's firmware runs its TMU on these hosts. */ if (!tb_route(sw) && tb_switch_tmu_host_managed(sw)) return 0; @@ -3985,10 +4003,13 @@ static int tb_start(struct tb *tb, bool reset) /* * To support highest CLx state, we set host router's TMU to - * Normal mode. + * Normal mode, unless the host runs bi-directional HiFi. */ if (!tb_switch_tmu_host_managed(tb->root_switch)) { - tb_switch_tmu_configure(tb->root_switch, TB_SWITCH_TMU_MODE_LOWRES); + tb_switch_tmu_configure(tb->root_switch, + (tb->nhi->quirks & QUIRK_TMU_HIFI_BI) ? + TB_SWITCH_TMU_MODE_HIFI_BI : + TB_SWITCH_TMU_MODE_LOWRES); /* Enable TMU if it is off */ tb_switch_tmu_enable(tb->root_switch); } From 2926f23dfb11213f9dacd876b41f7168089d258d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0kuta?= <20834920+petrskuta@users.noreply.github.com> Date: Mon, 16 Nov 2026 10:33:12 +0100 Subject: [PATCH 06/10] phy: apple: t6040: release both AUSPLL clock outputs when a tunnel stops MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The tunnel's AUSPLL start sets CLKOUT_MASTER 0x808 and refuses to start while either bit is set ('already in use'), but the stop cleared only 0x8. After the first stop, e.g. a DPMS off of a Studio Display, the tunnel clock could not start again: DP tunnel: AUSPLL already in use (master 0x81d54, cmd 0x10000018) DP tunnel pixel clock (rate 0x14) failed: -16 and the display stayed dark after DPMS on. Clear both outputs. Signed-off-by: Petr Škuta <20834920+petrskuta@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 --- drivers/phy/apple/t6040-usb2.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/phy/apple/t6040-usb2.c b/drivers/phy/apple/t6040-usb2.c index 9b4a9262e1b9c..ba933da64a02a 100644 --- a/drivers/phy/apple/t6040-usb2.c +++ b/drivers/phy/apple/t6040-usb2.c @@ -2043,7 +2043,8 @@ static void t6040_tun_pll_stop(struct t6040_usb2_phy *tphy) dev_warn(tphy->dev, "DP tunnel: AUSPLL release timed out (cmd %#x, pclk status %#x)\n", readl(core + T6040_CORE_AUSPLL_CMD), readl(core + T6040_CORE_DP_PCLK_STATUS)); - t6040_usb2_clear32(core + T6040_CORE_AUSPLL_CLKOUT_MASTER, 0x8); + /* Both outputs the start set: a stale 0x800 reads as "in use" next time. */ + t6040_usb2_clear32(core + T6040_CORE_AUSPLL_CLKOUT_MASTER, 0x808); tphy->tun_pll = false; } From d64847a3514e194cb5bf7c90292ed987c675f035 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Fri, 13 Nov 2026 15:48:18 +0100 Subject: [PATCH 07/10] tools: asahi: model the T6040 tunnel clock in the T6030 clock host test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The host test extracts dcp_route_clock_rate() from the display fabric and builds it on its own. The fabric now calls the T6040 PHY's own tunnel clock symbol on T6040 and T6041, so the test needs that helper and a model of the symbol. Extract dcp_fabric_t6040_tunnel_clock() with the other fabric functions, stub apple_t6040_dp_tunnel_rate() and add a case that runs both machines through DP IN 0 and 1: the rate reaches the T6040 symbol with the right adapter, neither the ATC nor the T6050 provider is called, and a clock that fails to start leaves the route's rate alone. Signed-off-by: František Balázsy Signed-off-by: Petr Škuta <20834920+petrskuta@users.noreply.github.com> --- tools/asahi/t6030-clock-tests.py | 4 ++-- tools/asahi/t6030-clock/fixture.c | 36 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/tools/asahi/t6030-clock-tests.py b/tools/asahi/t6030-clock-tests.py index 1c26aee6b8718..77bea106500df 100644 --- a/tools/asahi/t6030-clock-tests.py +++ b/tools/asahi/t6030-clock-tests.py @@ -21,14 +21,14 @@ 'atc_t8122_tunnel_stop', 'atc_t8122_tunnel_pclk', 'atc_t8122_tunnel_start', 'apple_atc_dp_tunnel_rate_source'], 'drivers/gpu/drm/apple/dcp-fabric.c': [ - 'dcp_route_clock_rate', 'dcp_tunnel_set_rate'], + 'dcp_fabric_t6040_tunnel_clock', 'dcp_route_clock_rate', 'dcp_tunnel_set_rate'], } CASES = ['dual-start', 'reverse-start', 'stop-second', 'same-rate', 'stale-owner', 'same-source', 'retune-one', 'busy-mode', 'busy-pll', 'invalid-source', 'invalid-rate', 'wrong-generation', 'failed-cleanup', 'failed-final-stop', 'stale-ack', 'unflagged-ack'] CASES += ['fail-start-' + str(i) for i in range(4)] -CASES += ['t6050-dpin-clocks'] +CASES += ['t6050-dpin-clocks', 't6040-tunnel-clock'] def function(source, name): match = re.search(r'^(?:static\s+)?(?:inline\s+)?(?:unsigned\s+)?(?:int|void|bool)\s+' + name + diff --git a/tools/asahi/t6030-clock/fixture.c b/tools/asahi/t6030-clock/fixture.c index 3efdc838fe8d1..ce276bd92c831 100644 --- a/tools/asahi/t6030-clock/fixture.c +++ b/tools/asahi/t6030-clock/fixture.c @@ -138,6 +138,18 @@ static int apple_t6050_dp_tunnel_clock(struct phy *p, unsigned clock, u8 rate) t6050_rate = rate; return t6050_error; } +/* T6040 ATC PHY (t6040-usb2.c): one pixel clock per DP IN adapter (0 or 1), recorded. */ +static unsigned t6040_calls, t6040_dpin; +static u8 t6040_rate; +static int t6040_error; +static int apple_t6040_dp_tunnel_rate(struct phy *p, unsigned dpin, u8 rate) +{ + assert(!strcmp(machine, "apple,t6040") || !strcmp(machine, "apple,t6041")); + t6040_calls++; + t6040_dpin = dpin; + t6040_rate = rate; + return t6040_error; +} /* * Production: of_device_is_compatible(dcp->dev->of_node, "apple,t8132-dcpext"). * These are T6030 DCPs: the T8132 dcpext paths must never be taken. @@ -275,6 +287,30 @@ int main(int argc, char **argv) printf("PASS %s: DP IN n on tunnel clock n + 1, rate kept only when set\n", name); return 0; } + if (!strcmp(name, "t6040-tunnel-clock")) { + /* T6040 and T6041 use the PHY's own symbol, not the ATC one nor the T6050 one. */ + const char *const machines[] = { "apple,t6040", "apple,t6041" }; + u8 route_rate; + for (unsigned m = 0; m < 2; m++) { + machine = machines[m]; + t6040_calls = 0; + t6040_error = 0; + for (unsigned dpin = 0; dpin < 2; dpin++) { + assert(!t6050_clock_call(&phy, dpin, 0x1e, &route_rate)); + assert(t6040_dpin == dpin && t6040_rate == 0x1e && route_rate == 0x1e); + assert(!t6050_clock_call(&phy, dpin, 0, &route_rate)); + assert(t6040_dpin == dpin && !t6040_rate && !route_rate); + } + assert(t6040_calls == 4); + /* A clock that failed to start leaves the route's rate alone. */ + t6040_error = -ETIMEDOUT; + assert(t6050_clock_call(&phy, 1, 0x14, &route_rate) == -ETIMEDOUT && + route_rate == 0x55); + } + assert(!t6050_calls && !writes && !polls && !crossbar_stops); + printf("PASS %s: T6040/T6041 tunnel clock through apple_t6040_dp_tunnel_rate\n", name); + return 0; + } if (!strcmp(name, "wrong-generation")) { hw.gen = ATCPHY_GENERATION_T8103; assert(clock_call(&phy, 0, 0, 0x14) == -EOPNOTSUPP && !writes); From b491b4912e0142ab52c2968d639a78d0b7dc8693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0kuta?= <20834920+petrskuta@users.noreply.github.com> Date: Mon, 16 Nov 2026 10:07:08 +0100 Subject: [PATCH 08/10] PCI: apple: T6040 PCIe-C is an Intr2AXI controller MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit t6040_pciec_hw was modelled on T8132: the kernel_init (oe-fabric) cold init, the T8132 port reset values and SID-indexed RID2SID slots. The ADT's apciec,t6040 has no oe-fabric region (config, rc, port0, fabric, debug, ioa, ltssm, intr2axi), so cold init failed mapping it (-ENODATA). Its fabric, rc, debug, config and DART tunables are T6050's with small value differences. Make it an Intr2AXI controller with T6050's no_port_reset, and allocate RID2SID slots as T6050 does: with iommu-map-mask 0xff the Studio Display's xHCI (RID 0x300) and its Thunderbolt bridge (RID 0x100) share SID 0, and an SID-indexed slot failed the xHCI's enable with a silent -EBUSY ("Can't enable PCI device, BIOS handoff failed"). Tested on the J614s with a Studio Display (2022) on the left port: cold init completes (link up), the display's Titan Ridge bridges and xHCI enumerate and xhci_hcd binds, aurora-silicon/linux#1589. Signed-off-by: Petr Škuta <20834920+petrskuta@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 --- drivers/pci/controller/pcie-apple.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c index a3671bf39d196..b2224f9fe6930 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -432,6 +432,16 @@ static const struct hw_info t8132_pciec_hw = { .s2idle_hold_domain = true, }; +/* + * T6040 PCIe-C is an Intr2AXI controller like T6050: the ADT + * (apciec,t6040) has no oe-fabric region, and its fabric/rc/debug/config and + * DART tunables are T6050's with small value differences. Cold init therefore + * takes the T6050 path (no port reset sequence, RID2SID cleared only). + * RID2SID slots are allocated as on T6050, not indexed by SID: with + * iommu-map-mask 0xff a device behind the tunnel (e.g. 03:00.0, the + * Studio Display's xHCI) shares SID 0 with 01:00.0, and an indexed slot + * then fails its enable with -EBUSY. + */ static const struct hw_info t6040_pciec_hw = { .port_msiaddr = PORT_MSIADDR, .port_msiaddr_hi = PORT_MSIADDR + 4, @@ -440,9 +450,9 @@ static const struct hw_info t6040_pciec_hw = { .port_msimap = PORT_T602X_MSIMAP, .port_tunctrl = 0x1088, .max_rid2sid = 256, - .sid_indexed_rid2sid = true, .tunneled = true, - .t8132_reset = true, + .tunnel_intr2axi = true, + .no_port_reset = true, .msimap_by_vector = true, .s2idle_hold_domain = true, }; From d2da57d2346e3ec4f780325fe875fcc5dac5a9bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0kuta?= <20834920+petrskuta@users.noreply.github.com> Date: Mon, 16 Nov 2026 10:07:23 +0100 Subject: [PATCH 09/10] arm64: dts: apple: t6040-j614s: PCIe-C on the left Thunderbolt port MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enable the left port's tunneled PCIe (usb4_0_pcie_tunnel, apciec0_dart, usb4_0_pcie) and keep the ACIO's apple,pcie-tunnel, so a Thunderbolt device's PCIe functions reach a root port. No boot loader hands the port over, so the kernel cold-initializes it (apple,pciec-kernel-init). From the j614s ADT (macOS 26 IODeviceTree) apciec0 and dart-apciec0: - the controller's fabric, rc and debug tunables and the port's config tunables; - the DART's tunables and its DMA window: vm-base 1 TiB + 2 GiB, vm-size 0x7ff00000, the first 16 KiB a dead mapping; - bypass streams 253 and 255 (bypass-253, bypass-255): the port's own writes, its MSIs turned into AIC writes, use them. Without the bypass no MSI arrived (xHCI "Command Aborted") and the DART fault IRQ stormed. As on T6050's PCIe-C DART: full error reporting, CTC flush and the ATC0 PCIe power domain. Tested on the J614s with a Studio Display (2022): its USB2 and USB3 Gen2 hubs, speakers and microphones (snd-usb-audio), camera (uvcvideo), HID and a USB-C port (a USB 3.1 drive at 5 Gb/s) work, aurora-silicon/linux#1589. Signed-off-by: Petr Škuta <20834920+petrskuta@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 --- arch/arm64/boot/dts/apple/t6040-j614s.dts | 85 ++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/apple/t6040-j614s.dts b/arch/arm64/boot/dts/apple/t6040-j614s.dts index 2d4bd56b1ba99..4a3b8a857f2f9 100644 --- a/arch/arm64/boot/dts/apple/t6040-j614s.dts +++ b/arch/arm64/boot/dts/apple/t6040-j614s.dts @@ -131,7 +131,6 @@ }; &usb4_0_acio { - /delete-property/ apple,pcie-tunnel; status = "okay"; }; @@ -145,6 +144,90 @@ status = "okay"; }; +/* + * The left port's PCIe-C (tunneled PCIe), e.g. the Studio Display's xHCI. + * No boot loader hands it over: the kernel cold-initializes it. + */ +&usb4_0_pcie_tunnel { + status = "okay"; +}; + +/* Tunables: the j614s ADT (macOS 26 IODeviceTree) dart-apciec0 and apciec0. */ +&apciec0_dart { + /* + * ADT dart-apciec0 vm-base 1 TiB + 2 GiB, vm-size 0x7ff00000, its first + * 16 KiB a dead mapping: the tunnel's devices address DMA only there. + */ + apple,dma-range = <0x100 0x80004000 0x0 0x7fefc000>; + /* + * As T6050's PCIe-C DART: the port's own writes (MSIs turned into AIC + * writes) use reserved streams 253 and 255 (ADT bypass-253, bypass-255), + * which must bypass; and report every error class. + */ + power-domains = <&ps_atc0_pcie>; + apple,bypass-sids = <253 255>; + apple,full-error-reporting; + apple,ctc-flush; + apple,tunable = <0x20c 0x80000121 0x80000121>, + <0x220 0xf0f0f 0xf0f0f>, + <0x224 0xffffff 0x80808>, + <0x300 0x1f31 0x1>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>; + status = "okay"; +}; + +&usb4_0_pcie { + apple,pciec-kernel-init; + apple,tunable-debug = <0x1000 0x1 0x0>; + apple,tunable-rc = <0x78 0x7000 0x0>, + <0x718 0x7c000 0x0>, + <0x814 0xffffffff 0x2000f060>, + <0x8bc 0x1 0x0>; + apple,tunable-fabric = <0x4 0x1f001f 0x100010>, + <0x8 0x1 0x1>, + <0xc 0x1 0x1>, + <0x10 0x801f 0x4>, + <0x18 0xff 0xe0>, + <0x1c 0x1 0x1>, + <0x20 0x801f 0x4>, + <0x28 0x1f 0x10>, + <0x2c 0x801f 0x4>, + <0x34 0x3f 0x20>, + <0x38 0x801f 0x4>, + <0x40 0x3f 0x20>, + <0x44 0x801f 0x4>, + <0x4c 0x10001 0x10001>, + <0x50 0x1 0x1>, + <0x54 0x1 0x1>, + <0x58 0x801f 0x4>, + <0x60 0x7f007f 0x450045>, + <0x64 0x801f 0x4>, + <0x6c 0x1f001f 0x100010>, + <0x70 0xf1 0x1>, + <0x74 0x801f 0x4>, + <0x7c 0x801f 0x4>, + <0x84 0x1 0x1>, + <0x88 0x1 0x1>, + <0x8c 0x801f 0x4>, + <0x94 0x1 0x1>, + <0x98 0x801f 0x4>, + <0xa0 0x1 0x1>, + <0xa4 0x801f 0x4>, + <0xac 0x1 0x1>, + <0xb0 0x1 0x1>, + <0xb4 0x801f 0x4>, + <0xbc 0x801f 0x4>, + <0xc4 0x801f 0x4>; + status = "okay"; +}; + +&usb4_0_pcie_port { + apple,tunable = <0x140 0x1 0x1>, + <0x2a0 0x7e 0xa>, + <0x1090 0x1 0x0>; +}; + &ps_atc1_cio { status = "okay"; }; From b19f2476f17a77b613fb71943e5bb9e52a3854c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0kuta?= <20834920+petrskuta@users.noreply.github.com> Date: Mon, 16 Nov 2026 13:47:21 +0100 Subject: [PATCH 10/10] arm64: dts: apple: t6040-j614s: PCIe-C on all three Thunderbolt ports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ADT's apciec0-2 and dart-apciec0-2 carry identical tunables, DMA windows and bypass streams, so describe the PCIe-C of the left port once in t6040-j614s-pciec.dtsi and use it for all three ports. Port 0 is unchanged; ports 1 and 2 keep their ACIO's apple,pcie-tunnel now. Signed-off-by: Petr Škuta <20834920+petrskuta@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 --- .../boot/dts/apple/t6040-j614s-pciec.dtsi | 94 +++++++++++++++++++ arch/arm64/boot/dts/apple/t6040-j614s.dts | 87 +---------------- 2 files changed, 95 insertions(+), 86 deletions(-) create mode 100644 arch/arm64/boot/dts/apple/t6040-j614s-pciec.dtsi diff --git a/arch/arm64/boot/dts/apple/t6040-j614s-pciec.dtsi b/arch/arm64/boot/dts/apple/t6040-j614s-pciec.dtsi new file mode 100644 index 0000000000000..9e131830b8663 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t6040-j614s-pciec.dtsi @@ -0,0 +1,94 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * J614s: PCIe-C (tunneled PCIe) on the three Thunderbolt ports, e.g. a + * Studio Display's xHCI. No boot loader hands the ports over: the kernel + * cold-initializes them. + * + * From the j614s ADT (macOS 26 IODeviceTree), identical for apciec0-2 and + * dart-apciec0-2: + * - the DART's DMA window: vm-base 1 TiB + 2 GiB, vm-size 0x7ff00000, its + * first 16 KiB a dead mapping; + * - bypass-253 and bypass-255: the port's own writes (MSIs turned into AIC + * writes) use those reserved streams, which must bypass, as on T6050; + * - the DART tunables, the controller's debug, rc and fabric tunables and + * the port's config tunables. + * Full error reporting, CTC flush and the ATC PCIe power domain as on + * T6050's PCIe-C DART. + */ + +#define J614S_PCIEC(n) \ +&usb4_##n##_pcie_tunnel { \ + status = "okay"; \ +}; \ + \ +&apciec##n##_dart { \ + apple,dma-range = <0x100 0x80004000 0x0 0x7fefc000>; \ + power-domains = <&ps_atc##n##_pcie>; \ + apple,bypass-sids = <253 255>; \ + apple,full-error-reporting; \ + apple,ctc-flush; \ + apple,tunable = <0x20c 0x80000121 0x80000121>, \ + <0x220 0xf0f0f 0xf0f0f>, \ + <0x224 0xffffff 0x80808>, \ + <0x300 0x1f31 0x1>, \ + <0x308 0x3ffffffc 0x10000000>, \ + <0x310 0x3ffffffc 0x3ffffffc>; \ + status = "okay"; \ +}; \ + \ +&usb4_##n##_pcie { \ + apple,pciec-kernel-init; \ + apple,tunable-debug = <0x1000 0x1 0x0>; \ + apple,tunable-rc = <0x78 0x7000 0x0>, \ + <0x718 0x7c000 0x0>, \ + <0x814 0xffffffff 0x2000f060>, \ + <0x8bc 0x1 0x0>; \ + apple,tunable-fabric = <0x4 0x1f001f 0x100010>, \ + <0x8 0x1 0x1>, \ + <0xc 0x1 0x1>, \ + <0x10 0x801f 0x4>, \ + <0x18 0xff 0xe0>, \ + <0x1c 0x1 0x1>, \ + <0x20 0x801f 0x4>, \ + <0x28 0x1f 0x10>, \ + <0x2c 0x801f 0x4>, \ + <0x34 0x3f 0x20>, \ + <0x38 0x801f 0x4>, \ + <0x40 0x3f 0x20>, \ + <0x44 0x801f 0x4>, \ + <0x4c 0x10001 0x10001>, \ + <0x50 0x1 0x1>, \ + <0x54 0x1 0x1>, \ + <0x58 0x801f 0x4>, \ + <0x60 0x7f007f 0x450045>, \ + <0x64 0x801f 0x4>, \ + <0x6c 0x1f001f 0x100010>, \ + <0x70 0xf1 0x1>, \ + <0x74 0x801f 0x4>, \ + <0x7c 0x801f 0x4>, \ + <0x84 0x1 0x1>, \ + <0x88 0x1 0x1>, \ + <0x8c 0x801f 0x4>, \ + <0x94 0x1 0x1>, \ + <0x98 0x801f 0x4>, \ + <0xa0 0x1 0x1>, \ + <0xa4 0x801f 0x4>, \ + <0xac 0x1 0x1>, \ + <0xb0 0x1 0x1>, \ + <0xb4 0x801f 0x4>, \ + <0xbc 0x801f 0x4>, \ + <0xc4 0x801f 0x4>; \ + status = "okay"; \ +}; \ + \ +&usb4_##n##_pcie_port { \ + apple,tunable = <0x140 0x1 0x1>, \ + <0x2a0 0x7e 0xa>, \ + <0x1090 0x1 0x0>; \ +}; + +J614S_PCIEC(0) +J614S_PCIEC(1) +J614S_PCIEC(2) + +#undef J614S_PCIEC diff --git a/arch/arm64/boot/dts/apple/t6040-j614s.dts b/arch/arm64/boot/dts/apple/t6040-j614s.dts index 4a3b8a857f2f9..73b76db059b18 100644 --- a/arch/arm64/boot/dts/apple/t6040-j614s.dts +++ b/arch/arm64/boot/dts/apple/t6040-j614s.dts @@ -144,90 +144,6 @@ status = "okay"; }; -/* - * The left port's PCIe-C (tunneled PCIe), e.g. the Studio Display's xHCI. - * No boot loader hands it over: the kernel cold-initializes it. - */ -&usb4_0_pcie_tunnel { - status = "okay"; -}; - -/* Tunables: the j614s ADT (macOS 26 IODeviceTree) dart-apciec0 and apciec0. */ -&apciec0_dart { - /* - * ADT dart-apciec0 vm-base 1 TiB + 2 GiB, vm-size 0x7ff00000, its first - * 16 KiB a dead mapping: the tunnel's devices address DMA only there. - */ - apple,dma-range = <0x100 0x80004000 0x0 0x7fefc000>; - /* - * As T6050's PCIe-C DART: the port's own writes (MSIs turned into AIC - * writes) use reserved streams 253 and 255 (ADT bypass-253, bypass-255), - * which must bypass; and report every error class. - */ - power-domains = <&ps_atc0_pcie>; - apple,bypass-sids = <253 255>; - apple,full-error-reporting; - apple,ctc-flush; - apple,tunable = <0x20c 0x80000121 0x80000121>, - <0x220 0xf0f0f 0xf0f0f>, - <0x224 0xffffff 0x80808>, - <0x300 0x1f31 0x1>, - <0x308 0x3ffffffc 0x10000000>, - <0x310 0x3ffffffc 0x3ffffffc>; - status = "okay"; -}; - -&usb4_0_pcie { - apple,pciec-kernel-init; - apple,tunable-debug = <0x1000 0x1 0x0>; - apple,tunable-rc = <0x78 0x7000 0x0>, - <0x718 0x7c000 0x0>, - <0x814 0xffffffff 0x2000f060>, - <0x8bc 0x1 0x0>; - apple,tunable-fabric = <0x4 0x1f001f 0x100010>, - <0x8 0x1 0x1>, - <0xc 0x1 0x1>, - <0x10 0x801f 0x4>, - <0x18 0xff 0xe0>, - <0x1c 0x1 0x1>, - <0x20 0x801f 0x4>, - <0x28 0x1f 0x10>, - <0x2c 0x801f 0x4>, - <0x34 0x3f 0x20>, - <0x38 0x801f 0x4>, - <0x40 0x3f 0x20>, - <0x44 0x801f 0x4>, - <0x4c 0x10001 0x10001>, - <0x50 0x1 0x1>, - <0x54 0x1 0x1>, - <0x58 0x801f 0x4>, - <0x60 0x7f007f 0x450045>, - <0x64 0x801f 0x4>, - <0x6c 0x1f001f 0x100010>, - <0x70 0xf1 0x1>, - <0x74 0x801f 0x4>, - <0x7c 0x801f 0x4>, - <0x84 0x1 0x1>, - <0x88 0x1 0x1>, - <0x8c 0x801f 0x4>, - <0x94 0x1 0x1>, - <0x98 0x801f 0x4>, - <0xa0 0x1 0x1>, - <0xa4 0x801f 0x4>, - <0xac 0x1 0x1>, - <0xb0 0x1 0x1>, - <0xb4 0x801f 0x4>, - <0xbc 0x801f 0x4>, - <0xc4 0x801f 0x4>; - status = "okay"; -}; - -&usb4_0_pcie_port { - apple,tunable = <0x140 0x1 0x1>, - <0x2a0 0x7e 0xa>, - <0x1090 0x1 0x0>; -}; - &ps_atc1_cio { status = "okay"; }; @@ -249,7 +165,6 @@ }; &usb4_1_acio { - /delete-property/ apple,pcie-tunnel; status = "okay"; }; @@ -284,7 +199,6 @@ }; &usb4_2_acio { - /delete-property/ apple,pcie-tunnel; status = "okay"; }; @@ -299,3 +213,4 @@ }; #include "t6040-j614s-extdisp-hdmi.dtsi" +#include "t6040-j614s-pciec.dtsi"