Skip to content

Commit 2ca443b

Browse files
Josh-Tsaiquinchou77
authored andcommitted
fwk: CCG6: set the active current limit before multi-port switching
When the EC processes a multi-port switch, the sink path is enabled first, and then the input current limit for the active port is set. This sequence can cause a lower power adapter to operate with a higher input current limit , potentially triggering an OCP event. To ensure the adapter operates within a safe operating current, the EC should set the input current limit to the active one before enabling the sink path or completing the multi-port switching. BRANCH=fwk-main BUG=https://app.clickup.com/t/86ev81hyn TEST=The EC log will not print the AC off during the multi-port switching Signed-off-by: Josh Tsai <Josh_Tsai@compal.com> (cherry picked from commit b32f66864b8374b65e5f3206dd54272ab9e1b463)
1 parent ea09e7a commit 2ca443b

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

zephyr/program/framework/src/cypd_ccg6.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ int check_power_on_port(void)
283283
*/
284284
int board_set_active_charge_port(int charge_port)
285285
{
286-
int next_charge_port = get_active_charge_pd_port();
286+
int pre_charge_port = get_active_charge_pd_port();
287287
bool battery_can_discharge = (battery_is_present() == BP_YES) &
288288
battery_get_disconnect_state();
289289

@@ -300,10 +300,19 @@ int board_set_active_charge_port(int charge_port)
300300
}
301301

302302
/* port need change, stop all power and ready to switch. */
303-
if (next_charge_port != -1 && next_charge_port != charge_port) {
303+
if (pre_charge_port != -1 && pre_charge_port != charge_port) {
304304
CPRINTS("Disable all type-c port to change the charger port");
305305
cypd_write_reg8(0, CCG_CUST_C_CTRL_CONTROL_REG, CCG_P0P1_TURN_OFF_C_CTRL);
306306
cypd_write_reg8(1, CCG_CUST_C_CTRL_CONTROL_REG, CCG_P0P1_TURN_OFF_C_CTRL);
307+
308+
/**
309+
* Multi-port switch, we should force set the current limit to the active
310+
* port before enabling the sink path.
311+
*/
312+
if (IS_ENABLED(CONFIG_PLATFORM_EC_CHARGE_MANAGER)) {
313+
charge_manager_force_ceil(
314+
pre_charge_port, pd_port_states[charge_port].current);
315+
}
307316
crec_msleep(250);
308317
}
309318

0 commit comments

Comments
 (0)