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

Signed-off-by: Jameson Thies <jthies@google.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Benson Leung <bleung@chromium.org>
Tested-By: Kenneth R. Crudup <kenny@panix.com>
Link: https://patch.msgid.link/20251016235909.2092917-2-jthies@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Jameson Thies and committed by
Greg Kroah-Hartman
ef7204a9 0ec946d3

+29
+26
drivers/usb/typec/ucsi/psy.c
··· 29 29 POWER_SUPPLY_PROP_CURRENT_MAX, 30 30 POWER_SUPPLY_PROP_CURRENT_NOW, 31 31 POWER_SUPPLY_PROP_SCOPE, 32 + POWER_SUPPLY_PROP_STATUS, 32 33 }; 33 34 34 35 static int ucsi_psy_get_scope(struct ucsi_connector *con, ··· 49 48 scope = POWER_SUPPLY_SCOPE_DEVICE; 50 49 } 51 50 val->intval = scope; 51 + return 0; 52 + } 53 + 54 + static int ucsi_psy_get_status(struct ucsi_connector *con, 55 + union power_supply_propval *val) 56 + { 57 + bool is_sink = UCSI_CONSTAT(con, PWR_DIR) == TYPEC_SINK; 58 + bool sink_path_enabled = true; 59 + 60 + val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; 61 + 62 + if (con->ucsi->version >= UCSI_VERSION_2_0) 63 + sink_path_enabled = 64 + UCSI_CONSTAT(con, SINK_PATH_STATUS_V2_0) == 65 + UCSI_CONSTAT_SINK_PATH_ENABLED; 66 + 67 + if (UCSI_CONSTAT(con, CONNECTED)) { 68 + if (is_sink && sink_path_enabled) 69 + val->intval = POWER_SUPPLY_STATUS_CHARGING; 70 + else if (!is_sink) 71 + val->intval = POWER_SUPPLY_STATUS_DISCHARGING; 72 + } 73 + 52 74 return 0; 53 75 } 54 76 ··· 269 245 return ucsi_psy_get_current_now(con, val); 270 246 case POWER_SUPPLY_PROP_SCOPE: 271 247 return ucsi_psy_get_scope(con, val); 248 + case POWER_SUPPLY_PROP_STATUS: 249 + return ucsi_psy_get_status(con, val); 272 250 default: 273 251 return -EINVAL; 274 252 }
+3
drivers/usb/typec/ucsi/ucsi.h
··· 360 360 #define UCSI_CONSTAT_BC_SLOW_CHARGING 2 361 361 #define UCSI_CONSTAT_BC_TRICKLE_CHARGING 3 362 362 #define UCSI_CONSTAT_PD_VERSION_V1_2 UCSI_DECLARE_BITFIELD_V1_2(70, 16) 363 + #define UCSI_CONSTAT_SINK_PATH_STATUS_V2_0 UCSI_DECLARE_BITFIELD_V2_0(87, 1) 364 + #define UCSI_CONSTAT_SINK_PATH_DISABLED 0 365 + #define UCSI_CONSTAT_SINK_PATH_ENABLED 1 363 366 #define UCSI_CONSTAT_PWR_READING_READY_V2_1 UCSI_DECLARE_BITFIELD_V2_1(89, 1) 364 367 #define UCSI_CONSTAT_CURRENT_SCALE_V2_1 UCSI_DECLARE_BITFIELD_V2_1(90, 3) 365 368 #define UCSI_CONSTAT_PEAK_CURRENT_V2_1 UCSI_DECLARE_BITFIELD_V2_1(93, 16)