Attempt to fix power_peci_limit issues
- Return false when power_peci_limit fails - Allow power_peci_limit to be retried indefinitely from power_set_limit
This commit is contained in:
committed by
Jeremy Soller
parent
f55e493001
commit
646a6436a7
@@ -358,20 +358,19 @@ void power_off_s5(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_DGPU
|
#ifdef HAVE_DGPU
|
||||||
static void power_peci_limit(bool ac) {
|
static bool power_peci_limit(bool ac) {
|
||||||
uint8_t watts = ac ? POWER_LIMIT_AC : POWER_LIMIT_DC;
|
uint8_t watts = ac ? POWER_LIMIT_AC : POWER_LIMIT_DC;
|
||||||
// Retry, timeout errors happen occasionally
|
// Set PL4 using PECI
|
||||||
for (uint8_t i = 16; i != 0; i--) {
|
int16_t res = peci_wr_pkg_config(60, 0, ((uint32_t)watts) * 8);
|
||||||
// Set PL4 using PECI
|
DEBUG("power_peci_limit %d = %d\n", watts, res);
|
||||||
int16_t res = peci_wr_pkg_config(60, 0, ((uint32_t)watts) * 8);
|
if (res == 0x40) {
|
||||||
DEBUG("power_peci_limit %d = %d\n", watts, res);
|
return true;
|
||||||
if (res == 0x40) {
|
} else if (res < 0) {
|
||||||
break;
|
ERROR("power_peci_limit failed: 0x%02X\n", -res);
|
||||||
} else if (res < 0) {
|
return false;
|
||||||
ERROR("power_peci_limit failed: 0x%02X\n", -res);
|
} else {
|
||||||
} else {
|
ERROR("power_peci_limit unknown response: 0x%02X\n", res);
|
||||||
ERROR("power_peci_limit unknown response: 0x%02X\n", res);
|
return false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -386,15 +385,15 @@ void power_set_limit(void) {
|
|||||||
#endif
|
#endif
|
||||||
bool ac = !gpio_get(&ACIN_N);
|
bool ac = !gpio_get(&ACIN_N);
|
||||||
if (last_power_limit_ac != ac) {
|
if (last_power_limit_ac != ac) {
|
||||||
power_peci_limit(ac);
|
if (power_peci_limit(ac)) {
|
||||||
last_power_limit_ac = ac;
|
last_power_limit_ac = ac;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
last_power_limit_ac = true;
|
last_power_limit_ac = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static void power_peci_limit(bool ac) { ac = ac; }
|
|
||||||
void power_set_limit(void) {}
|
void power_set_limit(void) {}
|
||||||
#endif // HAVE_DGPU
|
#endif // HAVE_DGPU
|
||||||
|
|
||||||
@@ -426,7 +425,7 @@ void power_event(void) {
|
|||||||
static bool ac_last = true;
|
static bool ac_last = true;
|
||||||
bool ac_new = gpio_get(&ACIN_N);
|
bool ac_new = gpio_get(&ACIN_N);
|
||||||
if (ac_new != ac_last) {
|
if (ac_new != ac_last) {
|
||||||
power_peci_limit(!ac_new);
|
power_set_limit();
|
||||||
|
|
||||||
DEBUG("Power adapter ");
|
DEBUG("Power adapter ");
|
||||||
if (ac_new) {
|
if (ac_new) {
|
||||||
|
Reference in New Issue
Block a user