linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benson Leung <bleung@google.com>
To: Jameson Thies <jthies@google.com>
Cc: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org, dmitry.baryshkov@oss.qualcomm.com,
	bleung@chromium.org, gregkh@linuxfoundation.org,
	akuchynski@chromium.org, abhishekpandit@chromium.org,
	sebastian.reichel@collabora.com, linux-pm@vger.kernel.org
Subject: Re: [PATCH 6/6] usb: typec: ucsi: pr_swap should check connector_status
Date: Tue, 7 Oct 2025 23:56:27 +0000	[thread overview]
Message-ID: <aOWoq08H-3F66Ozg@google.com> (raw)
In-Reply-To: <20251007000007.3724229-7-jthies@google.com>

[-- Attachment #1: Type: text/plain, Size: 2793 bytes --]

On Tue, Oct 07, 2025 at 12:00:07AM +0000, Jameson Thies wrote:
> From: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
> 
> Power role swaps initiated by the host system doesn't generate
> connection status change notifications.
> 
> From UCSIv3.0 spec, section 6.5.10 Set Power Direction Role:
> 
> The execution of this command might require PPM to initiate a power
> role swap. If the power role swap fails for any reason, the command
> returns, and error and the power direction should remain unchanged.
> Note that if the execution of the command resulted in a successful
> power role swap, it should not result in a connector status change
> notification.
> 
> Signed-off-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
> Signed-off-by: Jameson Thies <jthies@google.com>

Reviewed-by: Benson Leung <bleung@chromium.org>


> ---
>  drivers/usb/typec/ucsi/ucsi.c | 30 +++++++++++++++++++++++++-----
>  1 file changed, 25 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index 1a7d850b11ea..6e3797d7a144 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -1526,20 +1526,40 @@ static int ucsi_pr_swap(struct typec_port *port, enum typec_role role)
>  	if (ret < 0)
>  		goto out_unlock;
>  
> -	mutex_unlock(&con->lock);
> +	command = UCSI_GET_CONNECTOR_STATUS | UCSI_CONNECTOR_NUMBER(con->num);
> +	ret = ucsi_send_command(con->ucsi, command, &con->status, sizeof(con->status));
> +	if (ret < 0)
> +		goto out_unlock;
>  
> -	if (!wait_for_completion_timeout(&con->complete,
> -					 msecs_to_jiffies(UCSI_SWAP_TIMEOUT_MS)))
> -		return -ETIMEDOUT;
> +	cur_role = !!UCSI_CONSTAT(con, PWR_DIR);
>  
> -	mutex_lock(&con->lock);
> +	/* Execution of SET_PDR should not result in connector status
> +	 * notifications. However, some legacy implementations may still defer
> +	 * the actual role swap and return immediately. Thus, check the
> +	 * connector status in case it immediately succeeded or wait for a later
> +	 * connector status change.
> +	 */
> +	if (cur_role != role) {
> +		mutex_unlock(&con->lock);
> +
> +		if (!wait_for_completion_timeout(
> +			    &con->complete,
> +			    msecs_to_jiffies(UCSI_SWAP_TIMEOUT_MS)))
> +			return -ETIMEDOUT;
> +
> +		mutex_lock(&con->lock);
> +	}
>  
>  	/* Something has gone wrong while swapping the role */
>  	if (UCSI_CONSTAT(con, PWR_OPMODE) != UCSI_CONSTAT_PWR_OPMODE_PD) {
>  		ucsi_reset_connector(con, true);
>  		ret = -EPROTO;
> +		goto out_unlock;
>  	}
>  
> +	/* Indicate successful power role swap */
> +	typec_set_pwr_role(con->port, role);
> +
>  out_unlock:
>  	mutex_unlock(&con->lock);
>  
> -- 
> 2.51.0.618.g983fd99d29-goog
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply	other threads:[~2025-10-07 23:56 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-07  0:00 [PATCH 0/6] UCSI Power Supply Updates and Bug Fixes Jameson Thies
2025-10-07  0:00 ` [PATCH 1/6] usb: typec: ucsi: psy: Add power supply status Jameson Thies
2025-10-08 12:53   ` Heikki Krogerus
2025-10-07  0:00 ` [PATCH 2/6] usb: typec: ucsi: psy: Add support for DRP USB type Jameson Thies
2025-10-07 23:50   ` Benson Leung
2025-10-08 13:02   ` Heikki Krogerus
2025-10-13 20:44     ` Jameson Thies
2025-10-07  0:00 ` [PATCH 3/6] usb: typec: ucsi: Report power supply changes on power opmode changes Jameson Thies
2025-10-07 23:51   ` Benson Leung
2025-10-08 13:02   ` Heikki Krogerus
2025-10-07  0:00 ` [PATCH 4/6] usb: typec: ucsi: Report power supply change on sink path change Jameson Thies
2025-10-07 23:52   ` Benson Leung
2025-10-08 13:06   ` Heikki Krogerus
2025-10-13 20:45     ` Jameson Thies
2025-10-07  0:00 ` [PATCH 5/6] usb: typec: ucsi: psy: Set max current to zero when disconnected Jameson Thies
2025-10-07 23:55   ` Benson Leung
2025-10-08 13:08   ` Heikki Krogerus
2025-10-07  0:00 ` [PATCH 6/6] usb: typec: ucsi: pr_swap should check connector_status Jameson Thies
2025-10-07 23:56   ` Benson Leung [this message]
2025-10-08 13:10   ` Heikki Krogerus
2025-10-13 20:56     ` Jameson Thies
2025-10-13  7:33 ` [PATCH 0/6] UCSI Power Supply Updates and Bug Fixes Greg KH
2025-10-13 20:59   ` Jameson Thies
2025-10-14  5:19     ` Greg KH
2025-10-13 21:02 ` Kenneth Crudup
2025-10-13 22:53   ` Jameson Thies
2025-10-13 23:26     ` Kenneth Crudup

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=aOWoq08H-3F66Ozg@google.com \
    --to=bleung@google.com \
    --cc=abhishekpandit@chromium.org \
    --cc=akuchynski@chromium.org \
    --cc=bleung@chromium.org \
    --cc=dmitry.baryshkov@oss.qualcomm.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=jthies@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=sebastian.reichel@collabora.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).