All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tzung-Bi Shih <tzungbi@kernel.org>
To: Marek Maslanka <mmaslanka@google.com>
Cc: Benson Leung <bleung@chromium.org>,
	Abhishek Pandit-Subedi <abhishekpandit@chromium.org>,
	Jameson Thies <jthies@google.com>,
	Andrei Kuchynski <akuchynski@chromium.org>,
	Guenter Roeck <groeck@chromium.org>,
	Radu Vele <raduvele@google.com>,
	chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] platform/chrome: cros_ec_typec: Poll for role swap completion
Date: Tue, 29 Sep 2026 09:02:30 +0000	[thread overview]
Message-ID: <art-pgdLHXiCm5l4@google.com> (raw)
In-Reply-To: <20260923174420.2343724-1-mmaslanka@google.com>

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)?

  reply	other threads:[~2026-09-29  9:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-23 17:44 [PATCH] platform/chrome: cros_ec_typec: Poll for role swap completion Marek Maslanka
2026-09-29  9:02 ` Tzung-Bi Shih [this message]
2026-09-30 18:55   ` Marek Maslanka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=art-pgdLHXiCm5l4@google.com \
    --to=tzungbi@kernel.org \
    --cc=abhishekpandit@chromium.org \
    --cc=akuchynski@chromium.org \
    --cc=bleung@chromium.org \
    --cc=chrome-platform@lists.linux.dev \
    --cc=groeck@chromium.org \
    --cc=jthies@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mmaslanka@google.com \
    --cc=raduvele@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.