Skip to content

Commit b046765

Browse files
JohnWC-YehTerrails
authored andcommitted
fwk: lotus: avoid looping attempts to enter epr mode
Only reproduce 180w AC with 100W PD MFD hub Since MFD Hub does not support epr mode, it will cause an infinite loop to enter epr mode and assert prochot. Enter_epr_mode(assert prochot)-> Retry 5 times -> timeout 3s(de-asssert prochot) -> enter_epr_mode -> .... loop Add workaround avoid looping attempts to enter epr mode. Unable to enter EPR mode after retrying 5 times, set the epr_support flag to 0. BUG=app.clickup.com/t/86enwhpg2 TEST=With 180w AC and 100W PD MFD hub, cpu not stuck at 500MHz BRANCH=lotus Signed-off-by: johnwc_yeh <[email protected]>
1 parent 029ab87 commit b046765

File tree

2 files changed

+32
-25
lines changed

2 files changed

+32
-25
lines changed

zephyr/program/framework/include/cypress_pd_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ struct pd_port_current_state_t {
466466
uint8_t cc;
467467
uint8_t epr_active;
468468
uint8_t epr_support;
469+
uint8_t epr_retry_count;
469470

470471
enum pd_power_role power_role;
471472
enum pd_data_role data_role;

zephyr/program/framework/src/cypress_pd_common.c

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -350,37 +350,42 @@ static void update_external_cc_mux(int port, int cc)
350350

351351
static void epr_flow_pending_deferred(void)
352352
{
353-
static int retry_count;
354-
353+
int port_idx;
355354
/**
356355
* Sometimes, EC does not receive the EPR event/NOT support event from PD chip.
357356
* Retry the last action.
358357
*/
358+
for (port_idx = 0; port_idx < PD_PORT_COUNT; port_idx++) {
359+
if (pd_epr_in_progress & BIT(port_idx)) {
360+
if (pd_port_states[port_idx].epr_retry_count > 4) {
361+
/* restore the input current limit if we retry 4 times */
362+
pd_port_states[port_idx].epr_retry_count = 0;
363+
pd_port_states[port_idx].epr_support = 0;
364+
pd_epr_in_progress &= EPR_PROCESS_MASK;
365+
if (prev_charge_port != -1)
366+
cypd_update_port_state((prev_charge_port & 0x02) >> 1,
367+
prev_charge_port & BIT(0));
368+
}
369+
/**
370+
* There is a low risk situation.
371+
* If both the EXIT EPR and ENTER EPR flags are set simultaneously,
372+
* it will cause epr_retry_count to be incremented twice.
373+
*/
374+
if (pd_epr_in_progress & EXIT_EPR) {
375+
CPRINTS("C%d exit EPR stuck, retry!", port_idx);
376+
exit_epr_mode();
377+
pd_port_states[port_idx].epr_retry_count++;
378+
}
359379

360-
if (!!(pd_epr_in_progress & ~EPR_PROCESS_MASK)) {
361-
if (retry_count > 4) {
362-
/* restore the input current limit if we retry 4 times */
363-
retry_count = 0;
364-
pd_epr_in_progress &= EPR_PROCESS_MASK;
365-
if (prev_charge_port != -1)
366-
cypd_update_port_state((prev_charge_port & 0x02) >> 1,
367-
prev_charge_port & BIT(0));
368-
}
369-
370-
if (pd_epr_in_progress & EXIT_EPR) {
371-
CPRINTS("Exit EPR stuck, retry!");
372-
exit_epr_mode();
373-
retry_count++;
374-
}
375-
376-
if (pd_epr_in_progress & ENTER_EPR) {
377-
CPRINTS("enter EPR stuck, retry!");
378-
enter_epr_mode();
379-
retry_count++;
380-
}
380+
if (pd_epr_in_progress & ENTER_EPR) {
381+
CPRINTS("C%d enter EPR stuck, retry!", port_idx);
382+
enter_epr_mode();
383+
pd_port_states[port_idx].epr_retry_count++;
384+
}
381385

382-
} else
383-
retry_count = 0;
386+
} else
387+
pd_port_states[port_idx].epr_retry_count = 0;
388+
}
384389
}
385390
DECLARE_DEFERRED(epr_flow_pending_deferred);
386391

@@ -1181,6 +1186,7 @@ static void clear_port_state(int controller, int port)
11811186
pd_port_states[port_idx].vconn = PD_ROLE_VCONN_OFF;
11821187
pd_port_states[port_idx].epr_active = 0;
11831188
pd_port_states[port_idx].epr_support = 0;
1189+
pd_port_states[port_idx].epr_retry_count = 0;
11841190
pd_port_states[port_idx].cc = POLARITY_CC1;
11851191
pd_port_states[port_idx].c_state = 0;
11861192
pd_port_states[port_idx].current = 0;

0 commit comments

Comments
 (0)