Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

usb: typec: ucsi: psy: Fix ucsi_psy_get_current_now in non-PD cases

current_now would always return 0 in for non-PD power sources, and the
negotiated current based on the Request RDO in PD mode.

For USB Type-C current or legacy Default USB cases current_now will present
the max value of those modes, as that is the equivalent of the Request RDO
in PD.

Also, current_now will now return 0 when the port is disconnected to match
the same behavior of current_max.

Signed-off-by: Benson Leung <bleung@chromium.org>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://patch.msgid.link/20251208174918.289394-2-bleung@chromium.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Benson Leung and committed by
Greg Kroah-Hartman
165fc074 c616b709

+21 -3
+21 -3
drivers/usb/typec/ucsi/psy.c
··· 202 202 static int ucsi_psy_get_current_now(struct ucsi_connector *con, 203 203 union power_supply_propval *val) 204 204 { 205 - if (UCSI_CONSTAT(con, PWR_OPMODE) == UCSI_CONSTAT_PWR_OPMODE_PD) 206 - val->intval = rdo_op_current(con->rdo) * 1000; 207 - else 205 + if (!UCSI_CONSTAT(con, CONNECTED)) { 208 206 val->intval = 0; 207 + return 0; 208 + } 209 + 210 + switch (UCSI_CONSTAT(con, PWR_OPMODE)) { 211 + case UCSI_CONSTAT_PWR_OPMODE_PD: 212 + val->intval = rdo_op_current(con->rdo) * 1000; 213 + break; 214 + case UCSI_CONSTAT_PWR_OPMODE_TYPEC1_5: 215 + val->intval = UCSI_TYPEC_1_5_CURRENT * 1000; 216 + break; 217 + case UCSI_CONSTAT_PWR_OPMODE_TYPEC3_0: 218 + val->intval = UCSI_TYPEC_3_0_CURRENT * 1000; 219 + break; 220 + case UCSI_CONSTAT_PWR_OPMODE_BC: 221 + case UCSI_CONSTAT_PWR_OPMODE_DEFAULT: 222 + /* UCSI can't tell b/w DCP/CDP or USB2/3x1/3x2 SDP chargers */ 223 + default: 224 + val->intval = UCSI_TYPEC_DEFAULT_CURRENT * 1000; 225 + break; 226 + } 209 227 return 0; 210 228 } 211 229