linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/6] UCSI Power Supply Updates and Bug Fixes
@ 2025-10-07  0:00 Jameson Thies
  2025-10-07  0:00 ` [PATCH 1/6] usb: typec: ucsi: psy: Add power supply status Jameson Thies
                   ` (7 more replies)
  0 siblings, 8 replies; 27+ messages in thread
From: Jameson Thies @ 2025-10-07  0:00 UTC (permalink / raw)
  To: heikki.krogerus, linux-usb, linux-kernel
  Cc: jthies, dmitry.baryshkov, bleung, gregkh, akuchynski,
	abhishekpandit, sebastian.reichel, linux-pm

This series includes the following minor changes to power supply
handling by the UCSI driver.

1) Adds the "Status" property to power supplies registered by the UCSI
driver.
2) Reports power supply USB type as "DRP" when the port partner is a
DRP.
3) Updates ucsi.c to report a power supply change all power opmode
changes. Currently this only gets reported when opmode is PD.
4) Updates ucsi.c to report a power supply change when the PPM signals
a sink path change.
5) Set max current to 0 when no device is connected. Currently this
defaults to 0.1A.
6) Updates connector status after initiating a PR swap. Following the
UCSI spec, there is no reported change following a successful SET_PDR
command. This results in the stored connector status being outdated.

Abhishek Pandit-Subedi (1):
  usb: typec: ucsi: pr_swap should check connector_status

Jameson Thies (5):
  usb: typec: ucsi: psy: Add power supply status
  usb: typec: ucsi: psy: Add support for DRP USB type
  usb: typec: ucsi: Report power supply changes on power opmode changes
  usb: typec: ucsi: Report power supply change on sink path change
  usb: typec: ucsi: psy: Set max current to zero when disconnected

 drivers/usb/typec/ucsi/psy.c  | 41 ++++++++++++++++++++++++++++++++++-
 drivers/usb/typec/ucsi/ucsi.c | 35 +++++++++++++++++++++++++-----
 drivers/usb/typec/ucsi/ucsi.h |  4 ++++
 3 files changed, 73 insertions(+), 7 deletions(-)


base-commit: e40b984b6c4ce3f80814f39f86f87b2a48f2e662
-- 
2.51.0.618.g983fd99d29-goog


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

* [PATCH 1/6] usb: typec: ucsi: psy: Add power supply status
  2025-10-07  0:00 [PATCH 0/6] UCSI Power Supply Updates and Bug Fixes Jameson Thies
@ 2025-10-07  0:00 ` 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
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 27+ messages in thread
From: Jameson Thies @ 2025-10-07  0:00 UTC (permalink / raw)
  To: heikki.krogerus, linux-usb, linux-kernel
  Cc: jthies, dmitry.baryshkov, bleung, gregkh, akuchynski,
	abhishekpandit, sebastian.reichel, linux-pm

Add support for power supply status. If a port is acting as a sink
with the sink path enabled, report it is charging. If a port is
source, report it is discharging. If there is no connection or the
port hasn't enabled the sink path, report not charging.

Signed-off-by: Jameson Thies <jthies@google.com>
---
 drivers/usb/typec/ucsi/psy.c  | 26 ++++++++++++++++++++++++++
 drivers/usb/typec/ucsi/ucsi.h |  3 +++
 2 files changed, 29 insertions(+)

diff --git a/drivers/usb/typec/ucsi/psy.c b/drivers/usb/typec/ucsi/psy.c
index 62a9d68bb66d..2b0225821502 100644
--- a/drivers/usb/typec/ucsi/psy.c
+++ b/drivers/usb/typec/ucsi/psy.c
@@ -29,6 +29,7 @@ static enum power_supply_property ucsi_psy_props[] = {
 	POWER_SUPPLY_PROP_CURRENT_MAX,
 	POWER_SUPPLY_PROP_CURRENT_NOW,
 	POWER_SUPPLY_PROP_SCOPE,
+	POWER_SUPPLY_PROP_STATUS,
 };
 
 static int ucsi_psy_get_scope(struct ucsi_connector *con,
@@ -51,6 +52,29 @@ static int ucsi_psy_get_scope(struct ucsi_connector *con,
 	return 0;
 }
 
+static int ucsi_psy_get_status(struct ucsi_connector *con,
+			       union power_supply_propval *val)
+{
+	bool is_sink = UCSI_CONSTAT(con, PWR_DIR) == TYPEC_SINK;
+	bool sink_path_enabled = true;
+
+	val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
+
+	if (con->ucsi->version >= UCSI_VERSION_2_0)
+		sink_path_enabled =
+			UCSI_CONSTAT(con, SINK_PATH_STATUS_V2_0) ==
+			UCSI_CONSTAT_SINK_PATH_ENABLED;
+
+	if (UCSI_CONSTAT(con, CONNECTED)) {
+		if (is_sink && sink_path_enabled)
+			val->intval = POWER_SUPPLY_STATUS_CHARGING;
+		else if (!is_sink)
+			val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
+	}
+
+	return 0;
+}
+
 static int ucsi_psy_get_online(struct ucsi_connector *con,
 			       union power_supply_propval *val)
 {
@@ -245,6 +269,8 @@ static int ucsi_psy_get_prop(struct power_supply *psy,
 		return ucsi_psy_get_current_now(con, val);
 	case POWER_SUPPLY_PROP_SCOPE:
 		return ucsi_psy_get_scope(con, val);
+	case POWER_SUPPLY_PROP_STATUS:
+		return ucsi_psy_get_status(con, val);
 	default:
 		return -EINVAL;
 	}
diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h
index e301d9012936..cce93af7461b 100644
--- a/drivers/usb/typec/ucsi/ucsi.h
+++ b/drivers/usb/typec/ucsi/ucsi.h
@@ -360,6 +360,9 @@ struct ucsi_cable_property {
 #define   UCSI_CONSTAT_BC_SLOW_CHARGING		2
 #define   UCSI_CONSTAT_BC_TRICKLE_CHARGING	3
 #define UCSI_CONSTAT_PD_VERSION_V1_2		UCSI_DECLARE_BITFIELD_V1_2(70, 16)
+#define UCSI_CONSTAT_SINK_PATH_STATUS_V2_0	UCSI_DECLARE_BITFIELD_V2_0(87, 1)
+#define   UCSI_CONSTAT_SINK_PATH_DISABLED   0
+#define   UCSI_CONSTAT_SINK_PATH_ENABLED    1
 #define UCSI_CONSTAT_PWR_READING_READY_V2_1	UCSI_DECLARE_BITFIELD_V2_1(89, 1)
 #define UCSI_CONSTAT_CURRENT_SCALE_V2_1		UCSI_DECLARE_BITFIELD_V2_1(90, 3)
 #define UCSI_CONSTAT_PEAK_CURRENT_V2_1		UCSI_DECLARE_BITFIELD_V2_1(93, 16)
-- 
2.51.0.618.g983fd99d29-goog


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

* [PATCH 2/6] usb: typec: ucsi: psy: Add support for DRP USB type
  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-07  0:00 ` Jameson Thies
  2025-10-07 23:50   ` Benson Leung
  2025-10-08 13:02   ` Heikki Krogerus
  2025-10-07  0:00 ` [PATCH 3/6] usb: typec: ucsi: Report power supply changes on power opmode changes Jameson Thies
                   ` (5 subsequent siblings)
  7 siblings, 2 replies; 27+ messages in thread
