Move power limit functions to common board code
Logic for changing power limit is the same for all boards with GPUs. It is still called from board_event() instead of in power_event() to maintain the current behavior of checking every main cycle. Signed-off-by: Tim Crawford <tcrawford@system76.com>
This commit is contained in:
committed by
Jeremy Soller
parent
3f446e5c6e
commit
a8229d9e62
@@ -7,7 +7,6 @@
|
||||
#include <board/gctrl.h>
|
||||
#include <board/gpio.h>
|
||||
#include <board/kbc.h>
|
||||
#include <board/peci.h>
|
||||
#include <board/power.h>
|
||||
#include <common/debug.h>
|
||||
|
||||
@@ -32,44 +31,8 @@ void board_init(void) {
|
||||
gpio_set(&SWI_N, true);
|
||||
}
|
||||
|
||||
// Set PL4 using PECI
|
||||
static int set_power_limit(uint8_t watts) {
|
||||
return peci_wr_pkg_config(
|
||||
60, // index
|
||||
0, // param
|
||||
((uint32_t)watts) * 8
|
||||
);
|
||||
}
|
||||
|
||||
void board_on_ac(bool ac) {
|
||||
uint8_t power_limit = ac ? POWER_LIMIT_AC : POWER_LIMIT_DC;
|
||||
// Retry, timeout errors happen occasionally
|
||||
for (int i = 0; i < 16; i++) {
|
||||
int res = set_power_limit(power_limit);
|
||||
DEBUG("set_power_limit %d = %d\n", power_limit, res);
|
||||
if (res == 0x40) {
|
||||
break;
|
||||
} else if (res < 0) {
|
||||
ERROR("set_power_limit failed: 0x%02X\n", -res);
|
||||
} else {
|
||||
ERROR("set_power_limit unknown response: 0x%02X\n", res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void board_event(void) {
|
||||
bool ac = !gpio_get(&ACIN_N);
|
||||
|
||||
static bool last_power_limit_ac = true;
|
||||
// We don't use power_state because the latency needs to be low
|
||||
if (gpio_get(&BUF_PLT_RST_N)) {
|
||||
if (last_power_limit_ac != ac) {
|
||||
board_on_ac(ac);
|
||||
last_power_limit_ac = ac;
|
||||
}
|
||||
} else {
|
||||
last_power_limit_ac = true;
|
||||
}
|
||||
power_set_limit();
|
||||
|
||||
if (main_cycle == 0) {
|
||||
// Set keyboard LEDs
|
||||
|
Reference in New Issue
Block a user