#include <linux/console.h>
#include <linux/io.h>
#include <mach/mt_reg_base.h>
#define UART_BASE UART1_BASE /* 根据需要修改,比如有些平台是AP_UART0_BASE */
#define EARLY_BASE (VMALLOC_START - SZ_1M)
static
void
mtuart_printch(
char
ch)
{
while
(!(readl_relaxed((
void
__iomem *)EARLY_BASE + 0x14)&0x20));
writel_relaxed(ch, (
void
__iomem *)EARLY_BASE);
}
static
void
early_write(
struct
console *con,
const
char
*s, unsigned n)
{
while
(n-- > 0) {
if
(*s ==
'\n'
)
mtuart_printch(
'\r'
);
mtuart_printch(*s);
s++;
}
}
static
void
__init setup_early_printk(
void
)
{
static
struct
console early_console_dev = {
.name =
"earlycon"
,
.write = early_write,
.flags = CON_PRINTBUFFER|CON_BOOT,
.index = -1,
};
struct
map_desc mt_uart_desc = {
.
virtual
= EARLY_BASE,
.pfn = __phys_to_pfn(IO_VIRT_TO_PHYS(UART_BASE)),
.length = SZ_4K,
.type = MT_DEVICE,
};
create_mapping(&mt_uart_desc,
false
);
register_console(&early_console_dev);
}