From: Jameson Thies @ 2025-10-07  0:00 UTC (permalink / raw)
  To: heikki.krogerus, linux-usb, linux-kernel
  Cc: jthies, dmitry.baryshkov, bleung, gregkh, akuchynski,
	abhishekpandit, sebastian.reichel, linux-pm

The USB Type registered with the power supply class is based on the
current power operation mode of the port. When the port is using USB
PD and is connected to a DRP partner, report that the power supply's
USB type is USB PD DRP.

Signed-off-by: Jameson Thies <jthies@google.com>
---
 drivers/usb/typec/ucsi/psy.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/typec/ucsi/psy.c b/drivers/usb/typec/ucsi/psy.c
index 2b0225821502..985a90d3f898 100644
--- a/drivers/usb/typec/ucsi/psy.c
+++ b/drivers/usb/typec/ucsi/psy.c
@@ -209,8 +209,16 @@ static int ucsi_psy_get_usb_type(struct ucsi_connector *con,
 {
 	val->intval = POWER_SUPPLY_USB_TYPE_C;
 	if (UCSI_CONSTAT(con, CONNECTED) &&
-	    UCSI_CONSTAT(con, PWR_OPMODE) == UCSI_CONSTAT_PWR_OPMODE_PD)
+	    UCSI_CONSTAT(con, PWR_OPMODE) == UCSI_CONSTAT_PWR_OPMODE_PD) {
+		for (int i = 0; i < con->num_pdos; i++) {
+			if (pdo_type(con->src_pdos[i]) == PDO_TYPE_FIXED &&
+			    con->src_pdos[i] & PDO_FIXED_DUAL_ROLE) {
+				val->intval = POWER_SUPPLY_USB_TYPE_PD_DRP;
+				return 0;
+			}
+		}
 		val->intval = POWER_SUPPLY_USB_TYPE_PD;
+	}
 
 	return 0;
 }
-- 
2.51.0.618.g983fd99d29-goog


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

* [PATCH 3/6] usb: typec: ucsi: Report power supply changes on power opmode changes
  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-07  0:00 ` [PATCH 2/6] usb: typec: ucsi: psy: Add support for DRP USB type Jameson Thies
@ 2025-10-07  0:00 ` 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
                   ` (4 subsequent siblings)
  7 siblings, 2 replies; 27+ messages in thread
From: Jameson Thies @ 2025-10-07  0:00 UTC (permalink / raw)
  To: heikki.krogerus, linux-usb, linux-kernel
  Cc: jthies, dmitry.baryshkov, bleung, gregkh, akuchynski,
	abhishekpandit, sebastian.reichel, linux-pm

Report opmode changes from the PPM to the power supply class by calling
ucsi_port_psy_changed(). If the current opmode is USB PD, do not call
ucsi_port_psy_changed(). The power supply class will be updated after
requesting partner source PDOs.

Signed-off-by: Jameson Thies <jthies@google.com>
---
 drivers/usb/typec/ucsi/ucsi.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
index 3f568f790f39..7b718049d0d1 100644
--- a/drivers/usb/typec/ucsi/ucsi.c
+++ b/drivers/usb/typec/ucsi/ucsi.c
@@ -1022,14 +1022,17 @@ static void ucsi_pwr_opmode_change(struct ucsi_connector *con)
 	case UCSI_CONSTAT_PWR_OPMODE_TYPEC1_5:
 		con->rdo = 0;
 		typec_set_pwr_opmode(con->port, TYPEC_PWR_MODE_1_5A);
+		ucsi_port_psy_changed(con);
 		break;
 	case UCSI_CONSTAT_PWR_OPMODE_TYPEC3_0:
 		con->rdo = 0;
 		typec_set_pwr_opmode(con->port, TYPEC_PWR_MODE_3_0A);
+		ucsi_port_psy_changed(con);
 		break;
 	default:
 		con->rdo = 0;
 		typec_set_pwr_opmode(con->port, TYPEC_PWR_MODE_USB);
+		ucsi_port_psy_changed(con);
 		break;
 	}
 }
-- 
2.51.0.618.g983fd99d29-goog


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

* [PATCH 4/6] usb: typec: ucsi: Report power supply change on sink path change
  2025-10-07  0:00 [PATCH 0/6] UCSI Power Supply Updates and Bug Fixes Jameson Thies
                   ` (2 preceding siblings ...)
  2025-10-07  0:00 ` [PATCH 3/6] usb: typec: ucsi: Report power supply changes on power opmode changes Jameson Thies
@ 2025-10-07  0:00 ` Jameson Thies
  2025-10-07 23:52   ` Benson Leung
  2025-10-08 13:06   ` Heikki Krogerus
  2025-10-07  0:00 ` [PATCH 5/6] usb: typec: ucsi: psy: Set max current to zero when disconnected Jameson Thies
                   ` (3 subsequent siblings)
  7 siblings, 2 replies; 27+ messages in thread
From: Jameson Thies @ 2025-10-07  0:00 UTC (permalink / raw)
  To: heikki.krogerus, linux-usb, linux-kernel
  Cc: jthies, dmitry.baryshkov, bleung, gregkh, akuchynski,
	abhishekpandit, sebastian.reichel, linux-pm

Update the UCSI interface driver to report a power supply change when
the PPM sets the Sink Path Change bit.

Signed-off-by: Jameson Thies <jthies@google.com>
---
 drivers/usb/typec/ucsi/ucsi.c | 2 +-
 drivers/usb/typec/ucsi/ucsi.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
