ec/system76/ec: Sync changes from upstream

Change-Id: I277324a731548fd9d30e790922834172ac86c2a3
This commit is contained in:
Tim Crawford
2020-09-18 09:29:04 -06:00
committed by Jeremy Soller
parent 3dd5bc6550
commit 1ff8f316f4

View File

@@ -4,7 +4,22 @@
#include <console/system76_ec.h>
#include <timer.h>
// This is the command region for System76 EC firmware. It must be
// enabled for LPC in the mainboard.
#define SYSTEM76_EC_BASE 0x0E00
#define SYSTEM76_EC_SIZE 256
#define REG_CMD 0
#define REG_RESULT 1
// When command register is 0, command is complete
#define CMD_FINISHED 0
// Print command. Registers are unique for each command
#define CMD_PRINT 4
#define CMD_PRINT_REG_FLAGS 2
#define CMD_PRINT_REG_LEN 3
#define CMD_PRINT_REG_DATA 4
static inline uint8_t system76_ec_read(uint8_t addr)
{
@@ -19,32 +34,28 @@ static inline void system76_ec_write(uint8_t addr, uint8_t data)
void system76_ec_init(void)
{
// Clear entire command region
for (int i = 0; i < 256; i++)
for (int i = 0; i < SYSTEM76_EC_SIZE; i++)
system76_ec_write((uint8_t)i, 0);
}
void system76_ec_flush(void)
{
// Send command
system76_ec_write(0, 4);
system76_ec_write(REG_CMD, CMD_PRINT);
// Wait for command completion, for up to 10 milliseconds
wait_us(10000, system76_ec_read(0) == 0);
// Wait for command completion, for up to 10 milliseconds, with a
// test period of 1 microsecond
wait_us(10000, system76_ec_read(REG_CMD) == CMD_FINISHED);
// Clear length
system76_ec_write(3, 0);
system76_ec_write(CMD_PRINT_REG_LEN, 0);
}
void system76_ec_print(uint8_t byte)
{
// Read length
uint8_t len = system76_ec_read(3);
// Write data at offset
system76_ec_write(len + 4, byte);
// Update length
system76_ec_write(3, len + 1);
uint8_t len = system76_ec_read(CMD_PRINT_REG_LEN);
system76_ec_write(CMD_PRINT_REG_DATA + len, byte);
system76_ec_write(CMD_PRINT_REG_LEN, len + 1);
// If we hit the end of the buffer, or were given a newline, flush
if (byte == '\n' || len >= 128)
if (byte == '\n' || len >= (SYSTEM76_EC_SIZE - CMD_PRINT_REG_DATA))
system76_ec_flush();
}