Set power limits on AC plug event
This commit is contained in:
committed by
Jeremy Soller
parent
5a8653ef08
commit
90bdcb3818
@@ -4,6 +4,7 @@
|
||||
#include <board/dgpu.h>
|
||||
#include <board/gpio.h>
|
||||
#include <board/kbc.h>
|
||||
#include <board/peci.h>
|
||||
#include <board/power.h>
|
||||
#include <common/debug.h>
|
||||
|
||||
@@ -28,10 +29,36 @@ void board_init(void) {
|
||||
dgpu_init();
|
||||
}
|
||||
|
||||
// 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_event(void) {
|
||||
bool acin = !gpio_get(&ACIN_N);
|
||||
gpio_set(&AC_PRESENT, acin);
|
||||
|
||||
static uint8_t last_power_limit = 0;
|
||||
if (power_state == POWER_STATE_S0) {
|
||||
uint8_t power_limit = acin ? POWER_LIMIT_AC : POWER_LIMIT_DC;
|
||||
if (power_limit != last_power_limit) {
|
||||
int res = set_power_limit(power_limit);
|
||||
DEBUG("set_power_limit %d = %d\n", power_limit, res);
|
||||
if (res >= 0) {
|
||||
last_power_limit = power_limit;
|
||||
} else {
|
||||
ERROR("set_power_limit failed: %X\n", -res);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
last_power_limit = 0;
|
||||
}
|
||||
|
||||
if (main_cycle == 0) {
|
||||
bool acin = !gpio_get(&ACIN_N);
|
||||
gpio_set(&AC_PRESENT, acin);
|
||||
if (acin) {
|
||||
// Discharging (no AC adapter)
|
||||
gpio_set(&LED_BAT_CHG, false);
|
||||
|
Reference in New Issue
Block a user