system76_ec: Improve performance
Change-Id: I4c35dd70067d78c3eded549de1a37ded6db3d364
This commit is contained in:
@@ -22,6 +22,7 @@ void console_hw_init(void)
|
||||
__usbdebug_init();
|
||||
__spiconsole_init();
|
||||
__flashconsole_init();
|
||||
__system76_ec_init();
|
||||
}
|
||||
|
||||
void console_tx_byte(unsigned char byte)
|
||||
@@ -52,6 +53,7 @@ void console_tx_flush(void)
|
||||
__ne2k_tx_flush();
|
||||
__usb_tx_flush();
|
||||
__flashconsole_tx_flush();
|
||||
__system76_ec_tx_flush();
|
||||
}
|
||||
|
||||
void console_write_line(uint8_t *buffer, size_t number_of_bytes)
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -4,17 +4,27 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
int system76_ec_print(uint8_t *buf, size_t len);
|
||||
void system76_ec_init(void);
|
||||
void system76_ec_flush(void);
|
||||
void system76_ec_print(uint8_t byte);
|
||||
|
||||
#define __CONSOLE_SYSTEM76_EC_ENABLE__ (CONFIG(CONSOLE_SYSTEM76_EC) && \
|
||||
(ENV_BOOTBLOCK || ENV_ROMSTAGE || ENV_RAMSTAGE || ENV_VERSTAGE || \
|
||||
ENV_POSTCAR || (ENV_SMM && CONFIG(DEBUG_SMI))))
|
||||
(ENV_BOOTBLOCK || ENV_ROMSTAGE || ENV_RAMSTAGE || ENV_SEPARATE_VERSTAGE \
|
||||
|| ENV_POSTCAR || (ENV_SMM && CONFIG(DEBUG_SMI))))
|
||||
|
||||
#if __CONSOLE_SYSTEM76_EC_ENABLE__
|
||||
static inline void __system76_ec_init(void) {
|
||||
system76_ec_init();
|
||||
}
|
||||
static inline void __system76_ec_tx_flush(void) {
|
||||
system76_ec_flush();
|
||||
}
|
||||
static inline void __system76_ec_tx_byte(unsigned char byte) {
|
||||
system76_ec_print(&byte, 1);
|
||||
system76_ec_print(byte);
|
||||
}
|
||||
#else
|
||||
static inline void __system76_ec_init(void) {}
|
||||
static inline void __system76_ec_tx_flush(void) {}
|
||||
static inline void __system76_ec_tx_byte(unsigned char byte) {}
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user