peci: Check for hardware error

Check if any hardware error bits are set instead of checking for only
command completion.

Move logging of WrPkgConfig() errors from power to peci.

Ref: IT5570E V0.3.2 datasheet
Signed-off-by: Tim Crawford <tcrawford@system76.com>
This commit is contained in:
Tim Crawford
2023-02-17 13:49:22 -07:00
committed by Jeremy Soller
parent 373dc36676
commit dd97946056
2 changed files with 22 additions and 25 deletions

View File

@ -277,8 +277,8 @@ bool peci_available(void) {
// Returns true on success, false on error
bool peci_get_temp(int16_t *data) {
// Wait for completion
while (HOSTAR & 1) {}
// Wait for any in-progress transaction to complete
while (HOSTAR & BIT(0)) {}
// Clear status
HOSTAR = HOSTAR;
@ -299,22 +299,23 @@ bool peci_get_temp(int16_t *data) {
while (HOSTAR & 1) {}
uint8_t status = HOSTAR;
if (status & BIT(1)) {
if (status & 0xEC) {
ERROR("peci_get_temp: hardware error: 0x%02X\n", status);
return false;
} else {
// Read two byte temperature data if finished successfully
uint8_t low = HORDDR;
uint8_t high = HORDDR;
*data = (((int16_t)high << 8) | (int16_t)low);
return true;
} else {
return false;
}
}
// Returns positive completion code on success, negative completion code or
// negative (0x1000 | status register) on PECI hardware error
int16_t peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data) {
// Wait for completion
while (HOSTAR & 1) {}
// Wait for any in-progress transaction to complete
while (HOSTAR & BIT(0)) {}
// Clear status
HOSTAR = HOSTAR;
@ -348,17 +349,21 @@ int16_t peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data) {
// Wait for completion
while (HOSTAR & 1) {}
int16_t status = (int16_t)HOSTAR;
if (status & BIT(1)) {
int16_t cc = (int16_t)HORDDR;
if (cc & 0x80) {
return -cc;
} else {
return cc;
}
} else {
uint8_t status = HOSTAR;
if (status & 0xEC) {
ERROR("peci_wr_pkg_config: hardware error: 0x%02X\n", status);
return -(0x1000 | status);
}
uint8_t cc = HORDDR;
if (cc == 0x40) {
TRACE("peci_wr_pkg_config: command successful\n");
return cc;
}
ERROR("peci_wr_pkg_config: command error: 0x%02X\n", cc);
return -((int16_t)cc);
}
#endif // CONFIG_BUS_ESPI

View File

@ -318,15 +318,7 @@ static bool power_peci_limit(bool ac) {
// Set PL4 using PECI
int16_t res = peci_wr_pkg_config(60, 0, ((uint32_t)watts) * 8);
DEBUG("power_peci_limit %d = %d\n", watts, res);
if (res == 0x40) {
return true;
} else if (res < 0) {
ERROR("power_peci_limit failed: 0x%02X\n", -res);
return false;
} else {
ERROR("power_peci_limit unknown response: 0x%02X\n", res);
return false;
}
return res == 0x40;
}
// Set the power draw limit depending on if on AC or DC power