Jeremy Soller f3ba5937e7
Change system76_ec timeout to 10 ms
Change-Id: Ic3d01892df83c09d8323433585e1d8fe507f8c3a
2020-07-02 09:39:46 -06:00

50 lines
1.2 KiB
C

#include <arch/io.h>
#include <console/system76_ec.h>
#include <delay.h>
#define SYSTEM76_EC_BASE 0x0E00
static inline uint8_t system76_ec_read(uint8_t addr) {
return inb(SYSTEM76_EC_BASE + (uint16_t)addr);
}
static inline void system76_ec_write(uint8_t addr, uint8_t data) {
outb(data, SYSTEM76_EC_BASE + (uint16_t)addr);
}
void system76_ec_init(void) {
// Clear entire command region
for (int i = 0; i < 256; i++) {
system76_ec_write((uint8_t)i, 0);
}
}
void system76_ec_flush(void) {
// Send command
system76_ec_write(0, 4);
// Wait for command completion, for up to 10 milliseconds
int timeout;
for (timeout = 10000; timeout > 0; timeout--) {
if (system76_ec_read(0) == 0) break;
udelay(1);
}
// Clear length
system76_ec_write(3, 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);
// If we hit the end of the buffer, or were given a newline, flush
if (byte == '\n' || len >= 128) {
system76_ec_flush();
}
}