2002-08-06 19:52:25 +00:00
|
|
|
/*
|
|
|
|
* COM1 NS16550 support
|
2010-04-15 14:07:28 +00:00
|
|
|
* originally from linux source (arch/powerpc/boot/ns16550.c)
|
2008-10-16 13:01:15 +00:00
|
|
|
* modified to use CONFIG_SYS_ISA_MEM and new defines
|
2002-08-06 19:52:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include "ns16550.h"
|
|
|
|
|
|
|
|
typedef struct NS16550 *NS16550_t;
|
|
|
|
|
2004-02-12 00:47:09 +00:00
|
|
|
const NS16550_t COM_PORTS[] =
|
2008-10-16 13:01:15 +00:00
|
|
|
{ (NS16550_t) ((CONFIG_SYS_EUMB_ADDR) + 0x4500),
|
|
|
|
(NS16550_t) ((CONFIG_SYS_EUMB_ADDR) + 0x4600) };
|
2002-08-06 19:52:25 +00:00
|
|
|
|
2004-02-12 00:47:09 +00:00
|
|
|
volatile struct NS16550 *NS16550_init (int chan, int baud_divisor)
|
2002-08-06 19:52:25 +00:00
|
|
|
{
|
2004-02-12 00:47:09 +00:00
|
|
|
volatile struct NS16550 *com_port;
|
|
|
|
|
|
|
|
com_port = (struct NS16550 *) COM_PORTS[chan];
|
|
|
|
com_port->ier = 0x00;
|
|
|
|
com_port->lcr = LCR_BKSE; /* Access baud rate */
|
|
|
|
com_port->dll = baud_divisor & 0xff; /* 9600 baud */
|
|
|
|
com_port->dlm = (baud_divisor >> 8) & 0xff;
|
|
|
|
com_port->lcr = LCR_8N1; /* 8 data, 1 stop, no parity */
|
|
|
|
com_port->mcr = MCR_RTS; /* RTS/DTR */
|
|
|
|
com_port->fcr = FCR_FIFO_EN | FCR_RXSR | FCR_TXSR; /* Clear & enable FIFOs */
|
|
|
|
return (com_port);
|
2002-08-06 19:52:25 +00:00
|
|
|
}
|
|
|
|
|
2004-02-12 00:47:09 +00:00
|
|
|
void NS16550_reinit (volatile struct NS16550 *com_port, int baud_divisor)
|
2002-08-06 19:52:25 +00:00
|
|
|
{
|
2004-02-12 00:47:09 +00:00
|
|
|
com_port->ier = 0x00;
|
|
|
|
com_port->lcr = LCR_BKSE; /* Access baud rate */
|
|
|
|
com_port->dll = baud_divisor & 0xff; /* 9600 baud */
|
|
|
|
com_port->dlm = (baud_divisor >> 8) & 0xff;
|
|
|
|
com_port->lcr = LCR_8N1; /* 8 data, 1 stop, no parity */
|
|
|
|
com_port->mcr = MCR_RTS; /* RTS/DTR */
|
|
|
|
com_port->fcr = FCR_FIFO_EN | FCR_RXSR | FCR_TXSR; /* Clear & enable FIFOs */
|
2002-08-06 19:52:25 +00:00
|
|
|
}
|
|
|
|
|
2004-02-12 00:47:09 +00:00
|
|
|
void NS16550_putc (volatile struct NS16550 *com_port, unsigned char c)
|
2002-08-06 19:52:25 +00:00
|
|
|
{
|
2004-02-12 00:47:09 +00:00
|
|
|
while ((com_port->lsr & LSR_THRE) == 0);
|
|
|
|
com_port->thr = c;
|
2002-08-06 19:52:25 +00:00
|
|
|
}
|
|
|
|
|
2004-02-12 00:47:09 +00:00
|
|
|
unsigned char NS16550_getc (volatile struct NS16550 *com_port)
|
2002-08-06 19:52:25 +00:00
|
|
|
{
|
2004-02-12 00:47:09 +00:00
|
|
|
while ((com_port->lsr & LSR_DR) == 0);
|
|
|
|
return (com_port->rbr);
|
2002-08-06 19:52:25 +00:00
|
|
|
}
|
|
|
|
|
2004-02-12 00:47:09 +00:00
|
|
|
int NS16550_tstc (volatile struct NS16550 *com_port)
|
2002-08-06 19:52:25 +00:00
|
|
|
{
|
2004-02-12 00:47:09 +00:00
|
|
|
return ((com_port->lsr & LSR_DR) != 0);
|
2002-08-06 19:52:25 +00:00
|
|
|
}
|