Skip to content

Commit f6c1e3c

Browse files
Merge pull request #1049 from FrameworkComputer/marigold.pd_system_power_state
marigold: update the system power state correctly
2 parents d7107c7 + 9a3e806 commit f6c1e3c

2 files changed

Lines changed: 36 additions & 26 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ enum power_state power_handle_state(enum power_state state)
462462
resume_ms_flag = 0;
463463
system_in_s0ix = 0;
464464
lpc_s0ix_resume_restore_masks();
465+
cypd_set_power_active();
465466
/* Call hooks now that rails are up */
466467
hook_notify(HOOK_CHIPSET_RESUME);
467468
return POWER_S0;
@@ -471,6 +472,7 @@ enum power_state power_handle_state(enum power_state state)
471472
system_in_s0ix = 1;
472473
CPRINTS("PH S0->S0ix");
473474
lpc_s0ix_suspend_clear_masks();
475+
cypd_set_power_active();
474476
/* Call hooks before we remove power rails */
475477
hook_notify(HOOK_CHIPSET_SUSPEND);
476478
return POWER_S0ix;

zephyr/program/framework/src/cypd_ccg6.c

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -330,46 +330,51 @@ void cypd_set_error_recovery(void)
330330
void update_system_power_state(int controller)
331331
{
332332
enum power_state ps = power_get_state();
333+
/* CCG6 does not support power state G3, just for initial state */
334+
static uint8_t pre_state = CCG_POWERSTATE_G3;
333335

334336
switch (ps) {
335337
case POWER_G3:
336338
case POWER_S5G3:
337-
cypd_set_power_state(CCG_POWERSTATE_G3, controller);
338-
break;
339339
case POWER_S5:
340340
case POWER_S3S5:
341341
case POWER_S4S5:
342-
cypd_set_power_state(CCG_POWERSTATE_S5, controller);
342+
/* Do not update the same state again */
343+
if (pre_state != CCG_POWERSTATE_S5)
344+
cypd_set_power_state(CCG_POWERSTATE_S5, controller);
345+
346+
pre_state = CCG_POWERSTATE_S5;
343347
reconnect_flag = true;
344348
break;
345349
case POWER_S3:
346350
case POWER_S4S3:
347351
case POWER_S5S3:
348352
case POWER_S0S3:
349-
case POWER_S0ixS3: /* S0ix -> S3 */
350-
cypd_set_power_state(CCG_POWERSTATE_S3, controller);
353+
case POWER_S0ix:
354+
case POWER_S0S0ix: /* S0 -> S0ix */
355+
/* Do not update the same state again */
356+
if (pre_state != CCG_POWERSTATE_S3)
357+
cypd_set_power_state(CCG_POWERSTATE_S3, controller);
358+
pre_state = CCG_POWERSTATE_S3;
351359
break;
352360
case POWER_S0:
353361
case POWER_S3S0:
354362
case POWER_S0ixS0: /* S0ix -> S0 */
355-
cypd_set_error_recovery();
356-
cypd_set_power_state(CCG_POWERSTATE_S0, controller);
363+
if (pre_state != CCG_POWERSTATE_S0) {
364+
cypd_set_error_recovery();
365+
cypd_set_power_state(CCG_POWERSTATE_S0, controller);
366+
}
367+
pre_state = CCG_POWERSTATE_S0;
368+
357369
if (reconnect_flag) {
358370
CPRINTS("CYPD reconnect");
359371
cypd_reconnect();
360372
reconnect_flag = false;
361373
}
362374
break;
363-
case POWER_S0ix:
364-
case POWER_S3S0ix: /* S3 -> S0ix */
365-
case POWER_S0S0ix: /* S0 -> S0ix */
366-
cypd_set_power_state(CCG_POWERSTATE_S0ix, controller);
367-
break;
368-
369375
default:
370376
break;
371377
}
372-
373378
}
374379

375380
int cypd_reconnect_port_disable(int controller)
@@ -441,35 +446,38 @@ void cypd_reconnect(void)
441446
void update_system_power_state(int controller)
442447
{
443448
enum power_state ps = power_get_state();
449+
/* CCG6 does not support power state G3, just for initial state */
450+
static uint8_t pre_state = CCG_POWERSTATE_G3;
444451

445452
switch (ps) {
446453
case POWER_G3:
447454
case POWER_S5G3:
448-
cypd_set_power_state(CCG_POWERSTATE_G3, controller);
449-
break;
450455
case POWER_S5:
451456
case POWER_S3S5:
452457
case POWER_S4S5:
453-
cypd_set_power_state(CCG_POWERSTATE_S5, controller);
458+
/* Do not update the same state again */
459+
if (pre_state != CCG_POWERSTATE_S5)
460+
cypd_set_power_state(CCG_POWERSTATE_S5, controller);
461+
pre_state = CCG_POWERSTATE_S5;
454462
break;
455463
case POWER_S3:
456464
case POWER_S4S3:
457465
case POWER_S5S3:
458466
case POWER_S0S3:
459-
case POWER_S0ixS3: /* S0ix -> S3 */
460-
cypd_set_power_state(CCG_POWERSTATE_S3, controller);
467+
case POWER_S0ix:
468+
case POWER_S0S0ix: /* S0 -> S0ix */
469+
/* Do not update the same state again */
470+
if (pre_state != CCG_POWERSTATE_S3)
471+
cypd_set_power_state(CCG_POWERSTATE_S3, controller);
472+
pre_state = CCG_POWERSTATE_S3;
461473
break;
462474
case POWER_S0:
463475
case POWER_S3S0:
464476
case POWER_S0ixS0: /* S0ix -> S0 */
465-
cypd_set_power_state(CCG_POWERSTATE_S0, controller);
477+
if (pre_state != CCG_POWERSTATE_S0)
478+
cypd_set_power_state(CCG_POWERSTATE_S0, controller);
479+
pre_state = CCG_POWERSTATE_S0;
466480
break;
467-
case POWER_S0ix:
468-
case POWER_S3S0ix: /* S3 -> S0ix */
469-
case POWER_S0S0ix: /* S0 -> S0ix */
470-
cypd_set_power_state(CCG_POWERSTATE_S0ix, controller);
471-
break;
472-
473481
default:
474482
break;
475483
}

0 commit comments

Comments
 (0)