Skip to content

Commit d671dc0

Browse files
authored
Merge pull request #691 from FrameworkComputer/azalea.fix_dead_battery_poweron
pd enable error recovery on boot
2 parents c274b70 + a0d0aa5 commit d671dc0

File tree

3 files changed

+55
-16
lines changed

3 files changed

+55
-16
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,9 @@ enum power_state power_handle_state(enum power_state state)
568568
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_apu_aud_pwr_en), 0);
569569
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_pch_pwr_en), 0);
570570

571+
cypd_set_power_active(POWER_G3);
572+
573+
571574
return POWER_G3;
572575
default:
573576
break;

zephyr/program/lotus/include/cypress_pd_common.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
#define CCG_CUST_C_CTRL_CONTROL_REG 0x003B
4444
#define CCG_HPI_VERSION 0x003C
4545
/*User registers from 0x40 to 0x48 are used for BB retimer */
46-
#define CCG_ICL_CTRL_REG 0x0040
46+
#define CCG_ERR_RECOVERY_REG 0x0040
4747
#define CCG_ICL_STS_REG 0x0042
4848
#define CCG_ICL_BB_RETIMER_CMD_REG 0x0046
4949
#define CCG_ICL_BB_RETIMER_DAT_REG 0x0048
@@ -140,12 +140,12 @@
140140
/************************************************/
141141
/* POWER STATE DEFINITION */
142142
/************************************************/
143-
#define CCG_POWERSTATE_S0 0x01
144-
#define CCG_POWERSTATE_S0ix 0x02
145-
#define CCG_POWERSTATE_S3 0x03
146-
#define CCG_POWERSTATE_S4 0x04
147-
#define CCG_POWERSTATE_S5 0x05
148-
#define CCG_POWERSTATE_G3 0x06
143+
#define CCG_POWERSTATE_S0 0x00
144+
#define CCG_POWERSTATE_S3 0x01
145+
#define CCG_POWERSTATE_S4 0x02
146+
#define CCG_POWERSTATE_S5 0x03
147+
#define CCG_POWERSTATE_S0ix 0x04
148+
#define CCG_POWERSTATE_G3 0x05
149149

150150
/************************************************/
151151
/* CCG_CUST_C_CTRL_CONTROL_REG DEFINITION */

zephyr/program/lotus/src/cypress_pd_common.c

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -912,36 +912,72 @@ static int cypd_update_power_status(int controller)
912912
return rv;
913913
}
914914

915+
static void perform_error_recovery(int controller)
916+
{
917+
int i;
918+
if (controller < 2)
919+
for (i = 0; i < 2; i++) {
920+
if (!((controller*2 + i) == prev_charge_port && battery_is_present() != BP_YES) )
921+
cypd_write_reg8(controller, CCG_ERR_RECOVERY_REG, i);
922+
}
923+
else {
924+
/* Hard reset all ports that are not supplying power in dead battery mode */
925+
for (i = 0; i < 4; i++) {
926+
if (!(i == prev_charge_port && battery_is_present() != BP_YES) ) {
927+
CPRINTS("Hard reset %d", i);
928+
cypd_write_reg8(i >> 1, CCG_ERR_RECOVERY_REG, i & 1);
929+
}
930+
}
931+
}
932+
return ;
933+
}
934+
enum power_state pd_prev_power_state = POWER_G3;
915935
void update_system_power_state(int controller)
916936
{
917937
enum power_state ps = power_get_state();
918938

939+
if (battery_is_present() != BP_YES && ps == POWER_G3) {
940+
return;
941+
}
919942
switch (ps) {
920943
case POWER_G3:
921-
case POWER_S5:
922944
case POWER_S5G3:
945+
pd_prev_power_state = POWER_G3;
923946
cypd_set_power_state(CCG_POWERSTATE_G3, controller);
924947
break;
948+
case POWER_S5:
925949
case POWER_S3S5:
950+
case POWER_S4S5:
951+
pd_prev_power_state = POWER_S5;
926952
cypd_set_power_state(CCG_POWERSTATE_S5, controller);
927953
break;
928954
case POWER_S3:
955+
case POWER_S4S3:
956+
case POWER_S5S3:
957+
case POWER_S0S3:
958+
case POWER_S0ixS3: /* S0ix -> S3 */
959+
if (pd_prev_power_state < POWER_S3) {
960+
perform_error_recovery(controller);
961+
pd_prev_power_state = ps;
962+
}
929963
cypd_set_power_state(CCG_POWERSTATE_S3, controller);
930964
break;
965+
case POWER_S0:
966+
case POWER_S3S0:
931967
case POWER_S0ixS0: /* S0ix -> S0 */
968+
if (pd_prev_power_state < POWER_S3) {
969+
perform_error_recovery(controller);
970+
pd_prev_power_state = ps;
971+
}
932972
cypd_set_power_state(CCG_POWERSTATE_S0, controller);
933973
break;
934-
case POWER_S0S0ix: /* S0 -> S0ix */
935-
cypd_set_power_state(CCG_POWERSTATE_S0ix, controller);
936-
break;
937-
case POWER_S0ixS3: /* S0ix -> S3 */
938-
cypd_set_power_state(CCG_POWERSTATE_S3, controller);
939-
break;
974+
case POWER_S0ix:
940975
case POWER_S3S0ix: /* S3 -> S0ix */
976+
case POWER_S0S0ix: /* S0 -> S0ix */
941977
cypd_set_power_state(CCG_POWERSTATE_S0ix, controller);
942978
break;
979+
943980
default:
944-
cypd_set_power_state(CCG_POWERSTATE_S0, controller);
945981
break;
946982
}
947983

@@ -1044,7 +1080,7 @@ static void cypd_handle_state(int controller)
10441080
cypd_get_version(controller);
10451081
cypd_update_power_status(controller);
10461082

1047-
cypd_set_power_state(CCG_POWERSTATE_S5, controller);
1083+
//update_system_power_state(controller);
10481084
cypd_setup(controller);
10491085

10501086
/* After initial complete, update the type-c port state */

0 commit comments

Comments
 (0)