linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: typec: ucsi: Monitor connector change before getting connector status
@ 2025-11-17  9:31 Hsin-Te Yuan
  2025-11-18 16:54 ` Kenneth Crudup
  2025-11-19  8:39 ` Heikki Krogerus
  0 siblings, 2 replies; 3+ messages in thread
From: Hsin-Te Yuan @ 2025-11-17  9:31 UTC (permalink / raw)
  To: Heikki Krogerus, Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel, Hsin-Te Yuan

Originally, the notification for connector change will be enabled after
the first read of the connector status. Therefore, if the event happens
during this window, it will be missing and make the status unsynced.

Enable the notification for connector change before getting the
connector status to ensure the status is synced.

Signed-off-by: Hsin-Te Yuan <yuanhsinte@chromium.org>
---
 drivers/usb/typec/ucsi/ucsi.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
index 3f568f790f39b0271667e80816270274b8dd3008..07290cd85b618b22cb989151079707dbe9f578a7 100644
--- a/drivers/usb/typec/ucsi/ucsi.c
+++ b/drivers/usb/typec/ucsi/ucsi.c
@@ -1565,7 +1565,7 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con)
 	struct typec_capability *cap = &con->typec_cap;
 	enum typec_accessory *accessory = cap->accessory;
 	enum usb_role u_role = USB_ROLE_NONE;
-	u64 command;
+	u64 command, ntfy;
 	char *name;
 	int ret;
 
@@ -1659,6 +1659,15 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con)
 		goto out;
 	}
 
+	/* Enable the notification for connector change before getting the connector status */
+	ntfy = UCSI_ENABLE_NTFY_CMD_COMPLETE | UCSI_ENABLE_NTFY_ERROR | UCSI_ENABLE_NTFY_CONNECTOR_CHANGE;
+	command = UCSI_SET_NOTIFICATION_ENABLE | ntfy;
+	ret = ucsi_send_command(ucsi, command, NULL, 0);
+	if (ret < 0) {
+		dev_warn(ucsi->dev, "con%d: failed to enable the notification for connector change\n",
+			 con->num);
+	}
+
 	/* Get the status */
 	ret = ucsi_get_connector_status(con, false);
 	if (ret) {

---
base-commit: 6a23ae0a96a600d1d12557add110e0bb6e32730c
change-id: 20251117-ucsi-c2dfe8c006d7

Best regards,
-- 
Hsin-Te Yuan <yuanhsinte@chromium.org>


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] usb: typec: ucsi: Monitor connector change before getting connector status
  2025-11-17  9:31 [PATCH] usb: typec: ucsi: Monitor connector change before getting connector status Hsin-Te Yuan
@ 2025-11-18 16:54 ` Kenneth Crudup
  2025-11-19  8:39 ` Heikki Krogerus
  1 sibling, 0 replies; 3+ messages in thread
From: Kenneth Crudup @ 2025-11-18 16:54 UTC (permalink / raw)
  To: Hsin-Te Yuan, Heikki Krogerus, Greg Kroah-Hartman
  Cc: linux-usb, linux-kernel, Kenneth C, Mario Limonciello (AMD)


