System76 EC console support
Change-Id: I04c2aeb19d780a7c6638b502192fa9f569e32e94
This commit is contained in:
@@ -302,6 +302,13 @@ config SPI_CONSOLE
|
||||
This is currently working only in ramstage due to how the spi
|
||||
drivers are written.
|
||||
|
||||
config CONSOLE_SYSTEM76_EC
|
||||
bool "System76 EC console output"
|
||||
default y
|
||||
depends on DRIVERS_SYSTEM76_EC
|
||||
help
|
||||
Send coreboot debug output to a System76 embedded controller.
|
||||
|
||||
config CONSOLE_OVERRIDE_LOGLEVEL
|
||||
bool
|
||||
help
|
||||
|
@@ -20,6 +20,7 @@
|
||||
#include <console/usb.h>
|
||||
#include <console/spi.h>
|
||||
#include <console/flash.h>
|
||||
#include <console/system76_ec.h>
|
||||
|
||||
void console_hw_init(void)
|
||||
{
|
||||
@@ -53,6 +54,7 @@ void console_tx_byte(unsigned char byte)
|
||||
__usb_tx_byte(byte);
|
||||
__spiconsole_tx_byte(byte);
|
||||
__flashconsole_tx_byte(byte);
|
||||
__system76_ec_tx_byte(byte);
|
||||
}
|
||||
|
||||
void console_tx_flush(void)
|
||||
|
2
src/drivers/system76_ec/Kconfig
Normal file
2
src/drivers/system76_ec/Kconfig
Normal file
@@ -0,0 +1,2 @@
|
||||
config DRIVERS_SYSTEM76_EC
|
||||
bool
|
10
src/drivers/system76_ec/Makefile.inc
Normal file
10
src/drivers/system76_ec/Makefile.inc
Normal file
@@ -0,0 +1,10 @@
|
||||
ifeq ($(CONFIG_DRIVERS_SYSTEM76_EC),y)
|
||||
|
||||
bootblock-y += system76_ec.c
|
||||
verstage-y += system76_ec.c
|
||||
romstage-y += system76_ec.c
|
||||
postcar-y += system76_ec.c
|
||||
ramstage-y += system76_ec.c
|
||||
smm-$(CONFIG_DEBUG_SMI) += system76_ec.c
|
||||
|
||||
endif
|
49
src/drivers/system76_ec/system76_ec.c
Normal file
49
src/drivers/system76_ec/system76_ec.c
Normal file
@@ -0,0 +1,49 @@
|
||||
#include <arch/io.h>
|
||||
#include <console/system76_ec.h>
|
||||
#include <delay.h>
|
||||
|
||||
#define SYSTEM76_EC_BASE 0x0E00
|
||||
|
||||
static 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) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
return (int)i;
|
||||
}
|
21
src/include/console/system76_ec.h
Normal file
21
src/include/console/system76_ec.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef CONSOLE_SYSTEM76_EC_H
|
||||
#define CONSOLE_SYSTEM76_EC_H 1
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
int system76_ec_print(uint8_t *buf, size_t len);
|
||||
|
||||
#define __CONSOLE_SYSTEM76_EC_ENABLE__ (CONFIG(CONSOLE_SYSTEM76_EC) && \
|
||||
(ENV_BOOTBLOCK || ENV_ROMSTAGE || ENV_RAMSTAGE || ENV_VERSTAGE || \
|
||||
ENV_POSTCAR || (ENV_SMM && CONFIG(DEBUG_SMI))))
|
||||
|
||||
#if __CONSOLE_SYSTEM76_EC_ENABLE__
|
||||
static inline void __system76_ec_tx_byte(unsigned char byte) {
|
||||
system76_ec_print(&byte, 1);
|
||||
}
|
||||
#else
|
||||
static inline void __system76_ec_tx_byte(unsigned char byte) {}
|
||||
#endif
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user