#include
#include
#include
static int early_serial_base = 0x3f8; /*ttyS0*/
#define XMTRDY 0x20
#define DLAB 0x80
#define TXR 0 /*Transmit register(WRITE)*/
#define RXR 0 /*Receive register(READ)*/
#define IER 1 /*Interrupt Enable*/
#define IIR 2 /*Interrupt ID*/
#define FCR 2 /*FIFO control*/
#define LCR 3 /*Line control*/
#define MCR 4 /*Modem control*/
#define LSR 5 /*Line Status*/
#define MSR 6 /*Modem Status*/
#define DLL 0 /*Divisor Latch Low*/
#define DLH 1 /*Divisor latch High*/
static int early_serial_putc(uint8_t ch)
{
uint16_t timeout = 0xffff;
while((inb(early_serial_base + LSR) & XMTRDY) == 0 && --timeout)
iodelay();
outb(early_serial_base + TXR, ch);
return timeout ? 0 : -1;
}
static void early_serial_write(const char *s, uint32_t n)
{
while(*s && n-- > 0)
{
if (*s == '\n')
early_serial_putc('\r');
early_serial_putc(*s);
s++;
}
}
int __printk(const char *file, int line, const char *fmt, ...)
{
int i;
char buf[512];
va_list args;
va_start(args, fmt);
//i = vsnprintf(buf, sizeof(buf), fmt, args);
i = vsprintf(buf, fmt, args);
va_end(args);
early_serial_write(buf, strlen(buf));
return i;
}
#define DEFAULT_BAUD 9600
void early_serial_init()
{
uint32_t port = 0;
uint8_t c;
uint32_t divisor;
uint32_t baud = DEFAULT_BAUD;
static const int bases[] = { 0x3f8, 0x2f8 };
early_serial_base = bases[port];
outb(early_serial_base + LCR, 0x3); /*8n1*/
outb(early_serial_base + IER, 0); /*no intr*/
outb(early_serial_base + FCR, 0); /*no fifo*/
outb(early_serial_base + MCR, 0x3); /*DTR+RTS*/
divisor = 115200 / baud;
c = inb(early_serial_base + LCR);
outb(early_serial_base + LCR, c | DLAB);
outb(early_serial_base + DLL, divisor & 0xff);
outb(early_serial_base + DLH, (divisor >> 8) & 0xff);
outb(early_serial_base + LCR, c & ~DLAB);
}
阅读(1399) | 评论(0) | 转发(0) |