blob: b1c28eb264a79c2fa00635b5c06c0f969eecf1cb [file] [log] [blame]
wdenk71fc6c52002-08-06 19:52:25 +00001/*
2 * COM1 NS16550 support
3 * originally from linux source (arch/ppc/boot/ns16550.c)
4 * modified to use CFG_ISA_MEM and new defines
5 */
6
7#include <config.h>
8#include "ns16550.h"
9
10typedef struct NS16550 *NS16550_t;
11
12const NS16550_t COM_PORTS[] = { (NS16550_t) ((CFG_EUMB_ADDR) + 0x4500), (NS16550_t) ((CFG_EUMB_ADDR) + 0x4600)};
13
14volatile struct NS16550 *
15NS16550_init(int chan, int baud_divisor)
16{
17 volatile struct NS16550 *com_port;
18 com_port = (struct NS16550 *) COM_PORTS[chan];
19 com_port->ier = 0x00;
20 com_port->lcr = LCR_BKSE; /* Access baud rate */
21 com_port->dll = baud_divisor & 0xff; /* 9600 baud */
22 com_port->dlm = (baud_divisor >> 8) & 0xff;
23 com_port->lcr = LCR_8N1; /* 8 data, 1 stop, no parity */
24 com_port->mcr = MCR_RTS; /* RTS/DTR */
25 com_port->fcr = FCR_FIFO_EN | FCR_RXSR | FCR_TXSR; /* Clear & enable FIFOs */
26return (com_port);
27}
28
29void
30NS16550_reinit(volatile struct NS16550 *com_port, int baud_divisor)
31{
32 com_port->ier = 0x00;
33 com_port->lcr = LCR_BKSE; /* Access baud rate */
34 com_port->dll = baud_divisor & 0xff; /* 9600 baud */
35 com_port->dlm = (baud_divisor >> 8) & 0xff;
36 com_port->lcr = LCR_8N1; /* 8 data, 1 stop, no parity */
37 com_port->mcr = MCR_RTS; /* RTS/DTR */
38 com_port->fcr = FCR_FIFO_EN | FCR_RXSR | FCR_TXSR; /* Clear & enable FIFOs */
39}
40
41void NS16550_putc(volatile struct NS16550 *com_port, unsigned char c)
42{
43 while ((com_port->lsr & LSR_THRE) == 0) ;
44 com_port->thr = c;
45}
46
47unsigned char
48NS16550_getc(volatile struct NS16550 *com_port)
49{
50 while ((com_port->lsr & LSR_DR) == 0) ;
51 return (com_port->rbr);
52}
53
54int NS16550_tstc(volatile struct NS16550 *com_port)
55{
56 return ((com_port->lsr & LSR_DR) != 0);
57}