Skip to contentSkip to conversation

UCSI Power Supply Updates

PATCH In review Jameson Thies 3 participants 8 messages Oct 16, 2025 – Oct 17, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover UCSI Power Supply Updates

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) Updates ucsi.c to report a power supply change all power opmode changes. Currently this only gets reported when opmode is PD.
3) Updates ucsi.c to report a power supply change when the PPM signals a sink path change.

v2 changes
- Removed patch adding support for reporting DRP power supply types. It led to spam in dmesg and needs further debug.
- Removed patch to report 0 max current when a port is not connected. This is a bug fix and should be reviewed separately.
- Removed patch to refresh connector status after PR swaps. This is not directly related to the power supply and should be sent up separately.
- Updated patch notify the power supply class of sink path status changes. It now uses a single bit mask for checking both sink path status changes and battery charging status changes.

Jameson Thies (3):
usb: typec: ucsi: psy: Add power supply status
usb: typec: ucsi: Report power supply changes on power opmode changes
usb: typec: ucsi: Report power supply change on sink path change

 drivers/usb/typec/ucsi/psy.c  | 26 ++++++++++++++++++++++++++
 drivers/usb/typec/ucsi/ucsi.c |  5 ++++-
 drivers/usb/typec/ucsi/ucsi.h |  4 ++++
 3 files changed, 34 insertions(+), 1 deletion(-)

base-commit: e40b984b6c4ce3f80814f39f86f87b2a48f2e662

Signature · 1 line
2.51.0.858.gf9c4a03a3a-goog
#1 lore raw

PATCH v2 1/3 usb: typec: ucsi: psy: Add power supply status

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.

---
 drivers/usb/typec/ucsi/psy.c  | 26 ++++++++++++++++++++++++++
 drivers/usb/typec/ucsi/ucsi.h |  3 +++
 2 files changed, 29 insertions(+)
drivers/usb/typec/ucsi/psy.c +26 -0
index 62a9d68bb66d..2b0225821502 100644
@@ -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;
 	}
drivers/usb/typec/ucsi/ucsi.h +3 -0
index e301d9012936..cce93af7461b 100644
@@ -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)
Signature · 1 line
2.51.0.858.gf9c4a03a3a-goog
Reviewed-by on v2 1/3
#2 lore raw

Re: [PATCH v2 1/3] usb: typec: ucsi: psy: Add power supply status

Quoted 7 lines · Jameson Thies

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.

Quoted 73 lines
---
 drivers/usb/typec/ucsi/psy.c  | 26 ++++++++++++++++++++++++++
 drivers/usb/typec/ucsi/ucsi.h |  3 +++
 2 files changed, 29 insertions(+)
drivers/usb/typec/ucsi/psy.c +26 -0
index 62a9d68bb66d..2b0225821502 100644
@@ -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;
 	}
drivers/usb/typec/ucsi/ucsi.h +3 -0
index e301d9012936..cce93af7461b 100644
@@ -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)
Signature · 1 line
2.51.0.858.gf9c4a03a3a-goog
#3 lore raw

PATCH v2 2/3 usb: typec: ucsi: Report power supply changes on power opmode changes

In reply to Jameson Thies

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.

---
 drivers/usb/typec/ucsi/ucsi.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/usb/typec/ucsi/ucsi.c +3 -0
index 3f568f790f39..7b718049d0d1 100644
@@ -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;
 	}
 }
Signature · 1 line
2.51.0.858.gf9c4a03a3a-goog
#4 lore raw

PATCH v2 3/3 usb: typec: ucsi: Report power supply change on sink path change

In reply to Jameson Thies

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

---
 drivers/usb/typec/ucsi/ucsi.c | 2 +-
 drivers/usb/typec/ucsi/ucsi.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/usb/typec/ucsi/ucsi.c +1 -1
index 7b718049d0d1..cad3913bd7f9 100644
@@ -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 | UCSI_CONSTAT_SINK_PATH_CHANGE))
 		ucsi_port_psy_changed(con);
 
 	if (con->ucsi->version >= UCSI_VERSION_2_1 &&
drivers/usb/typec/ucsi/ucsi.h +1 -0
index cce93af7461b..35993bc34d4d 100644
@@ -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)
 
Signature · 1 line
2.51.0.858.gf9c4a03a3a-goog
Reviewed-by on v2 3/3
#5 lore raw

Re: [PATCH v2 3/3] usb: typec: ucsi: Report power supply change on sink path change

Quoted 4 lines · Jameson Thies

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

Quoted 33 lines
---
 drivers/usb/typec/ucsi/ucsi.c | 2 +-
 drivers/usb/typec/ucsi/ucsi.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/usb/typec/ucsi/ucsi.c +1 -1
index 7b718049d0d1..cad3913bd7f9 100644
@@ -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 | UCSI_CONSTAT_SINK_PATH_CHANGE))
 		ucsi_port_psy_changed(con);
 
 	if (con->ucsi->version >= UCSI_VERSION_2_1 &&
drivers/usb/typec/ucsi/ucsi.h +1 -0
index cce93af7461b..35993bc34d4d 100644
@@ -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)
 
Signature · 1 line
2.51.0.858.gf9c4a03a3a-goog
#6 lore raw
In reply to Jameson Thies
Quoted 3 lines · Jameson Thies

v2 changes
- Removed patch adding support for reporting DRP power supply types. It led to spam in dmesg and needs further debug.

So far, so good! I'm currently booted (along with the "Add power supply status" patch) and no issues so far.

I'll look for the sysfs entries and report back with a Tested-By: if all is well.

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

Tested-by on the v2 series
#7 lore raw
In reply to Jameson Thies
Quoted 34 lines · Jameson Thies

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) Updates ucsi.c to report a power supply change all power opmode changes. Currently this only gets reported when opmode is PD.
3) Updates ucsi.c to report a power supply change when the PPM signals a sink path change.

v2 changes
- Removed patch adding support for reporting DRP power supply types. It led to spam in dmesg and needs further debug.
- Removed patch to report 0 max current when a port is not connected. This is a bug fix and should be reviewed separately.
- Removed patch to refresh connector status after PR swaps. This is not directly related to the power supply and should be sent up separately.
- Updated patch notify the power supply class of sink path status changes. It now uses a single bit mask for checking both sink path status changes and battery charging status changes.

Jameson Thies (3):
usb: typec: ucsi: psy: Add power supply status
usb: typec: ucsi: Report power supply changes on power opmode changes
usb: typec: ucsi: Report power supply change on sink path change

  drivers/usb/typec/ucsi/psy.c  | 26 ++++++++++++++++++++++++++
  drivers/usb/typec/ucsi/ucsi.c |  5 ++++-
  drivers/usb/typec/ucsi/ucsi.h |  4 ++++
  3 files changed, 34 insertions(+), 1 deletion(-)

base-commit: e40b984b6c4ce3f80814f39f86f87b2a48f2e662

Signature · 1 line
Kenneth R. Crudup / Sr. SW Engineer, Scott County Consulting, Orange County CA