* [PATCH] usb: typec: tipd: cd321x: replay the plug on resume
@ 2026-11-12 11:30 Jacob Procee
2026-11-17 11:08 ` Heikki Krogerus
0 siblings, 1 reply; 6+ messages in thread
From: Jacob Procee @ 2026-11-12 11:30 UTC (permalink / raw)
To: Heikki Krogerus, Greg Kroah-Hartman
Cc: linux-usb, linux-kernel, Sven Peter, Janne Grunau, Jacob Procee
On Apple Silicon the Type-C PHY and the dwc3 controller behind a CD321x
port lose their state during s2idle while the plug stays connected, and
the CD321x does not raise an interrupt on resume. xhci notices the lost
state and re-initializes the host controller:
xhci-hcd xhci-hcd.0.auto: xHC error in resume, USBSTS 0x401, Reinit
usb usb1: root hub lost power or was reset
usb 1-1: USB disconnect, device number 2
but the PHY is only ever programmed from typec_mux_set(), so a device
left plugged in (here a FIDO2 security key) never comes back until it is
unplugged and plugged in again.
Re-initializing only dwc3 after resume does not work: tearing dwc3 down
also powers off the PHY, and nothing turns it back on, so xhci then
times out ("Host halt failed, -110", "can't setup: -110").
Instead, make cd321x replay the plug on resume when a partner was
connected: mark the plug as changed and queue the update work, which
then goes through the same sequence as a real replug (role none, mux
safe, mux back to the partner's mode, role back on). Queue it on
system_freezable_wq so it runs only after all devices have resumed.
Tested on a 14" MacBook Pro (M1 Pro, j314s) with a backport of this
change to the Asahi 7.3.3 kernel: a USB-C security key left plugged in
re-enumerates right after "PM: suspend exit", where it previously stayed
gone until replugged. Unplugging the device while the system is asleep
also works: after resume the role goes to none, nothing is brought back
up, and replugging it later enumerates normally. This mainline version
was build-tested only (W=1, checkpatch --strict clean).
Fixes: 82432bbfb9e8 ("usb: typec: tipd: Handle mode transitions for CD321x")
Assisted-by: LLM
Signed-off-by: Jacob Procee <sn125164@gmail.com>
---
checkpatch flags the Assisted-by tag (non-standard signature, 'LLM' is
not an email address); the format follows
Documentation/process/coding-assistants.rst.
drivers/usb/typec/tipd/core.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
index 02539378ffed..2ec380124532 100644
--- a/drivers/usb/typec/tipd/core.c
+++ b/drivers/usb/typec/tipd/core.c
@@ -164,6 +164,7 @@ struct tipd_data {
bool (*read_power_status)(struct tps6598x *tps);
int (*reset)(struct tps6598x *tps);
int (*connect)(struct tps6598x *tps, u32 status);
+ void (*resume)(struct tps6598x *tps);
};
struct tps6598x {
@@ -911,6 +912,21 @@ static int cd321x_connect(struct tps6598x *tps, u32 status)
return 0;
}
+static void cd321x_resume(struct tps6598x *tps)
+{
+ struct cd321x *cd321x = container_of(tps, struct cd321x, tps);
+
+ guard(mutex)(&tps->lock);
+
+ if (IS_ERR_OR_NULL(tps->partner))
+ return;
+
+ cd321x->update_status.status_changed |= TPS_STATUS_PLUG_PRESENT;
+ cancel_delayed_work(&cd321x->update_work);
+ queue_delayed_work(system_freezable_wq, &cd321x->update_work,
+ msecs_to_jiffies(CD321X_DEBOUNCE_DELAY_MS));
+}
+
static irqreturn_t cd321x_interrupt(int irq, void *data)
{
struct tps6598x *tps = data;
@@ -2014,6 +2030,9 @@ static int __maybe_unused tps6598x_resume(struct device *dev)
queue_delayed_work(system_power_efficient_wq, &tps->wq_poll,
msecs_to_jiffies(POLL_INTERVAL));
+ if (tps->data->resume)
+ tps->data->resume(tps);
+
return 0;
}
@@ -2040,6 +2059,7 @@ static const struct tipd_data cd321x_data = {
.reset = cd321x_reset,
.switch_power_state = cd321x_switch_power_state,
.connect = cd321x_connect,
+ .resume = cd321x_resume,
};
static const struct tipd_data tps6598x_data = {
--
2.56.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] usb: typec: tipd: cd321x: replay the plug on resume
2026-11-12 11:30 [PATCH] usb: typec: tipd: cd321x: replay the plug on resume Jacob Procee
@ 2026-11-17 11:08 ` Heikki Krogerus
2026-11-17 12:03 ` Sven Peter
0 siblings, 1 reply; 6+ messages in thread
From: Heikki Krogerus @ 2026-11-17 11:08 UTC (permalink / raw)
To: Jacob Procee, Sven Peter
Cc: Greg Kroah-Hartman, linux-usb, linux-kernel, Janne Grunau
On Thu, Nov 12, 2026 at 12:30:05PM +0100, Jacob Procee wrote:
> On Apple Silicon the Type-C PHY and the dwc3 controller behind a CD321x
> port lose their state during s2idle while the plug stays connected, and
> the CD321x does not raise an interrupt on resume. xhci notices the lost
> state and re-initializes the host controller:
>
> xhci-hcd xhci-hcd.0.auto: xHC error in resume, USBSTS 0x401, Reinit
> usb usb1: root hub lost power or was reset
> usb 1-1: USB disconnect, device number 2
>
> but the PHY is only ever programmed from typec_mux_set(), so a device
> left plugged in (here a FIDO2 security key) never comes back until it is
> unplugged and plugged in again.
>
> Re-initializing only dwc3 after resume does not work: tearing dwc3 down
> also powers off the PHY, and nothing turns it back on, so xhci then
> times out ("Host halt failed, -110", "can't setup: -110").
>
> Instead, make cd321x replay the plug on resume when a partner was
> connected: mark the plug as changed and queue the update work, which
> then goes through the same sequence as a real replug (role none, mux
> safe, mux back to the partner's mode, role back on). Queue it on
> system_freezable_wq so it runs only after all devices have resumed.
>
> Tested on a 14" MacBook Pro (M1 Pro, j314s) with a backport of this
> change to the Asahi 7.3.3 kernel: a USB-C security key left plugged in
> re-enumerates right after "PM: suspend exit", where it previously stayed
> gone until replugged. Unplugging the device while the system is asleep
> also works: after resume the role goes to none, nothing is brought back
> up, and replugging it later enumerates normally. This mainline version
> was build-tested only (W=1, checkpatch --strict clean).
>
> Fixes: 82432bbfb9e8 ("usb: typec: tipd: Handle mode transitions for CD321x")
> Assisted-by: LLM
> Signed-off-by: Jacob Procee <sn125164@gmail.com>
Looks okay to me, but as this is a fix, you should CC stable:
https://docs.kernel.org/process/submitting-patches.html#select-the-recipients-for-your-patch
Sven, would you be interested, or would you have time, to maintain
this driver?
Thanks,
> ---
> checkpatch flags the Assisted-by tag (non-standard signature, 'LLM' is
> not an email address); the format follows
> Documentation/process/coding-assistants.rst.
>
> drivers/usb/typec/tipd/core.c | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
> index 02539378ffed..2ec380124532 100644
> --- a/drivers/usb/typec/tipd/core.c
> +++ b/drivers/usb/typec/tipd/core.c
> @@ -164,6 +164,7 @@ struct tipd_data {
> bool (*read_power_status)(struct tps6598x *tps);
> int (*reset)(struct tps6598x *tps);
> int (*connect)(struct tps6598x *tps, u32 status);
> + void (*resume)(struct tps6598x *tps);
> };
>
> struct tps6598x {
> @@ -911,6 +912,21 @@ static int cd321x_connect(struct tps6598x *tps, u32 status)
> return 0;
> }
>
> +static void cd321x_resume(struct tps6598x *tps)
> +{
> + struct cd321x *cd321x = container_of(tps, struct cd321x, tps);
> +
> + guard(mutex)(&tps->lock);
> +
> + if (IS_ERR_OR_NULL(tps->partner))
> + return;
> +
> + cd321x->update_status.status_changed |= TPS_STATUS_PLUG_PRESENT;
> + cancel_delayed_work(&cd321x->update_work);
> + queue_delayed_work(system_freezable_wq, &cd321x->update_work,
> + msecs_to_jiffies(CD321X_DEBOUNCE_DELAY_MS));
> +}
> +
> static irqreturn_t cd321x_interrupt(int irq, void *data)
> {
> struct tps6598x *tps = data;
> @@ -2014,6 +2030,9 @@ static int __maybe_unused tps6598x_resume(struct device *dev)
> queue_delayed_work(system_power_efficient_wq, &tps->wq_poll,
> msecs_to_jiffies(POLL_INTERVAL));
>
> + if (tps->data->resume)
> + tps->data->resume(tps);
> +
> return 0;
> }
>
> @@ -2040,6 +2059,7 @@ static const struct tipd_data cd321x_data = {
> .reset = cd321x_reset,
> .switch_power_state = cd321x_switch_power_state,
> .connect = cd321x_connect,
> + .resume = cd321x_resume,
> };
>
> static const struct tipd_data tps6598x_data = {
> --
> 2.56.0
--
heikki
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] usb: typec: tipd: cd321x: replay the plug on resume
2026-11-17 11:08 ` Heikki Krogerus
@ 2026-11-17 12:03 ` Sven Peter
2026-11-17 12:17 ` Jacob Procee
0 siblings, 1 reply; 6+ messages in thread
From: Sven Peter @ 2026-11-17 12:03 UTC (permalink / raw)
To: Heikki Krogerus, Jacob Procee
Cc: Greg Kroah-Hartman, linux-usb, linux-kernel, Janne Grunau
On 17.11.26 12:08, Heikki Krogerus wrote:
> On Thu, Nov 12, 2026 at 12:30:05PM +0100, Jacob Procee wrote:
>> On Apple Silicon the Type-C PHY and the dwc3 controller behind a CD321x
>> port lose their state during s2idle while the plug stays connected, and
>> the CD321x does not raise an interrupt on resume. xhci notices the lost
>> state and re-initializes the host controller:
>>
>> xhci-hcd xhci-hcd.0.auto: xHC error in resume, USBSTS 0x401, Reinit
>> usb usb1: root hub lost power or was reset
>> usb 1-1: USB disconnect, device number 2
>>
>> but the PHY is only ever programmed from typec_mux_set(), so a device
>> left plugged in (here a FIDO2 security key) never comes back until it is
>> unplugged and plugged in again.
>>
>> Re-initializing only dwc3 after resume does not work: tearing dwc3 down
>> also powers off the PHY, and nothing turns it back on, so xhci then
>> times out ("Host halt failed, -110", "can't setup: -110").
>>
>> Instead, make cd321x replay the plug on resume when a partner was
>> connected: mark the plug as changed and queue the update work, which
>> then goes through the same sequence as a real replug (role none, mux
>> safe, mux back to the partner's mode, role back on). Queue it on
>> system_freezable_wq so it runs only after all devices have resumed.
>>
>> Tested on a 14" MacBook Pro (M1 Pro, j314s) with a backport of this
>> change to the Asahi 7.3.3 kernel: a USB-C security key left plugged in
>> re-enumerates right after "PM: suspend exit", where it previously stayed
>> gone until replugged. Unplugging the device while the system is asleep
>> also works: after resume the role goes to none, nothing is brought back
>> up, and replugging it later enumerates normally. This mainline version
>> was build-tested only (W=1, checkpatch --strict clean).
>>
>> Fixes: 82432bbfb9e8 ("usb: typec: tipd: Handle mode transitions for CD321x")
>> Assisted-by: LLM
>> Signed-off-by: Jacob Procee <sn125164@gmail.com>
>
> Looks okay to me, but as this is a fix, you should CC stable:
> https://docs.kernel.org/process/submitting-patches.html#select-the-recipients-for-your-patch
So I really don't think it's a good idea to work around a symptom here
and effectively fake a unplug/plug on each suspend.
XHCI is already capable of putting individual ports into a low power
state and it should already try to do that during suspend. Resume just
doesn't seem to work correctly for some reason on this platform.
I suspect we're just missing the proper suspend/resume work in the PHY
itself to put it into a low power state. Or maybe we need to keep an
additional power domain enabled so that the PHY doesn't lose all state
and keeps working in a lower power mode.
When using XNU it's possible to wake the machine with e.g. a usb
keyboard and it doesn't re-enumerate everything on resume and that
should be possible here on Linux as well. And I really don't think
that's going to be more complex than this patch here.
>
> Sven, would you be interested, or would you have time, to maintain
> this driver?
Sure, I can help.
Thanks,
Sven
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] usb: typec: tipd: cd321x: replay the plug on resume
2026-11-17 12:03 ` Sven Peter
@ 2026-11-17 12:17 ` Jacob Procee
2026-11-17 12:47 ` Janne Grunau
0 siblings, 1 reply; 6+ messages in thread
From: Jacob Procee @ 2026-11-17 12:17 UTC (permalink / raw)
To: Sven Peter
Cc: Heikki Krogerus, Greg Kroah-Hartman, linux-usb, linux-kernel,
Janne Grunau
On Tue, 17 Nov 2026 13:03:03 +0100
Sven Peter <sven@kernel.org> wrote:
> I suspect we're just missing the proper suspend/resume work in the PHY
> itself to put it into a low power state. Or maybe we need to keep an
> additional power domain enabled so that the PHY doesn't lose all state
> and keeps working in a lower power mode.
Agreed, please drop this (and v2).
That second option is what happens with wakeup enabled: the dwc3 node
and the ATC PHY share the atc*_usb pmgr domain, and it's only switched
off in s2idle because xhci and the root hubs default to power/wakeup =
disabled. With wakeup enabled on xhci-hcd.*.auto and usb* (Asahi 7.3.3,
j314s), the domain stays on and a device left plugged in stays
connected through s2idle without re-enumerating (no "xHC error in
resume ... Reinit"). Asahi's pmgr marks these domains
GENPD_FLAG_ACTIVE_WAKEUP; mainline's doesn't yet.
Wake from a USB keyboard still doesn't work: nothing calls
enable_irq_wake() for the dwc3/xhci IRQ, and irq-apple-aic has neither
irq_set_wake nor IRQCHIP_SKIP_SET_WAKE.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] usb: typec: tipd: cd321x: replay the plug on resume
2026-11-17 12:17 ` Jacob Procee
@ 2026-11-17 12:47 ` Janne Grunau
2026-11-20 10:58 ` Jacob Procee
0 siblings, 1 reply; 6+ messages in thread
From: Janne Grunau @ 2026-11-17 12:47 UTC (permalink / raw)
To: Jacob Procee
Cc: Sven Peter, Heikki Krogerus, Greg Kroah-Hartman, linux-usb, linux-kernel
On Tue, Nov 17, 2026 at 01:17:13PM +0100, Jacob Procee wrote:
> On Tue, 17 Nov 2026 13:03:03 +0100
> Sven Peter <sven@kernel.org> wrote:
>
> > I suspect we're just missing the proper suspend/resume work in the PHY
> > itself to put it into a low power state. Or maybe we need to keep an
> > additional power domain enabled so that the PHY doesn't lose all state
> > and keeps working in a lower power mode.
>
> Agreed, please drop this (and v2).
>
> That second option is what happens with wakeup enabled: the dwc3 node
> and the ATC PHY share the atc*_usb pmgr domain, and it's only switched
> off in s2idle because xhci and the root hubs default to power/wakeup =
> disabled. With wakeup enabled on xhci-hcd.*.auto and usb* (Asahi 7.3.3,
> j314s), the domain stays on and a device left plugged in stays
> connected through s2idle without re-enumerating (no "xHC error in
> resume ... Reinit"). Asahi's pmgr marks these domains
> GENPD_FLAG_ACTIVE_WAKEUP; mainline's doesn't yet.
yes, the downstream tree has commit to set GENPD_FLAG_ACTIVE_WAKEUP for
all power-domains which are active at probe (boot) time.
> Wake from a USB keyboard still doesn't work: nothing calls
> enable_irq_wake() for the dwc3/xhci IRQ, and irq-apple-aic has neither
> irq_set_wake nor IRQCHIP_SKIP_SET_WAKE.
The interrupt controller (AIC) doesn't have functionality to configure
IRQs as wake up source so it should set IRQCHIP_SKIP_SET_WAKE. Does wake
from USB keyboard work with that changed?
You might also need to add "wakeup-source" to the dwc3 nodes.
Janne
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] usb: typec: tipd: cd321x: replay the plug on resume
2026-11-17 12:47 ` Janne Grunau
@ 2026-11-20 10:58 ` Jacob Procee
0 siblings, 0 replies; 6+ messages in thread
From: Jacob Procee @ 2026-11-20 10:58 UTC (permalink / raw)
To: Janne Grunau
Cc: Sven Peter, Heikki Krogerus, Greg Kroah-Hartman, linux-usb, linux-kernel
On Tue, 17 Nov 2026 13:47:10 +0100
Janne Grunau <j@jannau.net> wrote:
> The interrupt controller (AIC) doesn't have functionality to configure
> IRQs as wake up source so it should set IRQCHIP_SKIP_SET_WAKE. Does
> wake from USB keyboard work with that changed?
> You might also need to add "wakeup-source" to the dwc3 nodes.
No, it still doesn't wake. I tested on Asahi 7.3.4 (j314s) with a
local test patch:
- AIC and AIC2 irq_chip .flags = IRQCHIP_SKIP_SET_WAKE
- dwc3-apple: device_init_wakeup(dev, true) in probe, and PM ops
that call enable_irq_wake() on the dwc3 IRQ in suspend when in
host mode and device_may_wakeup(), disable_irq_wake() in resume
The keyboard is behind a USB2 hub on b02280000. I had to enable
power/wakeup on the hub by hand (usbhid only sets it on the keyboard
itself), plus the xhci and root hubs.
On suspend, enable_irq_wake() returns 0 for both IRQs (113 and 115),
so the AIC flag does what it should. The keyboard stays connected
through s2idle and is still there after resume. But a keypress doesn't
wake the machine, and /sys/power/pm_wakeup_irq is empty afterwards, so
no interrupt seems to reach the kernel at all.
I didn't add "wakeup-source" to the DT: as far as I can see, neither
dwc3 core nor dwc3-apple parses it (only some glue drivers like qcom
do), so it would add nothing beyond device_init_wakeup().
My guess is that the halted xHC doesn't raise its interrupt on remote
wake, and a separate wake interrupt is needed, like qcom's
hs_phy_irq/dp_hs_phy_irq. Do you know whether the ATC PHY or some
other block on Apple has such an interrupt, or how macOS gets woken
here?
Power cost, in case it matters for the default: overnight s2idle runs
with a key plugged into f02280000 (lid closed, battery) came to
2.29 W with wakeup enabled (atc2_usb stays on) against 1.96 W with
wakeup disabled (domain off, device re-enumerates on resume). So
keeping the domain on costs about 0.33 W.
Thanks,
Jacob
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-20 10:58 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-12 11:30 [PATCH] usb: typec: tipd: cd321x: replay the plug on resume Jacob Procee
2026-11-17 11:08 ` Heikki Krogerus
2026-11-17 12:03 ` Sven Peter
2026-11-17 12:17 ` Jacob Procee
2026-11-17 12:47 ` Janne Grunau
2026-11-20 10:58 ` Jacob Procee
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®