Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions arch/arm64/boot/dts/apple/t6040-j614s-pciec.dtsi
Original file line number Diff line number Diff line change
@@ -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
4 changes: 1 addition & 3 deletions arch/arm64/boot/dts/apple/t6040-j614s.dts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@
};

&usb4_0_acio {
/delete-property/ apple,pcie-tunnel;
status = "okay";
};

Expand Down Expand Up @@ -166,7 +165,6 @@
};

&usb4_1_acio {
/delete-property/ apple,pcie-tunnel;
status = "okay";
};

Expand Down Expand Up @@ -201,7 +199,6 @@
};

&usb4_2_acio {
/delete-property/ apple,pcie-tunnel;
status = "okay";
};

Expand All @@ -216,3 +213,4 @@
};

#include "t6040-j614s-extdisp-hdmi.dtsi"
#include "t6040-j614s-pciec.dtsi"
55 changes: 48 additions & 7 deletions drivers/gpu/drm/apple/dcp-fabric.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2451,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);
Expand Down Expand Up @@ -3066,12 +3097,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) {
Expand Down
24 changes: 22 additions & 2 deletions drivers/mux/apple-display-crossbar.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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,
};

/*
Expand Down
14 changes: 12 additions & 2 deletions drivers/pci/controller/pcie-apple.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
};
Expand Down
Loading
Loading