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
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
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.
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
>
© 2016 - 2025 Red Hat, Inc.