This patch seems to fix an issue I've had for a while now on my Dell 
XPS-9320 where if I suspend with one Thunderbolt Dock connected and 
resume with another, the machine thinks the previous dock is still 
connected (which means mostly that the new monitor configuration isn't set).

I'm still testing it to see if it does indeed fix my issue, but to at 
least confirm it does what it says on the tin:

Tested-By: Kenneth R. Crudup <kenny@panix.com>

On 11/17/25 01:31, Hsin-Te Yuan wrote:
> Originally, the notification for connector change will be enabled after
> the first read of the connector status. Therefore, if the event happens
> during this window, it will be missing and make the status unsynced.
> 
> Enable the notification for connector change before getting the
> connector status to ensure the status is synced.
> 
> Signed-off-by: Hsin-Te Yuan <yuanhsinte@chromium.org>
> ---
>   drivers/usb/typec/ucsi/ucsi.c | 11 ++++++++++-
>   1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index 3f568f790f39b0271667e80816270274b8dd3008..07290cd85b618b22cb989151079707dbe9f578a7 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -1565,7 +1565,7 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con)
>   	struct typec_capability *cap = &con->typec_cap;
>   	enum typec_accessory *accessory = cap->accessory;
>   	enum usb_role u_role = USB_ROLE_NONE;
> -	u64 command;
> +	u64 command, ntfy;
>   	char *name;
>   	int ret;
>   
> @@ -1659,6 +1659,15 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con)
>   		goto out;
>   	}
>   
> +	/* Enable the notification for connector change before getting the connector status */
> +	ntfy = UCSI_ENABLE_NTFY_CMD_COMPLETE | UCSI_ENABLE_NTFY_ERROR | UCSI_ENABLE_NTFY_CONNECTOR_CHANGE;
> +	command = UCSI_SET_NOTIFICATION_ENABLE | ntfy;
> +	ret = ucsi_send_command(ucsi, command, NULL, 0);
> +	if (ret < 0) {
> +		dev_warn(ucsi->dev, "con%d: failed to enable the notification for connector change\n",
> +			 con->num);
> +	}
> +
>   	/* Get the status */
>   	ret = ucsi_get_connector_status(con, false);
>   	if (ret) {
> 
> ---
> base-commit: 6a23ae0a96a600d1d12557add110e0bb6e32730c
> change-id: 20251117-ucsi-c2dfe8c006d7
> 
> Best regards,

-- 
Kenneth R. Crudup / Sr. SW Engineer, Scott County Consulting, Orange 
County CA


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] usb: typec: ucsi: Monitor connector change before getting connector status
  2025-11-17  9:31 [PATCH] usb: typec: ucsi: Monitor connector change before getting connector status Hsin-Te Yuan
  2025-11-18 16:54 ` Kenneth Crudup
@ 2025-11-19  8:39 ` Heikki Krogerus
  1 sibling, 0 replies; 3+ messages in thread
From: Heikki Krogerus @ 2025-11-19  8:39 UTC (permalink / raw)
  To: Hsin-Te Yuan; +Cc: Greg Kroah-Hartman, linux-usb, linux-kernel

On Mon, Nov 17, 2025 at 05:31:43PM +0800, Hsin-Te Yuan wrote:
> Originally, the notification for connector change will be enabled after
> the first read of the connector status. Therefore, if the event happens
> during this window, it will be missing and make the status unsynced.
> 
> Enable the notification for connector change before getting the
> connector status to ensure the status is synced.
> 
> Signed-off-by: Hsin-Te Yuan <yuanhsinte@chromium.org>
> ---
>  drivers/usb/typec/ucsi/ucsi.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index 3f568f790f39b0271667e80816270274b8dd3008..07290cd85b618b22cb989151079707dbe9f578a7 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -1565,7 +1565,7 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con)
>  	struct typec_capability *cap = &con->typec_cap;
>  	enum typec_accessory *accessory = cap->accessory;
>  	enum usb_role u_role = USB_ROLE_NONE;
> -	u64 command;
> +	u64 command, ntfy;
>  	char *name;
>  	int ret;
>  
> @@ -1659,6 +1659,15 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con)
>  		goto out;
>  	}
>  
> +	/* Enable the notification for connector change before getting the connector status */
> +	ntfy = UCSI_ENABLE_NTFY_CMD_COMPLETE | UCSI_ENABLE_NTFY_ERROR | UCSI_ENABLE_NTFY_CONNECTOR_CHANGE;
> +	command = UCSI_SET_NOTIFICATION_ENABLE | ntfy;
> +	ret = ucsi_send_command(ucsi, command, NULL, 0);
> +	if (ret < 0) {
> +		dev_warn(ucsi->dev, "con%d: failed to enable the notification for connector change\n",
> +			 con->num);
> +	}

You can't do this repeatedly with every port that is registered. That
will lead into other problems.

I think the proper way to fix this is to first register all the ports
(and their alt modes) without checking the status, then enable the
notification, and finally check the status for every port separately.

So separate the status checking part at the end of
ucsi_register_port() into a new function, and then call it for every
port right after all notications are enabled in ucsi_init().

thanks,

-- 
heikki

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-11-19  8:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-17  9:31 [PATCH] usb: typec: ucsi: Monitor connector change before getting connector status Hsin-Te Yuan
2025-11-18 16:54 ` Kenneth Crudup
2025-11-19  8:39 ` Heikki Krogerus

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