system76_ec: Improve performance
Change-Id: I4c35dd70067d78c3eded549de1a37ded6db3d364
This commit is contained in:
@@ -4,46 +4,46 @@
|
||||
|
||||
#define SYSTEM76_EC_BASE 0x0E00
|
||||
|
||||
static uint8_t system76_ec_read(uint8_t addr) {
|
||||
static inline uint8_t system76_ec_read(uint8_t addr) {
|
||||
return inb(SYSTEM76_EC_BASE + (uint16_t)addr);
|
||||
}
|
||||
|
||||
static void system76_ec_write(uint8_t addr, uint8_t data) {
|
||||
static inline void system76_ec_write(uint8_t addr, uint8_t data) {
|
||||
outb(data, SYSTEM76_EC_BASE + (uint16_t)addr);
|
||||
}
|
||||
|
||||
int system76_ec_print(uint8_t *buf, size_t len) {
|
||||
size_t i;
|
||||
for (i=0; i < len;) {
|
||||
if (system76_ec_read(0) == 0) {
|
||||
size_t j;
|
||||
for (j=0; (i < len) && ((j + 4) < 256); i++, j++) {
|
||||
system76_ec_write((uint8_t)(j + 4), buf[i]);
|
||||
}
|
||||
// Flags
|
||||
system76_ec_write(2, 0);
|
||||
// Length
|
||||
system76_ec_write(3, (uint8_t)j);
|
||||
// Command
|
||||
system76_ec_write(0, 4);
|
||||
// Wait for command completion, for up to 1 second
|
||||
int timeout;
|
||||
for (timeout = 1000000; timeout > 0; timeout--) {
|
||||
if (system76_ec_read(0) == 0) break;
|
||||
udelay(1);
|
||||
}
|
||||
if (timeout == 0) {
|
||||
// Error: timeout occured
|
||||
return -1;
|
||||
}
|
||||
if (system76_ec_read(1) != 0) {
|
||||
// Error: command failed
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
// Error: command is already running
|
||||
return -1;
|
||||
}
|
||||
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 1 second
|
||||
int timeout;
|
||||
for (timeout = 1000000; 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();
|
||||
}
|
||||
return (int)i;
|
||||
}
|
||||
|
Reference in New Issue
Block a user