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

From: Tzung-Bi Shih

Date: Tue Sep 29 2026 - 05:03:00 EST


On Wed, Sep 23, 2026 at 07:44:19PM +0200, Marek Maslanka wrote:
> @@ -104,27 +127,41 @@ static int cros_typec_perform_role_swap(struct typec_port *tc_port, int target_r
> if (ret < 0)
> return ret;
>
> - switch (swap_type) {
> - case USB_PD_CTRL_SWAP_DATA:
> - role = resp.role & PD_CTRL_RESP_ROLE_DATA ? TYPEC_HOST : TYPEC_DEVICE;
> - if (role != target_role) {
> - dev_err(data->dev, "Data role swap failed despite EC returning success\n");
> - return -EIO;
> + /*
> + * Depending on the EC USB-C stack (TCPMv2 vs PDC), EC_CMD_USB_PD_CONTROL
> + * may either block until the swap completes or queue the request
> + * asynchronously and return the pre-swap role. Poll until the target
> + * role is reached while connected, or until the timeout expires.
> + */
> + 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)?