From 3e25078bca2350195dc66da981456ec3b6469c98 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 21 Nov 2026 11:00:15 +1100 Subject: [PATCH 1/7] usb: typec: mux: let a Thunderbolt switch ask for a port-driver stop Some USB4 routers must be stopped by the Type-C port driver, in a fixed order ahead of the USB role and the PHY, before tasks freeze and at shutdown. Others stop on their own. Let the provider say which it is in its switch description, and give port drivers typec_thunderbolt_switch_pd_ordered_stop() to ask, so they no longer have to guess from the machine they run on. Signed-off-by: Ryan Murray --- drivers/usb/typec/mux.c | 19 +++++++++++++++++++ drivers/usb/typec/mux.h | 1 + include/linux/usb/typec_mux.h | 11 +++++++++++ 3 files changed, 31 insertions(+) diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c index 8e830fff78fe7..49fee90e9809d 100644 --- a/drivers/usb/typec/mux.c +++ b/drivers/usb/typec/mux.c @@ -891,6 +891,24 @@ bool typec_thunderbolt_switch_is_live(struct typec_thunderbolt_switch *sw) } EXPORT_SYMBOL_GPL(typec_thunderbolt_switch_is_live); +/** + * typec_thunderbolt_switch_pd_ordered_stop - Whether the port driver stops the switch + * @sw: USB4/Thunderbolt switch + * + * Returns true if the bound provider asked the Type-C port driver to stop + * it before tasks freeze and at shutdown (see struct + * typec_thunderbolt_switch_desc), false for any other or no provider. + */ +bool typec_thunderbolt_switch_pd_ordered_stop(struct typec_thunderbolt_switch *sw) +{ + if (IS_ERR_OR_NULL(sw)) + return false; + + guard(rwsem_read)(&sw->sw_dev->set_lock); + return sw->sw_dev->set && sw->sw_dev->pd_ordered_stop; +} +EXPORT_SYMBOL_GPL(typec_thunderbolt_switch_pd_ordered_stop); + /** * typec_thunderbolt_switch_set - Forward cable details to USB4/Thunderbolt switch * @sw: USB4/Thunderbolt switch @@ -1057,6 +1075,7 @@ typec_thunderbolt_switch_register(struct device *parent, init_rwsem(&sw_dev->set_lock); sw_dev->owner = parent->driver ? parent->driver->owner : NULL; sw_dev->set = desc->set; + sw_dev->pd_ordered_stop = desc->pd_ordered_stop; device_initialize(&sw_dev->dev); sw_dev->dev.parent = parent; diff --git a/drivers/usb/typec/mux.h b/drivers/usb/typec/mux.h index 9ce77aecf7bac..501c7aa4010a7 100644 --- a/drivers/usb/typec/mux.h +++ b/drivers/usb/typec/mux.h @@ -43,6 +43,7 @@ struct typec_thunderbolt_switch_dev { struct module *owner; typec_thunderbolt_switch_set_fn_t set; struct atomic_notifier_head notifiers; + bool pd_ordered_stop; }; #define to_typec_thunderbolt_switch_dev(_dev_) \ diff --git a/include/linux/usb/typec_mux.h b/include/linux/usb/typec_mux.h index bf7fe40be1501..4cb9c2d1bff24 100644 --- a/include/linux/usb/typec_mux.h +++ b/include/linux/usb/typec_mux.h @@ -243,12 +243,16 @@ typedef int (*typec_thunderbolt_switch_set_fn_t)(struct typec_thunderbolt_switch * @set: Callback invoked with the cable details on connection changes * @name: Optional switch name, the parent device name is used if not set * @drvdata: Private data + * @pd_ordered_stop: The switch must be stopped by the Type-C port driver, + * before tasks freeze and at shutdown, ahead of the USB role and PHY + * (TYPEC_THUNDERBOLT_SWITCH_SLEEP / _OFF), instead of on its own */ struct typec_thunderbolt_switch_desc { struct fwnode_handle *fwnode; typec_thunderbolt_switch_set_fn_t set; const char *name; void *drvdata; + bool pd_ordered_stop; }; #if IS_ENABLED(CONFIG_TYPEC) @@ -257,6 +261,7 @@ struct typec_thunderbolt_switch * fwnode_typec_thunderbolt_switch_get(struct fwnode_handle *fwnode); void typec_thunderbolt_switch_put(struct typec_thunderbolt_switch *sw); bool typec_thunderbolt_switch_is_live(struct typec_thunderbolt_switch *sw); +bool typec_thunderbolt_switch_pd_ordered_stop(struct typec_thunderbolt_switch *sw); int typec_thunderbolt_switch_set(struct typec_thunderbolt_switch *sw, const struct typec_thunderbolt_switch_data *data); int typec_thunderbolt_switch_register_notifier(struct typec_thunderbolt_switch *sw, @@ -312,6 +317,12 @@ typec_thunderbolt_switch_is_live(struct typec_thunderbolt_switch *sw) return false; } +static inline bool +typec_thunderbolt_switch_pd_ordered_stop(struct typec_thunderbolt_switch *sw) +{ + return false; +} + static inline int typec_thunderbolt_switch_register_notifier(struct typec_thunderbolt_switch *sw, struct notifier_block *nb) From 289a5010be9d21887c64441366423834efc1d94f Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 21 Nov 2026 11:01:02 +1100 Subject: [PATCH 2/7] thunderbolt: apple: pick the T8122 router policy from the device tree The T8122 router policy (MxWrap RUN, explicit LSTX, strict firmware-ready admission, witnessed power-off) was only taken on apple,j613. Every other T8122 Mac with the same router - the 15-inch MacBook Air (J615), the iMacs (J433/J434) and the MacBook Pro (J504) - fell back to the T8103 policy, which cannot start it. What the policy needs is the router's MxWrap CPU block, which the device tree names as the "cpu" resource. Take the T8122 policy whenever that resource is described and keep the T8103 fallback otherwise (for example an older loader's handoff tree without it). The strict power cycle has to be stopped by the PD driver ahead of the USB role and the PHY, so advertise that through the switch description instead of letting the PD driver infer it from the machine. Signed-off-by: Ryan Murray --- drivers/thunderbolt/apple.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/thunderbolt/apple.c b/drivers/thunderbolt/apple.c index 8242b75609c0a..1d376a6584f40 100644 --- a/drivers/thunderbolt/apple.c +++ b/drivers/thunderbolt/apple.c @@ -4644,9 +4644,13 @@ static int apple_cio_probe(struct platform_device *pdev) acio->dev = &pdev->dev; acio->np = dev->of_node; acio->hw = of_device_get_match_data(dev); - /* Only J613 has qualified the T8122 router policy and resources. */ + /* + * The T8122 router policy starts the router through its MxWrap CPU + * block. A device tree (or an older loader's handoff tree) that does + * not describe that block keeps the T8103 policy. + */ if (acio->hw == &apple_cio_t8122_hw && - !of_machine_is_compatible("apple,j613")) + of_property_match_string(acio->np, "reg-names", "cpu") < 0) acio->hw = &apple_cio_t8103_hw; if (!acio->hw) return -EINVAL; @@ -4857,6 +4861,8 @@ static int apple_cio_probe(struct platform_device *pdev) .fwnode = pdev->dev.fwnode, .set = apple_cio_tbt_switch_set, .drvdata = acio, + /* A strict power cycle is ordered by the PD driver (sleep and shutdown). */ + .pd_ordered_stop = acio->hw->strict_power_cycle, }; /* A consumer cannot start a host before its failure listener is ready. */ scoped_guard(mutex, &acio->lock) { From cbce76be4d0d9946896591c6a7e0a20473b8d6fc Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 21 Nov 2026 11:01:26 +1100 Subject: [PATCH 3/7] usb: typec: tipd: stop the USB4 session when the switch asks for it The CD321x session stop before tasks freeze and at shutdown (ACIO, then the USB role, then the PHY in safe mode) only ran on apple,j613. Run it for whichever port's USB4/Thunderbolt switch asks for a port-driver stop instead, and leave every other switch alone as before. The notifier is registered for every CD321x and asks the switch on each suspend, because the router may bind after the port. Signed-off-by: Ryan Murray --- drivers/usb/typec/tipd/core.c | 29 ++++++++++++++++++++--------- drivers/usb/typec/tipd/tps6598x.h | 1 + 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index bc7929fec09f9..d97b2d9e83a7b 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -2626,12 +2626,20 @@ static int cd321x_session_pm(struct notifier_block *nb, unsigned long event, voi switch (event) { case PM_SUSPEND_PREPARE: + /* Only a switch that asked for it is stopped from here. */ + scoped_guard(mutex, &cd->tps.lock) + cd->session_pm_armed = + typec_thunderbolt_switch_pd_ordered_stop(cd->tbt_switch); + if (!cd->session_pm_armed) + return NOTIFY_DONE; ret = cd321x_session_stop(cd, true); if (ret) cd321x_session_restore(cd); return notifier_from_errno(ret); case PM_POST_SUSPEND: - cd321x_session_restore(cd); + if (cd->session_pm_armed) + cd321x_session_restore(cd); + cd->session_pm_armed = false; break; } return NOTIFY_OK; @@ -2641,12 +2649,11 @@ static void cd321x_ready(struct tps6598x *tps) { struct cd321x *cd321x = container_of(tps, struct cd321x, tps); - if (of_machine_is_compatible("apple,j613")) { - cd321x->session_pm.notifier_call = cd321x_session_pm; - cd321x->session_pm.priority = 100; - if (!register_pm_notifier(&cd321x->session_pm)) - cd321x->session_pm_registered = true; - } + /* The switch may bind later; each suspend asks it again. */ + cd321x->session_pm.notifier_call = cd321x_session_pm; + cd321x->session_pm.priority = 100; + if (!register_pm_notifier(&cd321x->session_pm)) + cd321x->session_pm_registered = true; guard(mutex)(&tps->lock); /* Include failures reported while the port was still being initialized. */ @@ -3939,11 +3946,15 @@ EXPORT_SYMBOL_GPL(tipd_init); void tipd_shutdown(struct tps6598x *tps) { + struct cd321x *cd = container_of(tps, struct cd321x, tps); + bool ordered; int ret; - if (!of_machine_is_compatible("apple,j613")) + scoped_guard(mutex, &tps->lock) + ordered = typec_thunderbolt_switch_pd_ordered_stop(cd->tbt_switch); + if (!ordered) return; - ret = cd321x_session_stop(container_of(tps, struct cd321x, tps), false); + ret = cd321x_session_stop(cd, false); if (ret) dev_err(tps->dev, "USB4 shutdown incomplete: %d\n", ret); } diff --git a/drivers/usb/typec/tipd/tps6598x.h b/drivers/usb/typec/tipd/tps6598x.h index b4344131ee322..d0450440e32cb 100644 --- a/drivers/usb/typec/tipd/tps6598x.h +++ b/drivers/usb/typec/tipd/tps6598x.h @@ -448,6 +448,7 @@ struct cd321x_status { struct cd321x { struct notifier_block session_pm; bool session_pm_registered; + bool session_pm_armed; bool session_closed; struct tps6598x tps; From 4e44561128adf8644856425044e22027e7f11dce Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 21 Nov 2026 11:01:27 +1100 Subject: [PATCH 4/7] arm64: dts: apple: t8122-j615: describe the USB4 PCIe-C tunnels The J615 (MacBook Air 15-inch, M3) has the J613's two ATC ports on the same T8122 routers. Give it the PCIe-C tunnel description and aliases the J613 already has, and drop its unused, disabled USB2 OTG node so older loaders do not prune the shared ATC0 suppliers. Signed-off-by: Ryan Murray --- arch/arm64/boot/dts/apple/t8122-j615.dts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8122-j615.dts b/arch/arm64/boot/dts/apple/t8122-j615.dts index 8c3add040f8d9..77544fc7ee03c 100644 --- a/arch/arm64/boot/dts/apple/t8122-j615.dts +++ b/arch/arm64/boot/dts/apple/t8122-j615.dts @@ -10,11 +10,21 @@ /dts-v1/; #include "t8122.dtsi" +#include "t8122-usb4.dtsi" #include "t8122-j613-j615.dtsi" / { compatible = "apple,j615", "apple,t8122", "apple,arm-platform"; model = "Apple MacBook Air (15-inch, M3, 2024)"; + + aliases { + usb4-0-pcie = &usb4_0_pcie; + usb4-0-pcie-port = &usb4_0_pcie_port; + usb4-1-pcie = &usb4_1_pcie; + usb4-1-pcie-port = &usb4_1_pcie_port; + usb4-0-pcie-adapter = &usb4_0_acio; + usb4-1-pcie-adapter = &usb4_1_acio; + }; }; &dcp { @@ -152,3 +162,6 @@ /* Per-device factory data from this Mac's own iBoot system container. */ firmware-name = "apple/mesacal-j615.bin"; }; + +/* Older Stage 2 loaders prune the shared ATC0 suppliers of this unused node. */ +/delete-node/ &usb_otg0; From d93c785bb78ca57cf2568cbf01f543d288fab67f Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 21 Nov 2026 12:24:07 +1100 Subject: [PATCH 5/7] usb: typec: tipd: test the session stop against both kinds of router Cover the suspend notifier with a router that stops on its own (nothing is sent to it) and with one that asks the port to stop it (SLEEP before the freeze, WAKE after it). Signed-off-by: Ryan Murray --- drivers/usb/typec/tipd/cd321x-tbt-test.c | 59 ++++++++++++++++++++++-- drivers/usb/typec/tipd/core.c | 3 +- drivers/usb/typec/tipd/tps6598x.h | 1 + 3 files changed, 58 insertions(+), 5 deletions(-) diff --git a/drivers/usb/typec/tipd/cd321x-tbt-test.c b/drivers/usb/typec/tipd/cd321x-tbt-test.c index 8e1d83d18546c..0c601c55d1c1f 100644 --- a/drivers/usb/typec/tipd/cd321x-tbt-test.c +++ b/drivers/usb/typec/tipd/cd321x-tbt-test.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -285,13 +286,15 @@ static struct cd321x *cd321x_tbt_test_late_port(struct kunit *test) return cd; } -static void cd321x_tbt_test_add_router(struct kunit *test, - const struct software_node *node) +static void cd321x_tbt_test_add_router_ordered(struct kunit *test, + const struct software_node *node, + bool pd_ordered_stop) { struct typec_thunderbolt_switch_desc desc = { .fwnode = software_node_fwnode(node), .set = cd321x_tbt_test_set, .name = node->name, + .pd_ordered_stop = pd_ordered_stop, }; struct typec_thunderbolt_switch_dev *sw_dev; struct device *router; @@ -306,6 +309,12 @@ static void cd321x_tbt_test_add_router(struct kunit *test, KUNIT_ASSERT_EQ(test, ret, 0); } +static void cd321x_tbt_test_add_router(struct kunit *test, + const struct software_node *node) +{ + cd321x_tbt_test_add_router_ordered(test, node, false); +} + /* A router that registers after the port gave up is taken; the cable is reread. */ static void cd321x_tbt_router_binds_late_test(struct kunit *test) { @@ -414,7 +423,7 @@ static void cd321x_tbt_router_rebinds_test(struct kunit *test) } /* A port with a live router, as the cable events find it. */ -static struct cd321x *cd321x_tbt_test_live_port(struct kunit *test) +static struct cd321x *cd321x_tbt_test_port(struct kunit *test, bool pd_ordered_stop) { struct cd321x *cd = cd321x_tbt_test_late_port(test); int ret; @@ -422,7 +431,7 @@ static struct cd321x *cd321x_tbt_test_live_port(struct kunit *test) ret = cd321x_tbt_watch_late(cd, software_node_fwnode(&cd321x_test_connector)); KUNIT_ASSERT_EQ(test, ret, 0); flush_work(&cd->tbt_attach_work); - cd321x_tbt_test_add_router(test, &cd321x_test_router); + cd321x_tbt_test_add_router_ordered(test, &cd321x_test_router, pd_ordered_stop); flush_work(&cd->tbt_attach_work); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cd->tbt_switch); scoped_guard(mutex, &cd->tps.lock) @@ -430,6 +439,11 @@ static struct cd321x *cd321x_tbt_test_live_port(struct kunit *test) return cd; } +static struct cd321x *cd321x_tbt_test_live_port(struct kunit *test) +{ + return cd321x_tbt_test_port(test, false); +} + /* A reboot closes the router's session at once and keeps cable events away. */ static void cd321x_tbt_reboot_closes_session_test(struct kunit *test) { @@ -454,6 +468,41 @@ static void cd321x_tbt_reboot_other_action_test(struct kunit *test) KUNIT_EXPECT_TRUE(test, cd321x_pm_can_update(&cd->pm)); } +/* A router that stops on its own is not stopped by the port before sleep. */ +static void cd321x_tbt_sleep_router_stops_itself_test(struct kunit *test) +{ + struct cd321x_tbt_test *ctx = test->priv; + struct cd321x *cd = cd321x_tbt_test_live_port(test); + + KUNIT_EXPECT_EQ(test, cd321x_session_pm(&cd->session_pm, PM_SUSPEND_PREPARE, NULL), + NOTIFY_DONE); + KUNIT_EXPECT_EQ(test, ctx->set_calls, 0); + KUNIT_EXPECT_EQ(test, cd321x_session_pm(&cd->session_pm, PM_POST_SUSPEND, NULL), + NOTIFY_OK); + KUNIT_EXPECT_EQ(test, ctx->set_calls, 0); +} + +/* A router that asks for it is put to sleep by the port and woken after. */ +static void cd321x_tbt_sleep_router_ordered_test(struct kunit *test) +{ + struct cd321x_tbt_test *ctx = test->priv; + struct cd321x *cd = cd321x_tbt_test_port(test, true); + + KUNIT_EXPECT_EQ(test, cd321x_session_pm(&cd->session_pm, PM_SUSPEND_PREPARE, NULL), + NOTIFY_OK); + KUNIT_EXPECT_EQ(test, ctx->set_calls, 1); + KUNIT_EXPECT_EQ(test, ctx->last_state, TYPEC_THUNDERBOLT_SWITCH_SLEEP); + /* The port is gated for sleep; there is no controller to reread after it. */ + scoped_guard(mutex, &cd->tps.lock) { + KUNIT_EXPECT_EQ(test, cd->pm.phase, CD321X_PM_PREPARED); + cd->pm.phase = CD321X_PM_INITIALIZING; + } + KUNIT_EXPECT_EQ(test, cd321x_session_pm(&cd->session_pm, PM_POST_SUSPEND, NULL), + NOTIFY_OK); + KUNIT_EXPECT_EQ(test, ctx->set_calls, 2); + KUNIT_EXPECT_EQ(test, ctx->last_state, TYPEC_THUNDERBOLT_SWITCH_WAKE); +} + static struct kunit_case cd321x_tbt_cases[] = { KUNIT_CASE(cd321x_tbt_no_router_test), KUNIT_CASE(cd321x_tbt_router_bound_test), @@ -466,6 +515,8 @@ static struct kunit_case cd321x_tbt_cases[] = { KUNIT_CASE(cd321x_tbt_router_rebinds_test), KUNIT_CASE(cd321x_tbt_reboot_closes_session_test), KUNIT_CASE(cd321x_tbt_reboot_other_action_test), + KUNIT_CASE(cd321x_tbt_sleep_router_stops_itself_test), + KUNIT_CASE(cd321x_tbt_sleep_router_ordered_test), {} }; diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index d97b2d9e83a7b..1b4c60190c2b8 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -2619,7 +2619,7 @@ static void cd321x_session_restore(struct cd321x *cd) cd321x_complete(&cd->tps); } -static int cd321x_session_pm(struct notifier_block *nb, unsigned long event, void *unused) +VISIBLE_IF_KUNIT int cd321x_session_pm(struct notifier_block *nb, unsigned long event, void *unused) { struct cd321x *cd = container_of(nb, struct cd321x, session_pm); int ret; @@ -2644,6 +2644,7 @@ static int cd321x_session_pm(struct notifier_block *nb, unsigned long event, voi } return NOTIFY_OK; } +EXPORT_SYMBOL_IF_KUNIT(cd321x_session_pm); static void cd321x_ready(struct tps6598x *tps) { diff --git a/drivers/usb/typec/tipd/tps6598x.h b/drivers/usb/typec/tipd/tps6598x.h index d0450440e32cb..743c8d62416a7 100644 --- a/drivers/usb/typec/tipd/tps6598x.h +++ b/drivers/usb/typec/tipd/tps6598x.h @@ -589,6 +589,7 @@ void cd321x_stop_work(struct cd321x *cd321x); int cd321x_reboot_close(struct cd321x *cd321x); int cd321x_reboot_notify(struct notifier_block *nb, unsigned long action, void *data); +int cd321x_session_pm(struct notifier_block *nb, unsigned long event, void *unused); bool cd321x_tbt_switch_keep_waiting(struct device *dev); struct typec_thunderbolt_switch * cd321x_tbt_switch_get(struct device *dev, struct fwnode_handle *fwnode, From dd986ff58929e6be0d5eb2f3c542dcf020f55de5 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sun, 22 Nov 2026 04:03:51 +1100 Subject: [PATCH 6/7] usb: typec: tipd: stop the USB4 session at shutdown on I2C ports too pd_ordered_stop asks the Type-C port driver to stop the USB4 session before tasks freeze and at shutdown. Only the SPMI SN201202x driver had a .shutdown, so on the T8122 Macs whose CD321x sits on I2C (J433, J434, J504) the router took the strict power cycle at device_shutdown with the USB role and PHY still owned by the port. Give the I2C driver the same .shutdown. The I2C driver also binds plain TPS6598x parts, which have no struct cd321x around them, so tipd_shutdown() now returns early for a port whose variant does not embed one, and a KUnit case covers that. On a PREPARE that fails, the PM core skips our POST_SUSPEND: clear session_pm_armed on that path too so the state stays obvious. Macs that take the T8122 router policy (ACIO node names "cpu", shared t8122.dtsi): J433, J434, J504, J613, J615; their ports get the PD-ordered sleep and shutdown stop. Signed-off-by: Ryan Murray --- drivers/usb/typec/tipd/cd321x-tbt-test.c | 17 +++++++++++++++++ drivers/usb/typec/tipd/core.c | 12 ++++++++++-- drivers/usb/typec/tipd/i2c.c | 7 +++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/tipd/cd321x-tbt-test.c b/drivers/usb/typec/tipd/cd321x-tbt-test.c index 0c601c55d1c1f..b0131305e00a7 100644 --- a/drivers/usb/typec/tipd/cd321x-tbt-test.c +++ b/drivers/usb/typec/tipd/cd321x-tbt-test.c @@ -503,6 +503,22 @@ static void cd321x_tbt_sleep_router_ordered_test(struct kunit *test) KUNIT_EXPECT_EQ(test, ctx->last_state, TYPEC_THUNDERBOLT_SWITCH_WAKE); } +/* A plain TPS6598x has no struct cd321x around it: its shutdown stops nothing. */ +static void cd321x_tbt_shutdown_plain_port_test(struct kunit *test) +{ + static const struct tipd_data plain = { + .tps_struct_size = sizeof(struct tps6598x), + }; + struct cd321x_tbt_test *ctx = test->priv; + struct tps6598x *tps = kunit_kzalloc(test, sizeof(*tps), GFP_KERNEL); + + KUNIT_ASSERT_NOT_NULL(test, tps); + tps->data = &plain; + mutex_init(&tps->lock); + tipd_shutdown(tps); + KUNIT_EXPECT_EQ(test, ctx->set_calls, 0); +} + static struct kunit_case cd321x_tbt_cases[] = { KUNIT_CASE(cd321x_tbt_no_router_test), KUNIT_CASE(cd321x_tbt_router_bound_test), @@ -517,6 +533,7 @@ static struct kunit_case cd321x_tbt_cases[] = { KUNIT_CASE(cd321x_tbt_reboot_other_action_test), KUNIT_CASE(cd321x_tbt_sleep_router_stops_itself_test), KUNIT_CASE(cd321x_tbt_sleep_router_ordered_test), + KUNIT_CASE(cd321x_tbt_shutdown_plain_port_test), {} }; diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index 1b4c60190c2b8..a18fbdd5704f4 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -2633,8 +2633,11 @@ VISIBLE_IF_KUNIT int cd321x_session_pm(struct notifier_block *nb, unsigned long if (!cd->session_pm_armed) return NOTIFY_DONE; ret = cd321x_session_stop(cd, true); - if (ret) + if (ret) { cd321x_session_restore(cd); + /* The PM core skips our POST_SUSPEND after a failed PREPARE. */ + cd->session_pm_armed = false; + } return notifier_from_errno(ret); case PM_POST_SUSPEND: if (cd->session_pm_armed) @@ -3947,10 +3950,15 @@ EXPORT_SYMBOL_GPL(tipd_init); void tipd_shutdown(struct tps6598x *tps) { - struct cd321x *cd = container_of(tps, struct cd321x, tps); + struct cd321x *cd; bool ordered; int ret; + /* Only a port embedded in a struct cd321x has a USB4 session to stop. */ + if (tps->data->tps_struct_size < sizeof(struct cd321x)) + return; + cd = container_of(tps, struct cd321x, tps); + scoped_guard(mutex, &tps->lock) ordered = typec_thunderbolt_switch_pd_ordered_stop(cd->tbt_switch); if (!ordered) diff --git a/drivers/usb/typec/tipd/i2c.c b/drivers/usb/typec/tipd/i2c.c index 7e63d2dfc04c7..2eed9be9210f8 100644 --- a/drivers/usb/typec/tipd/i2c.c +++ b/drivers/usb/typec/tipd/i2c.c @@ -93,6 +93,12 @@ static int __maybe_unused tps6598x_resume(struct device *dev) return ret; } +/* Stops a USB4 session first when its switch asks for a PD-ordered stop. */ +static void tps6598x_shutdown_i2c(struct i2c_client *client) +{ + tipd_shutdown(i2c_get_clientdata(client)); +} + static const struct dev_pm_ops tps6598x_pm_ops = { .prepare = pm_sleep_ptr(tipd_prepare), .complete = pm_sleep_ptr(tipd_complete), @@ -122,6 +128,7 @@ static struct i2c_driver tps6598x_i2c_driver = { }, .probe = tps6598x_probe_i2c, .remove = tps6598x_remove_i2c, + .shutdown = tps6598x_shutdown_i2c, .id_table = tps6598x_id, }; module_i2c_driver(tps6598x_i2c_driver); From e690d19c5b2eaa8755de03adf72fd17d4f0c1ea8 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sun, 22 Nov 2026 04:05:00 +1100 Subject: [PATCH 7/7] arm64: dts: apple: t8122-usb4: power the tunnel DARTs from CIO-PCIe The PCIe-C tunnel DARTs probe as devices of their own and sit inside the ATC's CIO-PCIe block, which their tunnel's root port already names. Give each DART the same power state so it is never probed or read while that block is off. apple-dart-pd-check.py reported both as new findings on the J613 and J615 DTBs; it reports none now. Signed-off-by: Ryan Murray --- arch/arm64/boot/dts/apple/t8122-usb4.dtsi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8122-usb4.dtsi b/arch/arm64/boot/dts/apple/t8122-usb4.dtsi index ce69d7ec74f9c..fccb62addf109 100644 --- a/arch/arm64/boot/dts/apple/t8122-usb4.dtsi +++ b/arch/arm64/boot/dts/apple/t8122-usb4.dtsi @@ -15,6 +15,7 @@ interrupt-parent = <&aic>; interrupts = ; #iommu-cells = <1>; + power-domains = <&ps_atc0_cio_pcie>; /* No bootloader fills this one; the tunnel's cold init needs it. */ apple,tunable = <0x20c 0x800001b7 0x800001b7>, @@ -115,6 +116,7 @@ interrupt-parent = <&aic>; interrupts = ; #iommu-cells = <1>; + power-domains = <&ps_atc1_cio_pcie>; /* No bootloader fills this one; the tunnel's cold init needs it. */ apple,tunable = <0x20c 0x800001b7 0x800001b7>,