Re: [PATCH] platform/chrome: cros_ec_typec: Poll for role swap completion

From: Marek Maslanka

Date: Wed Sep 30 2026 - 17:29:19 EST


On Tue, Sep 29, 2026 at 09:02:30AM +0000, Tzung-Bi Shih wrote:
> On Wed, Sep 23, 2026 at 07:44:19PM +0200, Marek Maslanka wrote:
> > + req.swap = USB_PD_CTRL_SWAP_NONE;
> > + end = jiffies + msecs_to_jiffies(ROLE_SWAP_TIMEOUT_MS);
> > + for (;;) {
> > + if ((resp.enabled & PD_CTRL_RESP_ENABLED_CONNECTED) &&
>
> Shouldn't PD_CTRL_RESP_ENABLED_CONNECTED remain set during the entire poll?
>
> > + cros_typec_resp_to_role(&resp, swap_type) == target_role)
> > + break;
> > +
> > + if (time_after_eq(jiffies, end)) {
> > + if (!(resp.enabled & PD_CTRL_RESP_ENABLED_CONNECTED)) {
> > + dev_err(data->dev, "Port disconnected during role swap\n");
> > + return -ENOTCONN;
> > + }
>
> Same here: if PD_CTRL_RESP_ENABLED_CONNECTED isn't set in the loop, should
> it return -ENOTCONN early (i.e., out of this if-block)?

Yea Right, thanks. PD_CTRL_RESP_ENABLED_CONNECTED remains set
throughout the role swap in the EC (both TCPMv2 and PDC keep the port
in an attached state while a PR_Swap or DR_Swap is in progress).

The original reason for checking PD_CTRL_RESP_ENABLED_CONNECTED before
comparing the role was to avoid misinterpreting a cleared resp.role (0)
on disconnect as TYPEC_SINK or TYPEC_DEVICE, but checking
!(resp.enabled & PD_CTRL_RESP_ENABLED_CONNECTED) at the start of the
loop and returning -ENOTCONN immediately is much cleaner and avoids
waiting for the timeout when the port disconnects.

I will update this in v2.