Skip to content

Commit fc47b5f

Browse files
authored
lotus: modified EPR flow and PMF updated flow (#862)
* lotus: modified EPR flow and PMF updated flow Signed-off-by: Josh-Tsai <[email protected]> * lotus: set the poweroff_dp_deferred from 5s to 30s Signed-off-by: Josh-Tsai <[email protected]> * lotus: converstion the current after epr progress Signed-off-by: Josh-Tsai <[email protected]> * lotus: add the retry ERP when the PD chip does not response EPR event Signed-off-by: Josh-Tsai <[email protected]> * louts: clear port status when PD sent hard reset for customized extpower Signed-off-by: Josh-Tsai <[email protected]> * lotus: only process enter epr mode when the source is support Signed-off-by: Josh-Tsai <[email protected]> --------- Signed-off-by: Josh-Tsai <[email protected]>
1 parent 6ea7984 commit fc47b5f

File tree

6 files changed

+227
-77
lines changed

6 files changed

+227
-77
lines changed

zephyr/program/lotus/include/common_cpu_power.h

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ int set_pl_limits(uint32_t spl, uint32_t fppt, uint32_t sppt, uint32_t p3t);
7272

7373
#ifdef CONFIG_BOARD_LOTUS
7474
int update_apu_only_sppt_limit(uint32_t mwatt);
75+
void update_pmf_events(uint8_t pd_event, int enable);
7576
#endif
7677

7778
extern bool thermal_warn_trigger(void);

zephyr/program/lotus/include/cypress_pd_common.h

+5-10
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ enum ccg_pd_command {
272272
CCG_PD_CMD_EC_INIT_COMPLETE = 0x10,
273273
CCG_PD_CMD_PORT_DISABLE = 0x11,
274274
CCG_PD_CMD_CHANGE_PD_PORT_PARAMS = 0x14,
275+
CCG_PD_CMD_READ_SRC_PDO = 0x20,
275276
CCG_PD_CMD_INITIATE_EPR_ENTRY = 0x47,
276277
CCG_PD_CMD_INITIATE_EPR_EXIT = 0x48,
277278
};
@@ -444,6 +445,7 @@ enum pd_port {
444445
enum pd_progress {
445446
PD_PROGRESS_IDLE = 0,
446447
PD_PROGRESS_DISCONNECTED,
448+
PD_PROGRESS_EPR_MODE,
447449
};
448450

449451
struct pd_chip_config_t {
@@ -462,6 +464,7 @@ struct pd_port_current_state_t {
462464
uint8_t pd_state;
463465
uint8_t cc;
464466
uint8_t epr_active;
467+
uint8_t epr_support;
465468

466469
enum pd_power_role power_role;
467470
enum pd_data_role data_role;
@@ -557,22 +560,14 @@ int cypd_vbus_state_check(void);
557560
*/
558561
int cypd_get_ac_power(void);
559562

560-
/**
561-
* Set disable_epr_mode flag to true
562-
*
563-
*/
564-
void force_disable_epr_mode(void);
563+
void exit_epr_mode(void);
565564

566-
void release_disable_epr_mode(void);
565+
void enter_epr_mode(void);
567566

568567
int cypd_modify_safety_power(int controller, int port, int profile);
569568

570569
int cypd_port_3a_status(int controller, int port);
571570

572571
uint8_t cypd_get_cfet_status(void);
573572

574-
uint8_t get_pd_progress_flags(void);
575-
576-
void update_pd_progress_flags(int bit, int clear);
577-
578573
#endif /* __CROS_EC_CYPRESS_PD_COMMON_H */

zephyr/program/lotus/lotus/src/battery.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "charge_state.h"
1717
#include "charge_manager.h"
1818
#include "cypress_pd_common.h"
19+
#include "common_cpu_power.h"
1920
#include "console.h"
2021
#include "customized_shared_memory.h"
2122
#include "hooks.h"
@@ -379,7 +380,7 @@ __override int board_cut_off_battery(void)
379380
if (power_uw <= 100000000) {
380381
hook_call_deferred(&board_cut_off_data, 0);
381382
} else {
382-
force_disable_epr_mode();
383+
exit_epr_mode();
383384
hook_call_deferred(&board_cut_off_data, 700*MSEC);
384385
}
385386

zephyr/program/lotus/lotus/src/cpu_power.c

+50-16
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ static int battery_current_limit_mA;
2626
static int slider_stt_table;
2727
static int thermal_stt_table;
2828
static int safety_stt;
29+
static uint8_t events;
30+
31+
enum clear_reasons {
32+
PROCHOT_CLEAR_REASON_SUCCESS,
33+
PROCHOT_CLEAR_REASON_NOT_POWER,
34+
PROCHOT_CLEAR_REASON_FORCE,
35+
};
2936

3037
/* Update PL for thermal table pmf sheet : slider default */
3138
static void update_os_power_slider(int mode, bool with_dc, int active_mpower)
@@ -889,13 +896,34 @@ static void update_safety_power_limit(int active_mpower)
889896
}
890897
}
891898

892-
void clear_prochot(void)
899+
void update_pmf_events(uint8_t pd_event, int enable)
893900
{
894-
bool wait_pmf_update = !!(get_pd_progress_flags() & BIT(PD_PROGRESS_DISCONNECTED));
901+
static uint8_t pre_events;
902+
903+
/* We should not need to assert the prochot before apu ready to update pmf */
904+
if (!get_apu_ready())
905+
return;
906+
907+
if (enable)
908+
events |= pd_event;
909+
else
910+
events &= ~pd_event;
911+
912+
if (pre_events != events) {
913+
if (events)
914+
throttle_ap(THROTTLE_ON, THROTTLE_HARD, THROTTLE_SRC_UPDATE_PMF);
915+
else
916+
throttle_ap(THROTTLE_OFF, THROTTLE_HARD, THROTTLE_SRC_UPDATE_PMF);
917+
918+
pre_events = events;
919+
}
920+
}
895921

896-
if (wait_pmf_update) {
897-
throttle_ap(THROTTLE_OFF, THROTTLE_HARD, THROTTLE_SRC_UPDATE_PMF);
898-
update_pd_progress_flags(PD_PROGRESS_DISCONNECTED, 1);
922+
void clear_prochot(enum clear_reasons reason)
923+
{
924+
if (events) {
925+
CPRINTS("release pmf prochot reason:%d", reason);
926+
update_pmf_events(events, 0);
899927
}
900928
}
901929

@@ -911,14 +939,15 @@ void update_soc_power_limit(bool force_update, bool force_no_adapter)
911939
static int old_stt_table;
912940
int mode = *host_get_memmap(EC_MEMMAP_POWER_SLIDE);
913941
int active_mpower = cypd_get_ac_power();
914-
bool with_dc = ((battery_is_present() == BP_YES) ? true : false);
942+
bool with_dc = (((battery_is_present() == BP_YES) &&
943+
!battery_cutoff_in_progress() && !battery_is_cut_off()) ? true : false);
915944
int battery_percent = get_system_percentage() / 10;
916945

917946
if ((*host_get_memmap(EC_MEMMAP_STT_TABLE_NUMBER)) == 0)
918947
old_stt_table = 0;
919948

920949
if (!chipset_in_state(CHIPSET_STATE_ON) || !get_apu_ready()) {
921-
clear_prochot();
950+
clear_prochot(PROCHOT_CLEAR_REASON_NOT_POWER);
922951
return;
923952
}
924953

@@ -978,26 +1007,31 @@ void update_soc_power_limit(bool force_update, bool force_no_adapter)
9781007
|| power_limit[target_func[TYPE_P3T]].mwatt[TYPE_P3T] != old_p3t_limit
9791008
|| (power_limit[target_func[TYPE_APU_ONLY_SPPT]].mwatt[TYPE_APU_ONLY_SPPT]
9801009
!= old_ao_sppt)
981-
|| set_pl_limit || force_update) {
1010+
|| set_pl_limit || force_update || events) {
9821011
/* only set PL when it is changed */
9831012
old_sustain_power_limit = power_limit[target_func[TYPE_SPL]].mwatt[TYPE_SPL];
9841013
old_slow_ppt_limit = power_limit[target_func[TYPE_SPPT]].mwatt[TYPE_SPPT];
9851014
old_fast_ppt_limit = power_limit[target_func[TYPE_FPPT]].mwatt[TYPE_FPPT];
9861015
old_p3t_limit = power_limit[target_func[TYPE_P3T]].mwatt[TYPE_P3T];
9871016

988-
CPRINTF("Change SOC Power Limit: SPL %dmW, sPPT %dmW, fPPT %dmW, p3T %dmW, ",
989-
old_sustain_power_limit, old_slow_ppt_limit,
990-
old_fast_ppt_limit, old_p3t_limit);
9911017
set_pl_limit = set_pl_limits(old_sustain_power_limit, old_fast_ppt_limit,
9921018
old_slow_ppt_limit, old_p3t_limit);
993-
old_ao_sppt =
1019+
1020+
if (!set_pl_limit) {
1021+
old_ao_sppt =
9941022
power_limit[target_func[TYPE_APU_ONLY_SPPT]].mwatt[TYPE_APU_ONLY_SPPT];
995-
CPRINTF("ao_sppt %dmW\n", old_ao_sppt);
996-
if (!set_pl_limit)
9971023
set_pl_limit = update_apu_only_sppt_limit(old_ao_sppt);
998-
}
1024+
}
9991025

1000-
clear_prochot();
1026+
if (!set_pl_limit) {
1027+
/* Update PMF success, print the setting and de-asssert the prochot */
1028+
CPRINTS("PMF: SPL %dmW, sPPT %dmW, fPPT %dmW, p3T %dmW, ao_sppt %dmW",
1029+
old_sustain_power_limit, old_slow_ppt_limit,
1030+
old_fast_ppt_limit, old_p3t_limit, old_ao_sppt);
1031+
1032+
clear_prochot(PROCHOT_CLEAR_REASON_SUCCESS);
1033+
}
1034+
}
10011035
}
10021036

10031037
static void initial_soc_power_limit(void)

zephyr/program/lotus/lotus/src/power_sequence.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,8 @@ static int chipset_prepare_S3(uint8_t enable)
347347
peripheral_power_suspend();
348348
/* only exit epr when battery connect */
349349
if (battery_get_disconnect_state() == BATTERY_NOT_DISCONNECTED)
350-
force_disable_epr_mode();
350+
exit_epr_mode();
351351
} else {
352-
release_disable_epr_mode();
353352
k_msleep(10);
354353
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_susp_l), 1);
355354
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_0p75vs_pwr_en), 1);
@@ -577,8 +576,11 @@ enum power_state power_handle_state(enum power_state state)
577576
return POWER_S0ixS3;
578577
}
579578

580-
if (check_s0ix_statsus() == CS_EXIT_S0ix)
579+
if (check_s0ix_statsus() == CS_EXIT_S0ix) {
580+
/* We should enter EPR mode when the system actually resume to S0 state */
581+
enter_epr_mode();
581582
return POWER_S0ixS0;
583+
}
582584

583585
break;
584586

0 commit comments

Comments
 (0)