Skip to content

Commit 0fccea0

Browse files
LeoCX-TsaiJohnAZoidberg
authored andcommitted
fwk: lilac: Set the S0ix enter/exit flags correctly
reference PR#1653 to add this solution to avoid MS mode abnormal Sometimes, the system will enter and resume S0ix several times within a tick time (200ms). EC should set the flags in the correct state. E.g., If the EC chipset state is in S0ix and the system resumes S0ix and then enters again, the final memmap (EC_CUSTOMIZED_MEMMAP_POWER_STATE) is EC_PS_ENTER_S0ix. In this case, EC should not set the enter_ms_flag. BRANCH=fwk-lilac-27116 BUG=None TEST=let system enter S0ix state, use the ec console command "memmap set 0x101 0x40", and the press power button to resume the system. Check the power LED is on and EC power state is S0. Signed-off-by: LeoCX_Tsai <LeoCX_Tsai@compal.com>
1 parent 44c39f0 commit 0fccea0

1 file changed

Lines changed: 25 additions & 25 deletions

File tree

zephyr/program/framework/azalea/src/power_sequence.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,7 @@ void clear_power_flags(void)
133133
* host resumes from S0ix, masks from backup variables are copied over to
134134
* lpc_host_event_mask for SCI.
135135
*/
136-
static int enter_ms_flag;
137-
static int resume_ms_flag;
138-
static int system_in_s0ix;
136+
static bool enter_ms_flag, resume_ms_flag, system_in_s0ix;
139137

140138
static int check_s0ix_statsus(void)
141139
{
@@ -148,14 +146,18 @@ static int check_s0ix_statsus(void)
148146

149147

150148
/**
151-
* Sometimes PCH will set the enter and resume flag continuously
152-
* so clear the EMI when we read the flag.
149+
* Sometimes, the system will enter and resume S0ix several times within a
150+
* tick time (200ms).EC should set the flags in the correct state.
151+
*
152+
* E.g., If the EC chipset state is in S0ix and the system resumes S0ix and
153+
* then enters again, the final memmap (EC_CUSTOMIZED_MEMMAP_POWER_STATE)
154+
* is EC_PS_ENTER_S0ix. In this case, EC should not set the enter_ms_flag.
153155
*/
154-
if (power_status & EC_PS_ENTER_S0ix)
155-
enter_ms_flag++;
156+
if ((power_status & EC_PS_ENTER_S0ix) && !system_in_s0ix)
157+
enter_ms_flag = true;
156158

157-
if (power_status & EC_PS_RESUME_S0ix)
158-
resume_ms_flag++;
159+
if ((power_status & EC_PS_RESUME_S0ix) && system_in_s0ix)
160+
resume_ms_flag = true;
159161

160162
clear_flag = power_status & (EC_PS_ENTER_S0ix | EC_PS_RESUME_S0ix);
161163

@@ -167,7 +169,14 @@ static int check_s0ix_statsus(void)
167169
if (enter_ms_flag)
168170
return CS_ENTER_S0ix;
169171
}
170-
return 0;
172+
return CS_NONE;
173+
}
174+
175+
static void power_clear_s0ix_flag(void)
176+
{
177+
resume_ms_flag = false;
178+
enter_ms_flag = false;
179+
system_in_s0ix = false;
171180
}
172181

173182
void s0ix_status_handle(void)
@@ -183,11 +192,6 @@ void s0ix_status_handle(void)
183192
}
184193
DECLARE_HOOK(HOOK_TICK, s0ix_status_handle, HOOK_PRIO_DEFAULT);
185194

186-
int check_s0ix_status(void)
187-
{
188-
return system_in_s0ix;
189-
}
190-
191195
#endif
192196

193197
void chipset_reset(enum chipset_shutdown_reason reason)
@@ -369,9 +373,7 @@ enum power_state power_handle_state(enum power_state state)
369373
} else if (gpio_pin_get_dt(GPIO_DT_FROM_NODELABEL(gpio_slp_s5_l)) == 0) {
370374

371375
if (system_in_s0ix) {
372-
resume_ms_flag = 0;
373-
enter_ms_flag = 0;
374-
system_in_s0ix = 0;
376+
power_clear_s0ix_flag();
375377
lpc_s0ix_resume_restore_masks();
376378
/* Call hooks now that rails are up */
377379
hook_notify(HOOK_CHIPSET_RESUME);
@@ -453,9 +455,7 @@ enum power_state power_handle_state(enum power_state state)
453455
* clear the resume ms flag
454456
*/
455457
if (resume_ms_flag > 0) {
456-
resume_ms_flag = 0;
457-
enter_ms_flag = 0;
458-
system_in_s0ix = 0;
458+
power_clear_s0ix_flag();
459459
return POWER_S0ixS0;
460460
}
461461
return POWER_S0ixS3;
@@ -482,8 +482,8 @@ enum power_state power_handle_state(enum power_state state)
482482

483483
case POWER_S0ixS0:
484484
CPRINTS("PH S0ixS0");
485-
resume_ms_flag = 0;
486-
system_in_s0ix = 0;
485+
resume_ms_flag = false;
486+
system_in_s0ix = false;
487487
lpc_s0ix_resume_restore_masks();
488488
/* Call hooks now that rails are up */
489489
hook_notify(HOOK_CHIPSET_RESUME);
@@ -500,8 +500,8 @@ enum power_state power_handle_state(enum power_state state)
500500
break;
501501

502502
case POWER_S0S0ix:
503-
enter_ms_flag = 0;
504-
system_in_s0ix = 1;
503+
enter_ms_flag = false;
504+
system_in_s0ix = true;
505505
CPRINTS("PH S0->S0ix");
506506
lpc_s0ix_suspend_clear_masks();
507507
/* Call hooks before we remove power rails */

0 commit comments

Comments
 (0)