Skip to content

Commit 0e6371f

Browse files
Heikki Krogerusgregkh
authored andcommitted
usb: typec: ucsi: Report power supply changes
When the ucsi power supply goes online/offline, and when the power levels change, the power supply class needs to be notified so it can inform the user space. Fixes: 992a60e ("usb: typec: ucsi: register with power_supply class") Cc: [email protected] Reported-and-tested-by: Vladimir Yerilov <[email protected]> Signed-off-by: Heikki Krogerus <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 7625547 commit 0e6371f

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

drivers/usb/typec/ucsi/psy.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,13 @@ void ucsi_unregister_port_psy(struct ucsi_connector *con)
238238
return;
239239

240240
power_supply_unregister(con->psy);
241+
con->psy = NULL;
242+
}
243+
244+
void ucsi_port_psy_changed(struct ucsi_connector *con)
245+
{
246+
if (IS_ERR_OR_NULL(con->psy))
247+
return;
248+
249+
power_supply_changed(con->psy);
241250
}

drivers/usb/typec/ucsi/ucsi.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,10 @@ static void ucsi_handle_connector_change(struct work_struct *work)
643643
role = !!(con->status.flags & UCSI_CONSTAT_PWR_DIR);
644644

645645
if (con->status.change & UCSI_CONSTAT_POWER_OPMODE_CHANGE ||
646-
con->status.change & UCSI_CONSTAT_POWER_LEVEL_CHANGE)
646+
con->status.change & UCSI_CONSTAT_POWER_LEVEL_CHANGE) {
647647
ucsi_pwr_opmode_change(con);
648+
ucsi_port_psy_changed(con);
649+
}
648650

649651
if (con->status.change & UCSI_CONSTAT_POWER_DIR_CHANGE) {
650652
typec_set_pwr_role(con->port, role);
@@ -674,6 +676,8 @@ static void ucsi_handle_connector_change(struct work_struct *work)
674676
ucsi_register_partner(con);
675677
else
676678
ucsi_unregister_partner(con);
679+
680+
ucsi_port_psy_changed(con);
677681
}
678682

679683
if (con->status.change & UCSI_CONSTAT_CAM_CHANGE) {
@@ -994,6 +998,7 @@ static int ucsi_register_port(struct ucsi *ucsi, int index)
994998
!!(con->status.flags & UCSI_CONSTAT_PWR_DIR));
995999
ucsi_pwr_opmode_change(con);
9961000
ucsi_register_partner(con);
1001+
ucsi_port_psy_changed(con);
9971002
}
9981003

9991004
if (con->partner) {

drivers/usb/typec/ucsi/ucsi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,11 @@ int ucsi_resume(struct ucsi *ucsi);
340340
#if IS_ENABLED(CONFIG_POWER_SUPPLY)
341341
int ucsi_register_port_psy(struct ucsi_connector *con);
342342
void ucsi_unregister_port_psy(struct ucsi_connector *con);
343+
void ucsi_port_psy_changed(struct ucsi_connector *con);
343344
#else
344345
static inline int ucsi_register_port_psy(struct ucsi_connector *con) { return 0; }
345346
static inline void ucsi_unregister_port_psy(struct ucsi_connector *con) { }
347+
static inline void ucsi_port_psy_changed(struct ucsi_connector *con) { }
346348
#endif /* CONFIG_POWER_SUPPLY */
347349

348350
#if IS_ENABLED(CONFIG_TYPEC_DP_ALTMODE)

0 commit comments

Comments
 (0)