index 7b718049d0d1..1a7d850b11ea 100644
--- a/drivers/usb/typec/ucsi/ucsi.c
+++ b/drivers/usb/typec/ucsi/ucsi.c
@@ -1293,7 +1293,7 @@ static void ucsi_handle_connector_change(struct work_struct *work)
 	if (change & UCSI_CONSTAT_CAM_CHANGE)
 		ucsi_partner_task(con, ucsi_check_altmodes, 1, HZ);
 
-	if (change & UCSI_CONSTAT_BC_CHANGE)
+	if (change & UCSI_CONSTAT_BC_CHANGE || change & UCSI_CONSTAT_SINK_PATH_CHANGE)
 		ucsi_port_psy_changed(con);
 
 	if (con->ucsi->version >= UCSI_VERSION_2_1 &&
diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h
index cce93af7461b..35993bc34d4d 100644
--- a/drivers/usb/typec/ucsi/ucsi.h
+++ b/drivers/usb/typec/ucsi/ucsi.h
@@ -382,6 +382,7 @@ struct ucsi_cable_property {
 #define UCSI_CONSTAT_BC_CHANGE			BIT(9)
 #define UCSI_CONSTAT_PARTNER_CHANGE		BIT(11)
 #define UCSI_CONSTAT_POWER_DIR_CHANGE		BIT(12)
+#define UCSI_CONSTAT_SINK_PATH_CHANGE		BIT(13)
 #define UCSI_CONSTAT_CONNECT_CHANGE		BIT(14)
 #define UCSI_CONSTAT_ERROR			BIT(15)
 
-- 
2.51.0.618.g983fd99d29-goog


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

* [PATCH 5/6] usb: typec: ucsi: psy: Set max current to zero when disconnected
  2025-10-07  0:00 [PATCH 0/6] UCSI Power Supply Updates and Bug Fixes Jameson Thies
                   ` (3 preceding siblings ...)
  2025-10-07  0:00 ` [PATCH 4/6] usb: typec: ucsi: Report power supply change on sink path change Jameson Thies
@ 2025-10-07  0:00 ` 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
                   ` (2 subsequent siblings)
  7 siblings, 2 replies; 27+ messages in thread
From: Jameson Thies @ 2025-10-07  0:00 UTC (permalink / raw)
  To: heikki.krogerus, linux-usb, linux-kernel
  Cc: jthies, dmitry.baryshkov, bleung, gregkh, akuchynski,
	abhishekpandit, sebastian.reichel, linux-pm

The ucsi_psy_get_current_max function defaults to 0.1A when it is not
clear how much current the partner device can support. But this does
not check the port is connected, and will report 0.1A max current when
nothing is connected. Update ucsi_psy_get_current_max to report 0A when
there is no connection.

Signed-off-by: Jameson Thies <jthies@google.com>
---
 drivers/usb/typec/ucsi/psy.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/usb/typec/ucsi/psy.c b/drivers/usb/typec/ucsi/psy.c
index 985a90d3f898..3a209de55c14 100644
--- a/drivers/usb/typec/ucsi/psy.c
+++ b/drivers/usb/typec/ucsi/psy.c
@@ -169,6 +169,11 @@ static int ucsi_psy_get_current_max(struct ucsi_connector *con,
 {
 	u32 pdo;
 
+	if (!UCSI_CONSTAT(con, CONNECTED)) {
+		val->intval = 0;
+		return 0;
+	}
+
 	switch (UCSI_CONSTAT(con, PWR_OPMODE)) {
 	case UCSI_CONSTAT_PWR_OPMODE_PD:
 		if (con->num_pdos > 0) {
-- 
2.51.0.618.g983fd99d29-goog


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

* [PATCH 6/6] usb: typec: ucsi: pr_swap should check connector_status
  2025-10-07  0:00 [PATCH 0/6] UCSI Power Supply Updates and Bug Fixes Jameson Thies
                   ` (4 preceding siblings ...)
  2025-10-07  0:00 ` [PATCH 5/6] usb: typec: ucsi: psy: Set max current to zero when disconnected Jameson Thies
@ 2025-10-07  0:00 ` Jameson Thies
  2025-10-07 23:56   ` Benson Leung
  2025-10-08 13:10   ` Heikki Krogerus
  2025-10-13  7:33 ` [PATCH 0/6] UCSI Power Supply Updates and Bug Fixes Greg KH
  2025-10-13 21:02 ` Kenneth Crudup
  7 siblings, 2 replies; 27+ messages in thread
From: Jameson Thies @ 2025-10-07  0:00 UTC (permalink / raw)
  To: heikki.krogerus, linux-usb, linux-kernel
  Cc: jthies, dmitry.baryshkov, bleung, gregkh, akuchynski,
	abhishekpandit, sebastian.reichel, linux-pm

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


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

* Re: [PATCH 2/6] usb: typec: ucsi: psy: Add support for DRP USB type
  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
  1 sibling, 0 replies; 27+ messages in thread
From: Benson Leung @ 2025-10-07 23:50 UTC (permalink / raw)
  To: Jameson Thies
  Cc: heikki.krogerus, linux-usb, linux-kernel, dmitry.baryshkov,
	bleung, gregkh, akuchynski, abhishekpandit, sebastian.reichel,
	linux-pm

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

Hi Jameson,

Quick nit about looking through and finding the Dual-Role Power bit.

On Tue, Oct 07, 2025 at 12:00:03AM +0000, Jameson Thies wrote:
> The USB Type registered with the power supply class is based on the
> current power operation mode of the port. When the port is using USB
> PD and is connected to a DRP partner, report that the power supply's
> USB type is USB PD DRP.
> 
> Signed-off-by: Jameson Thies <jthies@google.com>
> ---
>  drivers/usb/typec/ucsi/psy.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/ucsi/psy.c b/drivers/usb/typec/ucsi/psy.c
> index 2b0225821502..985a90d3f898 100644
> --- a/drivers/usb/typec/ucsi/psy.c
> +++ b/drivers/usb/typec/ucsi/psy.c
> @@ -209,8 +209,16 @@ static int ucsi_psy_get_usb_type(struct ucsi_connector *con,
>  {
>  	val->intval = POWER_SUPPLY_USB_TYPE_C;
>  	if (UCSI_CONSTAT(con, CONNECTED) &&
> -	    UCSI_CONSTAT(con, PWR_OPMODE) == UCSI_CONSTAT_PWR_OPMODE_PD)
> +	    UCSI_CONSTAT(con, PWR_OPMODE) == UCSI_CONSTAT_PWR_OPMODE_PD) {
> +		for (int i = 0; i < con->num_pdos; i++) {

Do you really need to iterate through the whole list of pdos to find this?

The DRP bit is guaranteed to be always in the 5V PDO, which is guaranteed to
be the 0th one.

See USB PD R3.2 V1.1 Section 6.4.1.3.1 Sink Fixed Supply Power Data Object

"Since all USB Consumers support vSafe5V, the required vSafe5V Fixed Supply
Power Data Object is also used to convey additional information that is
returned in bits 29 through 20. All other Fixed Supply Power Data Objects
Shall set bits 29…20 to zero."

> +			if (pdo_type(con->src_pdos[i]) == PDO_TYPE_FIXED &&
> +			    con->src_pdos[i] & PDO_FIXED_DUAL_ROLE) {
> +				val->intval = POWER_SUPPLY_USB_TYPE_PD_DRP;
> +				return 0;
> +			}
> +		}
>  		val->intval = POWER_SUPPLY_USB_TYPE_PD;
> +	}
>  
>  	return 0;
>  }
> -- 
> 2.51.0.618.g983fd99d29-goog
> 

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

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

* Re: [PATCH 3/6] usb: typec: ucsi: Report power supply changes on power opmode changes
  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
  1 sibling, 0 replies; 27+ messages in thread
From: Benson Leung @ 2025-10-07 23:51 UTC (permalink / raw)
  To: Jameson Thies
  Cc: heikki.krogerus, linux-usb, linux-kernel, dmitry.baryshkov,
	bleung, gregkh, akuchynski, abhishekpandit, sebastian.reichel,
	linux-pm

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

On Tue, Oct 07, 2025 at 12:00:04AM +0000, Jameson Thies wrote:
> Report opmode changes from the PPM to the power supply class by calling
> ucsi_port_psy_changed(). If the current opmode is USB PD, do not call
> ucsi_port_psy_changed(). The power supply class will be updated after
> requesting partner source PDOs.
> 
> Signed-off-by: Jameson Thies <jthies@google.com>

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


> ---
>  drivers/usb/typec/ucsi/ucsi.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index 3f568f790f39..7b718049d0d1 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -1022,14 +1022,17 @@ static void ucsi_pwr_opmode_change(struct ucsi_connector *con)
>  	case UCSI_CONSTAT_PWR_OPMODE_TYPEC1_5:
>  		con->rdo = 0;
>  		typec_set_pwr_opmode(con->port, TYPEC_PWR_MODE_1_5A);
> +		ucsi_port_psy_changed(con);
>  		break;
>  	case UCSI_CONSTAT_PWR_OPMODE_TYPEC3_0:
>  		con->rdo = 0;
>  		typec_set_pwr_opmode(con->port, TYPEC_PWR_MODE_3_0A);
> +		ucsi_port_psy_changed(con);
>  		break;
>  	default:
>  		con->rdo = 0;
>  		typec_set_pwr_opmode(con->port, TYPEC_PWR_MODE_USB);
> +		ucsi_port_psy_changed(con);
>  		break;
>  	}
>  }
> -- 
> 2.51.0.618.g983fd99d29-goog
> 

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

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

* Re: [PATCH 4/6] usb: typec: ucsi: Report power supply change on sink path change
  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
  1 sibling, 0 replies; 27+ messages in thread
From: Benson Leung @ 2025-10-07 23:52 UTC (permalink / raw)
  To: Jameson Thies
  Cc: heikki.krogerus, linux-usb, linux-kernel, dmitry.baryshkov,
	bleung, gregkh, akuchynski, abhishekpandit, sebastian.reichel,
	linux-pm

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

On Tue, Oct 07, 2025 at 12:00:05AM +0000, Jameson Thies wrote:
> Update the UCSI interface driver to report a power supply change when
> the PPM sets the Sink Path Change bit.
> 
> Signed-off-by: Jameson Thies <jthies@google.com>

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


> ---
>  drivers/usb/typec/ucsi/ucsi.c | 2 +-
>  drivers/usb/typec/ucsi/ucsi.h | 1 +
>  2 files changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index 7b718049d0d1..1a7d850b11ea 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -1293,7 +1293,7 @@ static void ucsi_handle_connector_change(struct work_struct *work)
>  	if (change & UCSI_CONSTAT_CAM_CHANGE)
>  		ucsi_partner_task(con, ucsi_check_altmodes, 1, HZ);
>  
> -	if (change & UCSI_CONSTAT_BC_CHANGE)
> +	if (change & UCSI_CONSTAT_BC_CHANGE || change & UCSI_CONSTAT_SINK_PATH_CHANGE)
>  		ucsi_port_psy_changed(con);
>  
>  	if (con->ucsi->version >= UCSI_VERSION_2_1 &&
> diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h
> index cce93af7461b..35993bc34d4d 100644
> --- a/drivers/usb/typec/ucsi/ucsi.h
> +++ b/drivers/usb/typec/ucsi/ucsi.h
> @@ -382,6 +382,7 @@ struct ucsi_cable_property {
>  #define UCSI_CONSTAT_BC_CHANGE			BIT(9)
>  #define UCSI_CONSTAT_PARTNER_CHANGE		BIT(11)
>  #define UCSI_CONSTAT_POWER_DIR_CHANGE		BIT(12)
> +#define UCSI_CONSTAT_SINK_PATH_CHANGE		BIT(13)
>  #define UCSI_CONSTAT_CONNECT_CHANGE		BIT(14)
>  #define UCSI_CONSTAT_ERROR			BIT(15)
>  
> -- 
> 2.51.0.618.g983fd99d29-goog
> 

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

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

* Re: [PATCH 5/6] usb: typec: ucsi: psy: Set max current to zero when disconnected
  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
  1 sibling, 0 replies; 27+ messages in thread
From: Benson Leung @ 2025-10-07 23:55 UTC (permalink / raw)
  To: Jameson Thies
  Cc: heikki.krogerus, linux-usb, linux-kernel, dmitry.baryshkov,
	bleung, gregkh, akuchynski, abhishekpandit, sebastian.reichel,
	linux-pm

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

On Tue, Oct 07, 2025 at 12:00:06AM +0000, Jameson Thies wrote:
> The ucsi_psy_get_current_max function defaults to 0.1A when it is not
> clear how much current the partner device can support. But this does
> not check the port is connected, and will report 0.1A max current when
> nothing is connected. Update ucsi_psy_get_current_max to report 0A when
> there is no connection.
> 
> Signed-off-by: Jameson Thies <jthies@google.com>

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


> ---
>  drivers/usb/typec/ucsi/psy.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/usb/typec/ucsi/psy.c b/drivers/usb/typec/ucsi/psy.c
> index 985a90d3f898..3a209de55c14 100644
> --- a/drivers/usb/typec/ucsi/psy.c
> +++ b/drivers/usb/typec/ucsi/psy.c
> @@ -169,6 +169,11 @@ static int ucsi_psy_get_current_max(struct ucsi_connector *con,
>  {
>  	u32 pdo;
>  
> +	if (!UCSI_CONSTAT(con, CONNECTED)) {
> +		val->intval = 0;
> +		return 0;
> +	}
> +
>  	switch (UCSI_CONSTAT(con, PWR_OPMODE)) {
>  	case UCSI_CONSTAT_PWR_OPMODE_PD:
>  		if (con->num_pdos > 0) {
> -- 
> 2.51.0.618.g983fd99d29-goog
> 

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

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

* Re: [PATCH 6/6] usb: typec: ucsi: pr_swap should check connector_status
  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
  2025-10-08 13:10   ` Heikki Krogerus
  1 sibling, 0 replies; 27+ messages in thread
From: Benson Leung @ 2025-10-07 23:56 UTC (permalink / raw)
  To: Jameson Thies
  Cc: heikki.krogerus, linux-usb, linux-kernel, dmitry.baryshkov,
	bleung, gregkh, akuchynski, abhishekpandit, sebastian.reichel,
	linux-pm

[-- 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 --]

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

* Re: [PATCH 1/6] usb: typec: ucsi: psy: Add power supply status
  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
  0 siblings, 0 replies; 27+ messages in thread
From: Heikki Krogerus @ 2025-10-08 12:53 UTC (permalink / raw)
  To: Jameson Thies
  Cc: linux-usb, linux-kernel, dmitry.baryshkov, bleung, gregkh,
	akuchynski, abhishekpandit, sebastian.reichel, linux-pm

On Tue, Oct 07, 2025 at 12:00:02AM +0000, Jameson Thies wrote:
> Add support for power supply status. If a port is acting as a sink
> with the sink path enabled, report it is charging. If a port is
> source, report it is discharging. If there is no connection or the
> port hasn't enabled the sink path, report not charging.
> 
> Signed-off-by: Jameson Thies <jthies@google.com>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/usb/typec/ucsi/psy.c  | 26 ++++++++++++++++++++++++++
>  drivers/usb/typec/ucsi/ucsi.h |  3 +++
>  2 files changed, 29 insertions(+)
> 
> diff --git a/drivers/usb/typec/ucsi/psy.c b/drivers/usb/typec/ucsi/psy.c
> index 62a9d68bb66d..2b0225821502 100644
> --- a/drivers/usb/typec/ucsi/psy.c
> +++ b/drivers/usb/typec/ucsi/psy.c
> @@ -29,6 +29,7 @@ static enum power_supply_property ucsi_psy_props[] = {
>  	POWER_SUPPLY_PROP_CURRENT_MAX,
>  	POWER_SUPPLY_PROP_CURRENT_NOW,
>  	POWER_SUPPLY_PROP_SCOPE,
> +	POWER_SUPPLY_PROP_STATUS,
>  };
>  
>  static int ucsi_psy_get_scope(struct ucsi_connector *con,
> @@ -51,6 +52,29 @@ static int ucsi_psy_get_scope(struct ucsi_connector *con,
>  	return 0;
>  }
>  
> +static int ucsi_psy_get_status(struct ucsi_connector *con,
> +			       union power_supply_propval *val)
> +{
> +	bool is_sink = UCSI_CONSTAT(con, PWR_DIR) == TYPEC_SINK;
> +	bool sink_path_enabled = true;
> +
> +	val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
> +
> +	if (con->ucsi->version >= UCSI_VERSION_2_0)
> +		sink_path_enabled =
> +			UCSI_CONSTAT(con, SINK_PATH_STATUS_V2_0) ==
> +			UCSI_CONSTAT_SINK_PATH_ENABLED;
> +
> +	if (UCSI_CONSTAT(con, CONNECTED)) {
> +		if (is_sink && sink_path_enabled)
> +			val->intval = POWER_SUPPLY_STATUS_CHARGING;
> +		else if (!is_sink)
> +			val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
> +	}
> +
> +	return 0;
> +}
> +
>  static int ucsi_psy_get_online(struct ucsi_connector *con,
>  			       union power_supply_propval *val)
>  {
> @@ -245,6 +269,8 @@ static int ucsi_psy_get_prop(struct power_supply *psy,
>  		return ucsi_psy_get_current_now(con, val);
>  	case POWER_SUPPLY_PROP_SCOPE:
>  		return ucsi_psy_get_scope(con, val);
> +	case POWER_SUPPLY_PROP_STATUS:
> +		return ucsi_psy_get_status(con, val);
>  	default:
>  		return -EINVAL;
>  	}
> diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h
> index e301d9012936..cce93af7461b 100644
> --- a/drivers/usb/typec/ucsi/ucsi.h
> +++ b/drivers/usb/typec/ucsi/ucsi.h
> @@ -360,6 +360,9 @@ struct ucsi_cable_property {
>  #define   UCSI_CONSTAT_BC_SLOW_CHARGING		2
>  #define   UCSI_CONSTAT_BC_TRICKLE_CHARGING	3
>  #define UCSI_CONSTAT_PD_VERSION_V1_2		UCSI_DECLARE_BITFIELD_V1_2(70, 16)
> +#define UCSI_CONSTAT_SINK_PATH_STATUS_V2_0	UCSI_DECLARE_BITFIELD_V2_0(87, 1)
> +#define   UCSI_CONSTAT_SINK_PATH_DISABLED   0
> +#define   UCSI_CONSTAT_SINK_PATH_ENABLED    1
>  #define UCSI_CONSTAT_PWR_READING_READY_V2_1	UCSI_DECLARE_BITFIELD_V2_1(89, 1)
>  #define UCSI_CONSTAT_CURRENT_SCALE_V2_1		UCSI_DECLARE_BITFIELD_V2_1(90, 3)
>  #define UCSI_CONSTAT_PEAK_CURRENT_V2_1		UCSI_DECLARE_BITFIELD_V2_1(93, 16)
> -- 
> 2.51.0.618.g983fd99d29-goog

-- 
heikki

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

* Re: [PATCH 2/6] usb: typec: ucsi: psy: Add support for DRP USB type
  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
  1 sibling, 1 reply; 27+ messages in thread
From: Heikki Krogerus @ 2025-10-08 13:02 UTC (permalink / raw)
  To: Jameson Thies
  Cc: linux-usb, linux-kernel, dmitry.baryshkov, bleung, gregkh,
	akuchynski, abhishekpandit, sebastian.reichel, linux-pm

On Tue, Oct 07, 2025 at 12:00:03AM +0000, Jameson Thies wrote:
> The USB Type registered with the power supply class is based on the
> current power operation mode of the port. When the port is using USB
> PD and is connected to a DRP partner, report that the power supply's
> USB type is USB PD DRP.
> 
> Signed-off-by: Jameson Thies <jthies@google.com>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/usb/typec/ucsi/psy.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/ucsi/psy.c b/drivers/usb/typec/ucsi/psy.c
> index 2b0225821502..985a90d3f898 100644
> --- a/drivers/usb/typec/ucsi/psy.c
> +++ b/drivers/usb/typec/ucsi/psy.c
> @@ -209,8 +209,16 @@ static int ucsi_psy_get_usb_type(struct ucsi_connector *con,
>  {
>  	val->intval = POWER_SUPPLY_USB_TYPE_C;
>  	if (UCSI_CONSTAT(con, CONNECTED) &&
> -	    UCSI_CONSTAT(con, PWR_OPMODE) == UCSI_CONSTAT_PWR_OPMODE_PD)
> +	    UCSI_CONSTAT(con, PWR_OPMODE) == UCSI_CONSTAT_PWR_OPMODE_PD) {
> +		for (int i = 0; i < con->num_pdos; i++) {
> +			if (pdo_type(con->src_pdos[i]) == PDO_TYPE_FIXED &&
> +			    con->src_pdos[i] & PDO_FIXED_DUAL_ROLE) {
> +				val->intval = POWER_SUPPLY_USB_TYPE_PD_DRP;
> +				return 0;
> +			}
> +		}
>  		val->intval = POWER_SUPPLY_USB_TYPE_PD;
> +	}
>  
>  	return 0;
>  }
> -- 
> 2.51.0.618.g983fd99d29-goog

-- 
heikki

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

* Re: [PATCH 3/6] usb: typec: ucsi: Report power supply changes on power opmode changes
  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
  1 sibling, 0 replies; 27+ messages in thread
From: Heikki Krogerus @ 2025-10-08 13:02 UTC (permalink / raw)
  To: Jameson Thies
  Cc: linux-usb, linux-kernel, dmitry.baryshkov, bleung, gregkh,
	akuchynski, abhishekpandit, sebastian.reichel, linux-pm

On Tue, Oct 07, 2025 at 12:00:04AM +0000, Jameson Thies wrote:
> Report opmode changes from the PPM to the power supply class by calling
> ucsi_port_psy_changed(). If the current opmode is USB PD, do not call
> ucsi_port_psy_changed(). The power supply class will be updated after
> requesting partner source PDOs.
> 
> Signed-off-by: Jameson Thies <jthies@google.com>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/usb/typec/ucsi/ucsi.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index 3f568f790f39..7b718049d0d1 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -1022,14 +1022,17 @@ static void ucsi_pwr_opmode_change(struct ucsi_connector *con)
>  	case UCSI_CONSTAT_PWR_OPMODE_TYPEC1_5:
>  		con->rdo = 0;
>  		typec_set_pwr_opmode(con->port, TYPEC_PWR_MODE_1_5A);
> +		ucsi_port_psy_changed(con);
>  		break;
>  	case UCSI_CONSTAT_PWR_OPMODE_TYPEC3_0:
>  		con->rdo = 0;
>  		typec_set_pwr_opmode(con->port, TYPEC_PWR_MODE_3_0A);
> +		ucsi_port_psy_changed(con);
>  		break;
>  	default:
>  		con->rdo = 0;
>  		typec_set_pwr_opmode(con->port, TYPEC_PWR_MODE_USB);
> +		ucsi_port_psy_changed(con);
>  		break;
>  	}
>  }
> -- 
> 2.51.0.618.g983fd99d29-goog

-- 
heikki

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

* Re: [PATCH 4/6] usb: typec: ucsi: Report power supply change on sink path change
  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
  1 sibling, 1 reply; 27+ messages in thread
From: Heikki Krogerus @ 2025-10-08 13:06 UTC (permalink / raw)
  To: Jameson Thies
  Cc: linux-usb, linux-kernel, dmitry.baryshkov, bleung, gregkh,
	akuchynski, abhishekpandit, sebastian.reichel, linux-pm

On Tue, Oct 07, 2025 at 12:00:05AM +0000, Jameson Thies wrote:
> Update the UCSI interface driver to report a power supply change when
> the PPM sets the Sink Path Change bit.
> 
> Signed-off-by: Jameson Thies <jthies@google.com>
> ---
>  drivers/usb/typec/ucsi/ucsi.c | 2 +-
>  drivers/usb/typec/ucsi/ucsi.h | 1 +
>  2 files changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index 7b718049d0d1..1a7d850b11ea 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -1293,7 +1293,7 @@ static void ucsi_handle_connector_change(struct work_struct *work)
>  	if (change & UCSI_CONSTAT_CAM_CHANGE)
>  		ucsi_partner_task(con, ucsi_check_altmodes, 1, HZ);
>  
> -	if (change & UCSI_CONSTAT_BC_CHANGE)
> +	if (change & UCSI_CONSTAT_BC_CHANGE || change & UCSI_CONSTAT_SINK_PATH_CHANGE)

How about:

if (change & (UCSI_CONSTAT_BC_CHANGE | UCSI_CONSTAT_SINK_PATH_CHANGE))

>  		ucsi_port_psy_changed(con);
>  
>  	if (con->ucsi->version >= UCSI_VERSION_2_1 &&
> diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h
> index cce93af7461b..35993bc34d4d 100644
> --- a/drivers/usb/typec/ucsi/ucsi.h
> +++ b/drivers/usb/typec/ucsi/ucsi.h
> @@ -382,6 +382,7 @@ struct ucsi_cable_property {
>  #define UCSI_CONSTAT_BC_CHANGE			BIT(9)
>  #define UCSI_CONSTAT_PARTNER_CHANGE		BIT(11)
>  #define UCSI_CONSTAT_POWER_DIR_CHANGE		BIT(12)
> +#define UCSI_CONSTAT_SINK_PATH_CHANGE		BIT(13)
>  #define UCSI_CONSTAT_CONNECT_CHANGE		BIT(14)
>  #define UCSI_CONSTAT_ERROR			BIT(15)
>  
> -- 
> 2.51.0.618.g983fd99d29-goog

-- 
heikki

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

* Re: [PATCH 5/6] usb: typec: ucsi: psy: Set max current to zero when disconnected
  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
  1 sibling, 0 replies; 27+ messages in thread
From: Heikki Krogerus @ 2025-10-08 13:08 UTC (permalink / raw)
  To: Jameson Thies
  Cc: linux-usb, linux-kernel, dmitry.baryshkov, bleung, gregkh,
	akuchynski, abhishekpandit, sebastian.reichel, linux-pm

On Tue, Oct 07, 2025 at 12:00:06AM +0000, Jameson Thies wrote:
> The ucsi_psy_get_current_max function defaults to 0.1A when it is not
> clear how much current the partner device can support. But this does
> not check the port is connected, and will report 0.1A max current when
> nothing is connected. Update ucsi_psy_get_current_max to report 0A when
> there is no connection.
> 
> Signed-off-by: Jameson Thies <jthies@google.com>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/usb/typec/ucsi/psy.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/usb/typec/ucsi/psy.c b/drivers/usb/typec/ucsi/psy.c
> index 985a90d3f898..3a209de55c14 100644
> --- a/drivers/usb/typec/ucsi/psy.c
> +++ b/drivers/usb/typec/ucsi/psy.c
> @@ -169,6 +169,11 @@ static int ucsi_psy_get_current_max(struct ucsi_connector *con,
>  {
>  	u32 pdo;
>  
> +	if (!UCSI_CONSTAT(con, CONNECTED)) {
> +		val->intval = 0;
> +		return 0;
> +	}
> +
>  	switch (UCSI_CONSTAT(con, PWR_OPMODE)) {
>  	case UCSI_CONSTAT_PWR_OPMODE_PD:
>  		if (con->num_pdos > 0) {
> -- 
> 2.51.0.618.g983fd99d29-goog

-- 
heikki

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

* Re: [PATCH 6/6] usb: typec: ucsi: pr_swap should check connector_status
  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
@ 2025-10-08 13:10   ` Heikki Krogerus
  2025-10-13 20:56     ` Jameson Thies
  1 sibling, 1 reply; 27+ messages in thread
From: Heikki Krogerus @ 2025-10-08 13:10 UTC (permalink / raw)
  To: Jameson Thies
  Cc: linux-usb, linux-kernel, dmitry.baryshkov, bleung, gregkh,
	akuchynski, abhishekpandit, sebastian.reichel, linux-pm

Hi,

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>
> ---
>  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;

Couldn't you use the helper ucsi_get_connector_status() ?

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

Please align those properly.

> +			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);
>  

Maybe this could be send separately? It does not seem to be directly
ucsi psy related.

thanks,

-- 
heikki

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

* Re: [PATCH 0/6] UCSI Power Supply Updates and Bug Fixes
  2025-10-07  0:00 [PATCH 0/6] UCSI Power Supply Updates and Bug Fixes Jameson Thies
                   ` (5 preceding siblings ...)
  2025-10-07  0:00 ` [PATCH 6/6] usb: typec: ucsi: pr_swap should check connector_status Jameson Thies
@ 2025-10-13  7:33 ` Greg KH
  2025-10-13 20:59   ` Jameson Thies
  2025-10-13 21:02 ` Kenneth Crudup
  7 siblings, 1 reply; 27+ messages in thread
From: Greg KH @ 2025-10-13  7:33 UTC (permalink / raw)
  To: Jameson Thies
  Cc: heikki.krogerus, linux-usb, linux-kernel, dmitry.baryshkov,
	bleung, akuchynski, abhishekpandit, sebastian.reichel, linux-pm

On Tue, Oct 07, 2025 at 12:00:01AM +0000, Jameson Thies wrote:
> This series includes the following minor changes to power supply
> handling by the UCSI driver.
> 
> 1) Adds the "Status" property to power supplies registered by the UCSI
> driver.
> 2) Reports power supply USB type as "DRP" when the port partner is a
> DRP.
> 3) Updates ucsi.c to report a power supply change all power opmode
> changes. Currently this only gets reported when opmode is PD.
> 4) Updates ucsi.c to report a power supply change when the PPM signals
> a sink path change.
> 5) Set max current to 0 when no device is connected. Currently this
> defaults to 0.1A.
> 6) Updates connector status after initiating a PR swap. Following the
> UCSI spec, there is no reported change following a successful SET_PDR
> command. This results in the stored connector status being outdated.
> 
> Abhishek Pandit-Subedi (1):
>   usb: typec: ucsi: pr_swap should check connector_status
> 
> Jameson Thies (5):
>   usb: typec: ucsi: psy: Add power supply status
>   usb: typec: ucsi: psy: Add support for DRP USB type
>   usb: typec: ucsi: Report power supply changes on power opmode changes
>   usb: typec: ucsi: Report power supply change on sink path change
>   usb: typec: ucsi: psy: Set max current to zero when disconnected

Please do not mix bug fixes and updates to the driver in the same patch
series, as that means the bug fixes will be delayed until the next
release, not the current one, as I can't take them all at once.

thanks,

greg k-h

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

* Re: [PATCH 2/6] usb: typec: ucsi: psy: Add support for DRP USB type
  2025-10-08 13:02   ` Heikki Krogerus
@ 2025-10-13 20:44     ` Jameson Thies
  0 siblings, 0 replies; 27+ messages in thread
From: Jameson Thies @ 2025-10-13 20:44 UTC (permalink / raw)
  To: Heikki Krogerus
  Cc: linux-usb, linux-kernel, dmitry.baryshkov, bleung, gregkh,
	akuchynski, abhishekpandit, sebastian.reichel, linux-pm

Hi Benson

> Do you really need to iterate through the whole list of pdos to find this?
>
> The DRP bit is guaranteed to be always in the 5V PDO, which is guaranteed to
> be the 0th one.

Thanks for taking a look. This sounds like a good optimization, I'll
apply it to the v2 series.

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

* Re: [PATCH 4/6] usb: typec: ucsi: Report power supply change on sink path change
  2025-10-08 13:06   ` Heikki Krogerus
@ 2025-10-13 20:45     ` Jameson Thies
  0 siblings, 0 replies; 27+ messages in thread
From: Jameson Thies @ 2025-10-13 20:45 UTC (permalink / raw)
  To: Heikki Krogerus
  Cc: linux-usb, linux-kernel, dmitry.baryshkov, bleung, gregkh,
	akuchynski, abhishekpandit, sebastian.reichel, linux-pm

> How about:
>
> if (change & (UCSI_CONSTAT_BC_CHANGE | UCSI_CONSTAT_SINK_PATH_CHANGE))

Thank you for the suggestion, this is neater. I'll apply it to the v2 series.

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

* Re: [PATCH 6/6] usb: typec: ucsi: pr_swap should check connector_status
  2025-10-08 13:10   ` Heikki Krogerus
@ 2025-10-13 20:56     ` Jameson Thies
  0 siblings, 0 replies; 27+ messages in thread
From: Jameson Thies @ 2025-10-13 20:56 UTC (permalink / raw)
  To: Heikki Krogerus
  Cc: linux-usb, linux-kernel, dmitry.baryshkov, bleung, gregkh,
	akuchynski, abhishekpandit, sebastian.reichel, linux-pm

> Couldn't you use the helper ucsi_get_connector_status() ?

That work, I'll switch to using the helper here.

> Maybe this could be send separately? It does not seem to be directly
> ucsi psy related.

Sounds good to me. The same issue can happen with DR swaps, so I'll
also update the patch to refresh connector status after sending
SET_UOR.

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

* Re: [PATCH 0/6] UCSI Power Supply Updates and Bug Fixes
  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
  0 siblings, 1 reply; 27+ messages in thread
From: Jameson Thies @ 2025-10-13 20:59 UTC (permalink / raw)
  To: Greg KH
  Cc: heikki.krogerus, linux-usb, linux-kernel, dmitry.baryshkov,
	bleung, akuchynski, abhishekpandit, sebastian.reichel, linux-pm

Thank you for this feedback. The only patch here which is a clear bug
fix is 5/6. Currently the driver reports 0.1A max current when nothing
is connected on the port. I'll send that patch separately.

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

* Re: [PATCH 0/6] UCSI Power Supply Updates and Bug Fixes
  2025-10-07  0:00 [PATCH 0/6] UCSI Power Supply Updates and Bug Fixes Jameson Thies
                   ` (6 preceding siblings ...)
  2025-10-13  7:33 ` [PATCH 0/6] UCSI Power Supply Updates and Bug Fixes Greg KH
@ 2025-10-13 21:02 ` Kenneth Crudup
  2025-10-13 22:53   ` Jameson Thies
  7 siblings, 1 reply; 27+ messages in thread
From: Kenneth Crudup @ 2025-10-13 21:02 UTC (permalink / raw)
  To: Jameson Thies, heikki.krogerus, linux-usb, linux-kernel
  Cc: dmitry.baryshkov, bleung, gregkh, akuchynski, abhishekpandit,
	sebastian.reichel, linux-pm, Kenneth C


On 10/6/25 17:00, Jameson Thies wrote:

> This series includes the following minor changes to power supply
> handling by the UCSI driver.
...
> base-commit: e40b984b6c4ce3f80814f39f86f87b2a48f2e662

I wanted to let you know that on my Dell XPS-9320, this patchset ended 
up spamming (i.e., hundreds) my dmesg with the following:

power_supply ucsi-source-psy-USBC000:002: driver reporting unavailable 
enum value 7

... which I believe to be POWER_SUPPLY_USB_TYPE_PD_DRP .

In my case it was coming from the call to 
power_supply_show_enum_with_available() on/around line 380 in 
.../drivers/power/supply/power_supply_sysfs.c ; I'd tried adding 
POWER_SUPPLY_USB_TYPE_PD_DRP to con->psy_desc.usb_types in 
ucsi_register_port_psy() in
.../drivers/usb/typec/ucsi/psy.c thinking that may fix it with no success.

LMK if you need any further info,

-Kenny

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


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

* Re: [PATCH 0/6] UCSI Power Supply Updates and Bug Fixes
  2025-10-13 21:02 ` Kenneth Crudup
@ 2025-10-13 22:53   ` Jameson Thies
  2025-10-13 23:26     ` Kenneth Crudup
  0 siblings, 1 reply; 27+ messages in thread
From: Jameson Thies @ 2025-10-13 22:53 UTC (permalink / raw)
  To: Kenneth Crudup
  Cc: heikki.krogerus, linux-usb, linux-kernel, dmitry.baryshkov,
	bleung, gregkh, akuchynski, abhishekpandit, sebastian.reichel,
	linux-pm

Hi Kenneth,
You are correct that adding POWER_SUPPLY_USB_TYPE_PD_DRP in
ucsi_register_port_psy() is missing here. I would have expected that
adding it resolves the issue. I'll take a closer look, thanks for
raising this.

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

* Re: [PATCH 0/6] UCSI Power Supply Updates and Bug Fixes
  2025-10-13 22:53   ` Jameson Thies
@ 2025-10-13 23:26     ` Kenneth Crudup
  0 siblings, 0 replies; 27+ messages in thread
From: Kenneth Crudup @ 2025-10-13 23:26 UTC (permalink / raw)
  To: Jameson Thies
  Cc: heikki.krogerus, linux-usb, linux-kernel, dmitry.baryshkov,
	bleung, gregkh, akuchynski, abhishekpandit, sebastian.reichel,
	linux-pm, Kenneth C



On 10/13/25 15:53, Jameson Thies wrote:

> You are correct that adding POWER_SUPPLY_USB_TYPE_PD_DRP in
> ucsi_register_port_psy() is missing here. I would have expected that
> adding it resolves the issue. 

The issue must be deeper than that, as I even went as far as making the 
check for "allowed types" pass all the time (as the dmesg was swamped 
making booting difficult so debugging was somewhat painful) and was 
still getting "enum" errors.

... that being said, I had a flight to catch on Friday so didn't keep 
working on a fix.

-Kenny

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


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

* Re: [PATCH 0/6] UCSI Power Supply Updates and Bug Fixes
  2025-10-13 20:59   ` Jameson Thies
@ 2025-10-14  5:19     ` Greg KH
  0 siblings, 0 replies; 27+ messages in thread
From: Greg KH @ 2025-10-14  5:19 UTC (permalink / raw)
  To: Jameson Thies
  Cc: heikki.krogerus, linux-usb, linux-kernel, dmitry.baryshkov,
	bleung, akuchynski, abhishekpandit, sebastian.reichel, linux-pm

On Mon, Oct 13, 2025 at 01:59:23PM -0700, Jameson Thies wrote:
> Thank you for this feedback. The only patch here which is a clear bug
> fix is 5/6. Currently the driver reports 0.1A max current when nothing
> is connected on the port. I'll send that patch separately.

meta-comment, you lost all context here and I have no idea what you are
responding to, or what this is about :(

Remember, some of us get 1000+ emails a day to handle, context matters.

thanks,

greg k-h

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

end of thread, other threads:[~2025-10-14  5:19 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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