From 1a0ebea2d713f53a34e4ef772e40a1804516d493 Mon Sep 17 00:00:00 2001 From: Roberto Dantas <7robertodantas@gmail.com> Date: Thu, 26 Nov 2026 15:14:24 -0300 Subject: [PATCH 1/2] soc: apple: display-gate: take dcpext3's Type-C routes from the device tree The M4 Max dcpext3 chain names its Type-C routes by path: three, for the three USB-C ports of the J614c/J616c. A board with another number of ports needs another list, and the J575c, with four back Type-C ports, would leave its fourth route disabled. Take the routes from the processor's typec-routes node instead. Each child is enabled with the chain, just before the processor, as the listed routes were, and the chain is only ready while the typec-routes container is present, non-empty, and every route is still disabled. Application also refuses a missing or empty typec-routes container so an incomplete DTB leaves the whole changeset untouched. On the J614c/J616c the chain enables the same nodes, in the same order, as before. The KUnit chain check now covers the routes taken from the tree, and new cases cover a fourth route (positive control) as well as missing and empty typec-routes containers (negative controls). Signed-off-by: Roberto Dantas <7robertodantas@gmail.com> --- drivers/soc/apple/display-gate-test.c | 78 +++++++++++++++++++++++- drivers/soc/apple/display-gate.c | 87 +++++++++++++++++++++++++-- 2 files changed, 159 insertions(+), 6 deletions(-) diff --git a/drivers/soc/apple/display-gate-test.c b/drivers/soc/apple/display-gate-test.c index cff3298d1ee57..58e96acb602af 100644 --- a/drivers/soc/apple/display-gate-test.c +++ b/drivers/soc/apple/display-gate-test.c @@ -1440,10 +1440,22 @@ static void __init gt_max_fill(struct kunit *test, unsigned int i) static void __init gt_max_expect_chain(struct kunit *test, unsigned int i, bool enabled) { const struct gate_staged *st = &t6041_max_stages[i]; - unsigned int n; + struct device_node *routes, *route; + unsigned int n, nr_routes = 0; for (n = 0; n < st->nr; n++) KUNIT_EXPECT_EQ_MSG(test, gt_okay(test, st->nodes[n]), enabled, "%s", st->nodes[n]); + if (!st->dt_routes) + return; + /* A chain that takes its routes from the tree has every one of them. */ + routes = staged_routes(st); + KUNIT_ASSERT_NOT_NULL(test, routes); + for_each_child_of_node(routes, route) { + KUNIT_EXPECT_EQ_MSG(test, of_device_is_available(route), enabled, "%pOF", route); + nr_routes++; + } + of_node_put(routes); + KUNIT_EXPECT_GT(test, nr_routes, 0); } /* @@ -1525,6 +1537,67 @@ static void __init gate_t6041_max_all_externals(struct kunit *test) gt_max_expect_display(test, BIT(0) | BIT(1) | BIT(2) | BIT(3)); } +/* + * dcpext3 takes its routes from the tree: with a route to a fourth Type-C port, + * as the J575c has, that route comes up with the chain too. + */ +static void __init gate_t6041_max_dt_routes(struct kunit *test) +{ + struct gate_test *t = test->priv; + struct device_node *route; + + route = of_changeset_create_node(&t->cs, gt_node(test, "/dcp@306e00000/typec-routes"), + "route@3"); + KUNIT_ASSERT_NOT_NULL(test, route); + KUNIT_ASSERT_EQ(test, of_changeset_add_prop_u32(&t->cs, route, "reg", 3), 0); + KUNIT_ASSERT_EQ(test, of_changeset_add_prop_string(&t->cs, route, "status", "disabled"), 0); + gt_max_fill(test, 3); + gt_max_run(test); + gt_max_expect_chain(test, 3, true); + KUNIT_EXPECT_TRUE(test, gt_okay(test, "/dcp@306e00000/typec-routes/route@3")); + gt_max_expect_display(test, BIT(3)); +} + +static void __init gt_max_expect_dt_routes_refused(struct kunit *test) +{ + const struct gate_staged *st = &t6041_max_stages[3]; + struct device_node *display = gt_node(test, "/display-subsystem"); + unsigned int n; + + gt_max_fill(test, 3); + gt_max_run(test); + for (n = 0; n < st->nr; n++) + KUNIT_EXPECT_FALSE_MSG(test, gt_okay(test, st->nodes[n]), "%s", st->nodes[n]); + gt_max_expect_display(test, 0); + + /* Direct application refuses it too and leaves the changeset untouched. */ + if (gt_okay(test, st->nodes[st->nr - 1])) + return; + KUNIT_EXPECT_EQ(test, t6041_max_apply(3, display), -ENODEV); + for (n = 0; n < st->nr; n++) + KUNIT_EXPECT_FALSE_MSG(test, gt_okay(test, st->nodes[n]), "%s", st->nodes[n]); + gt_max_expect_display(test, 0); +} + +/* A dt_routes stage whose typec-routes container is missing stays off whole. */ +static void __init gate_t6041_max_dt_routes_missing(struct kunit *test) +{ + gt_detach(test, "/dcp@306e00000/typec-routes/route@0"); + gt_detach(test, "/dcp@306e00000/typec-routes/route@1"); + gt_detach(test, "/dcp@306e00000/typec-routes/route@2"); + gt_detach(test, "/dcp@306e00000/typec-routes"); + gt_max_expect_dt_routes_refused(test); +} + +/* A dt_routes stage whose typec-routes container has no routes stays off whole. */ +static void __init gate_t6041_max_dt_routes_empty(struct kunit *test) +{ + gt_detach(test, "/dcp@306e00000/typec-routes/route@0"); + gt_detach(test, "/dcp@306e00000/typec-routes/route@1"); + gt_detach(test, "/dcp@306e00000/typec-routes/route@2"); + gt_max_expect_dt_routes_refused(test); +} + /* The other processor's chain does not wait for one that was refused. */ static void __init gate_t6041_max_one_processor(struct kunit *test) { @@ -1646,6 +1719,9 @@ static struct kunit_case gate_t6041_max_cases[] __refdata = { KUNIT_CASE(gate_t6041_max_no_memory), KUNIT_CASE(gate_t6041_max_second_usbc), KUNIT_CASE(gate_t6041_max_all_externals), + KUNIT_CASE(gate_t6041_max_dt_routes), + KUNIT_CASE(gate_t6041_max_dt_routes_missing), + KUNIT_CASE(gate_t6041_max_dt_routes_empty), KUNIT_CASE(gate_t6041_max_one_processor), KUNIT_CASE(gate_t6041_max_partial_memory), KUNIT_CASE(gate_t6041_max_enabled_by_loader), diff --git a/drivers/soc/apple/display-gate.c b/drivers/soc/apple/display-gate.c index 9a326030f9ead..53c816e951523 100644 --- a/drivers/soc/apple/display-gate.c +++ b/drivers/soc/apple/display-gate.c @@ -2384,8 +2384,27 @@ struct gate_staged { const char *dart; /* display DART of this stage */ const char *const *nodes; unsigned int nr; + /* + * If set, the processor (the last of @nodes) whose typec-routes children + * belong to the chain too: one per Type-C port of the board, as its + * device tree describes them. + */ + bool dt_routes; }; +/* The typec-routes node of the processor that ends @st, or NULL. */ +static struct device_node *staged_routes(const struct gate_staged *st) +{ + struct device_node *dcp, *routes; + + if (!st->dt_routes) + return NULL; + dcp = of_find_node_by_path(st->nodes[st->nr - 1]); + routes = dcp ? of_get_child_by_name(dcp, "typec-routes") : NULL; + of_node_put(dcp); + return routes; +} + static const char *const t6041_hdmi_nodes[] = { /* ATC3 power, PMP DISPEXT0 request, DISPEXT0, AOP pins, PHY, crossbar, DARTs, mailbox, dcpext0 */ "/power-management@502800000/power-controller@408", @@ -2580,6 +2599,32 @@ static bool staged_ready(const struct gate_staged *st) } of_node_put(np); } + if (st->dt_routes) { + struct device_node *route; + unsigned int nr_routes = 0; + + np = staged_routes(st); + if (!np) { + staged_err("%s/typec-routes: no such node, nothing enabled\n", + st->nodes[st->nr - 1]); + return false; + } + for_each_child_of_node(np, route) { + if (of_device_is_available(route)) { + staged_err("%pOF: already enabled, nothing changed\n", route); + of_node_put(route); + of_node_put(np); + return false; + } + nr_routes++; + } + of_node_put(np); + if (!nr_routes) { + staged_err("%s/typec-routes: no routes, nothing enabled\n", + st->nodes[st->nr - 1]); + return false; + } + } return true; } @@ -3274,14 +3319,15 @@ static const char *const t6041_max_usbc2_nodes[] = { "/dcp@606e00000", }; -/* The third USB-C processor of the J614c/J616c, dcpext3, as dcpext2's chain. */ +/* + * The third USB-C processor of the M4 Max boards, dcpext3, as dcpext2's chain. + * Its routes are the ones the device tree gives it, one per Type-C port: three + * on the J614c/J616c, four on the J575c. + */ static const char *const t6041_max_usbc3_nodes[] = { "/iommu@306340000", "/iommu@306300000", "/mailbox@306e08000", - "/dcp@306e00000/typec-routes/route@0", - "/dcp@306e00000/typec-routes/route@1", - "/dcp@306e00000/typec-routes/route@2", "/dcp@306e00000", }; @@ -3289,7 +3335,7 @@ static const struct gate_staged t6041_max_stages[] = { { "/iommu@3a2300000", t6041_max_hdmi_nodes, ARRAY_SIZE(t6041_max_hdmi_nodes) }, { "/iommu@602300000", t6041_max_usbc_nodes, ARRAY_SIZE(t6041_max_usbc_nodes) }, { "/iommu@606300000", t6041_max_usbc2_nodes, ARRAY_SIZE(t6041_max_usbc2_nodes) }, - { "/iommu@306300000", t6041_max_usbc3_nodes, ARRAY_SIZE(t6041_max_usbc3_nodes) }, + { "/iommu@306300000", t6041_max_usbc3_nodes, ARRAY_SIZE(t6041_max_usbc3_nodes), true }, }; /* @@ -3394,6 +3440,32 @@ static bool __init t6041_max_needs_off_domain(const struct gate_staged *st, stru return off; } +/* Enable each typec-routes child of @st's processor in @cs, if @st takes its routes from the DT. */ +static int __init t6041_max_enable_routes(struct of_changeset *cs, const struct gate_staged *st) +{ + struct device_node *routes, *route; + unsigned int nr_routes = 0; + int ret = 0; + + if (!st->dt_routes) + return 0; + routes = staged_routes(st); + if (!routes) + return -ENODEV; + for_each_child_of_node(routes, route) { + ret = of_changeset_update_prop_string(cs, route, "status", "okay"); + if (ret) { + of_node_put(route); + break; + } + nr_routes++; + } + of_node_put(routes); + if (!ret && !nr_routes) + return -ENODEV; + return ret; +} + /* * Enable every node of stage @i and put its display DART into the display subsystem's iommus. * The in-tree trees give the chains no DISPEXT power domain: they are on as iBoot left them. A @@ -3415,6 +3487,11 @@ static int __init t6041_max_apply(unsigned int i, struct device_node *display) ret = np ? gate_iommus_append(cs, display, np) : -ENODEV; of_node_put(np); for (n = 0; !ret && n < st->nr; n++) { + /* The routes go in just before their processor, the last node. */ + if (n == st->nr - 1) + ret = t6041_max_enable_routes(cs, st); + if (ret) + break; np = of_find_node_by_path(st->nodes[n]); ret = np ? of_changeset_update_prop_string(cs, np, "status", "okay") : -ENODEV; if (!ret && t6041_max_needs_off_domain(st, np)) From f0ea546fae42ed55768a4365418acca9056696f1 Mon Sep 17 00:00:00 2001 From: Roberto Dantas <7robertodantas@gmail.com> Date: Thu, 26 Nov 2026 14:10:37 -0300 Subject: [PATCH 2/2] arm64: dts: apple: t6041-j575c: describe dcpext3 The J575c ADT has a fourth external display processor, dcpext3, at the J614c/J616c's address, and iBoot preloads and starts it here too (iop-dcpext3-nub pre-loaded 1, running 1). The tree did not describe it, so Linux left it running as iBoot did, unbound. Describe it as t6041-j616c-usbc-dcpext3.dtsi does, with a route to the fourth back Type-C port added, as the J575c's dcpext1 and dcpext2. The address, interrupts, external index, bandwidth agent slot and crossbar endpoint match this Mac's ADT. Everything is disabled: aura's t6041_exts fills the firmware memory, and the display gate enables the chain. dcpext3 can then drive a USB-C display on any back port, as dcpext1 and dcpext2 do, and Linux owns the processor instead of leaving it running unbound through a suspend. Signed-off-by: Roberto Dantas <7robertodantas@gmail.com> --- .../dts/apple/t6041-j575c-usbc-dcpext3.dtsi | 220 ++++++++++++++++++ arch/arm64/boot/dts/apple/t6041-j575c.dts | 1 + 2 files changed, 221 insertions(+) create mode 100644 arch/arm64/boot/dts/apple/t6041-j575c-usbc-dcpext3.dtsi diff --git a/arch/arm64/boot/dts/apple/t6041-j575c-usbc-dcpext3.dtsi b/arch/arm64/boot/dts/apple/t6041-j575c-usbc-dcpext3.dtsi new file mode 100644 index 0000000000000..679fc57246ebc --- /dev/null +++ b/arch/arm64/boot/dts/apple/t6041-j575c-usbc-dcpext3.dtsi @@ -0,0 +1,220 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * A third USB-C DisplayPort processor on the J575c: dcpext3, with a route to + * each of the four back Type-C ports (typec0-3), next to dcpext1 and dcpext2. + * + * The node is the J614c/J616c's (t6041-j616c-usbc-dcpext3.dtsi) with the + * fourth route added: the J575c ADT has dcpext3 at the same address + * (/arm-io/dcpext3 0x106e00000 + 0x2_0000_0000, interrupts +0x48, + * external-index 4, bwr-agent DISP_EXT3 slot 6, dp-switch-ufp-endpoint 3) + * and iBoot preloads and starts it here too (iop-dcpext3-nub pre-loaded 1, + * running 1). As dcpext1 and dcpext2, no PMP and no DISPEXT3 power domain is + * described: the chain runs as iBoot left it powered. + * + * Everything here is disabled. The boot loader fills dcpext3's firmware + * memory from this boot's ADT (aura t6041_exts) and the display gate enables + * the chain once it has. + */ + +/ { + aliases { + dcpext3 = &dcpext3; + }; + + reserved-memory { + dcpext3_text: dcpext3-text { + compatible = "apple,asc-mem"; + reg = <0x0 0x0 0x0 0x4000>; + no-map; + status = "disabled"; + }; + + dcpext3_data: dcpext3-data { + compatible = "apple,asc-mem"; + reg = <0x0 0x0 0x0 0x4000>; + no-map; + status = "disabled"; + }; + + dcpext3_heap: dcpext3-heap { + compatible = "apple,asc-mem"; + reg = <0x0 0x0 0x0 0x4000>; + no-map; + status = "disabled"; + }; + }; + + dcpext3: dcp@306e00000 { + compatible = "apple,t6041-dcpext", "apple,dcpext"; + reg = <0x3 0x06e00000 0x0 0x4000>, + <0x3 0x04000000 0x0 0x4000000>, + <0x3 0x06240000 0x0 0x10000>, + <0x3 0x063a8000 0x0 0x4000>, + <0x3 0x06800000 0x0 0x800000>; + reg-names = "coproc", "disp-0", "disp-1", "disp-2", "disp-3"; + mboxes = <&dcpext3_mbox>; + mbox-names = "mbox"; + iommus = <&dcpext3_dart 23>; + /* + * PMGR bandwidth agent scratch: the bwr-agent the ADT dispext3 + * function-bw_req_interrupt0 (0x4f) names: ADT + * pmgr bwr-agent DISP_EXT3, slot 6, so 0x20000 + 6 * 0x4000. + */ + apple,bw-scratch = <&pmgr_dcp 0 4 0x38000>; + /* ADT iop-dcpext3-nub external-index */ + apple,dcp-endpoint = <4>; + /* as dcpext0/1: without it apple-dcp's probe fails with -EINVAL */ + apple,iomfb-surfaces = <1 1 0 0>; + apple,connector-type = "USB-C"; + phys = <&atcphy0 PHY_TYPE_DP>, <&atcphy1 PHY_TYPE_DP>, + <&atcphy2 PHY_TYPE_DP>, <&atcphy3 PHY_TYPE_DP>; + phy-names = "typec0", "typec1", "typec2", "typec3"; + mux-controls = <&atcphy0_xbar 0>, <&atcphy1_xbar 0>, + <&atcphy2_xbar 0>, <&atcphy3_xbar 0>; + mux-control-names = "typec0", "typec1", "typec2", "typec3"; + /* + * indexed by route; crossbar state = 2 * dp-switch-ufp-endpoint + * (3) + port (0) + */ + apple,typec-dptx-phys = <0 1 2 3>; + apple,typec-mux-indices = <6 6 6 6>; + memory-region = <&dcpext3_text>, <&dcpext3_data>, <&dcpext3_heap>; + memory-region-names = "text", "data", "heap"; + status = "disabled"; + + dispext3_piodma: piodma { + iommus = <&dispext3_dart 16>; + }; + + typec-routes { + #address-cells = <1>; + #size-cells = <0>; + + route@0 { + reg = <0>; + mode-switch; + status = "disabled"; + + port { + dcpext3_typec0: endpoint { + remote-endpoint = <&typec0_dcpext3>; + }; + }; + }; + + route@1 { + reg = <1>; + mode-switch; + status = "disabled"; + + port { + dcpext3_typec1: endpoint { + remote-endpoint = <&typec1_dcpext3>; + }; + }; + }; + + route@2 { + reg = <2>; + mode-switch; + status = "disabled"; + + port { + dcpext3_typec2: endpoint { + remote-endpoint = <&typec2_dcpext3>; + }; + }; + }; + + route@3 { + reg = <3>; + mode-switch; + status = "disabled"; + + port { + dcpext3_typec3: endpoint { + remote-endpoint = <&typec3_dcpext3>; + }; + }; + }; + }; + }; + + dcpext3_mbox: mailbox@306e08000 { + compatible = "apple,t6041-asc-mailbox", "apple,asc-mailbox-v4"; + reg = <0x3 0x06e08000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = , + , + , + ; + interrupt-names = "send-empty", "send-not-empty", + "recv-empty", "recv-not-empty"; + #mbox-cells = <0>; + status = "disabled"; + }; + + dispext3_dart: iommu@306300000 { + compatible = "apple,t6041-dart", "apple,t8110-dart"; + reg = <0x3 0x06300000 0x0 0xc000>; + #iommu-cells = <1>; + apple,dma-range = <0x100 0x0 0x10 0x0>; + interrupt-parent = <&aic>; + interrupts = ; + status = "disabled"; + }; + + dcpext3_dart: iommu@306340000 { + compatible = "apple,t6041-dart", "apple,t8110-dart"; + reg = <0x3 0x06340000 0x0 0xc000>; + #iommu-cells = <1>; + apple,dma-range = <0x100 0x0 0x10 0x0>; + interrupt-parent = <&aic>; + interrupts = ; + status = "disabled"; + }; +}; + +&typec0 { + ports { + port@3 { + typec0_dcpext3: endpoint@2 { + reg = <2>; + remote-endpoint = <&dcpext3_typec0>; + }; + }; + }; +}; + +&typec1 { + ports { + port@3 { + typec1_dcpext3: endpoint@2 { + reg = <2>; + remote-endpoint = <&dcpext3_typec1>; + }; + }; + }; +}; + +&typec2 { + ports { + port@3 { + typec2_dcpext3: endpoint@2 { + reg = <2>; + remote-endpoint = <&dcpext3_typec2>; + }; + }; + }; +}; + +&typec3 { + ports { + port@3 { + typec3_dcpext3: endpoint@2 { + reg = <2>; + remote-endpoint = <&dcpext3_typec3>; + }; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t6041-j575c.dts b/arch/arm64/boot/dts/apple/t6041-j575c.dts index 235d7a2ab3af4..bce7e4962eec3 100644 --- a/arch/arm64/boot/dts/apple/t6041-j575c.dts +++ b/arch/arm64/boot/dts/apple/t6041-j575c.dts @@ -2085,6 +2085,7 @@ #include "t6041-j575c-usb3.dtsi" #include "t6041-j575c-usbc.dtsi" #include "t6041-j575c-usbc-dcpext2.dtsi" +#include "t6041-j575c-usbc-dcpext3.dtsi" #include "t6041-j575c-hdmi.dtsi" /* Not described: the SEP (no Touch ID sensor). */