wdenk | 71fc6c5 | 2002-08-06 19:52:25 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 10 | typedef struct NS16550 *NS16550_t; |
| 11 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame^] | 12 | const NS16550_t COM_PORTS[] = |
| 13 | { (NS16550_t) ((CFG_EUMB_ADDR) + 0x4500), |
| 14 | (NS16550_t) ((CFG_EUMB_ADDR) + 0x4600) }; |
wdenk | 71fc6c5 | 2002-08-06 19:52:25 +0000 | [diff] [blame] | 15 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame^] | 16 | volatile struct NS16550 *NS16550_init (int chan, int baud_divisor) |
wdenk | 71fc6c5 | 2002-08-06 19:52:25 +0000 | [diff] [blame] | 17 | { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame^] | 18 | volatile struct NS16550 *com_port; |
| 19 | |
| 20 | com_port = (struct NS16550 *) COM_PORTS[chan]; |
| 21 | com_port->ier = 0x00; |
| 22 | com_port->lcr = LCR_BKSE; /* Access baud rate */ |
| 23 | com_port->dll = baud_divisor & 0xff; /* 9600 baud */ |
| 24 | com_port->dlm = (baud_divisor >> 8) & 0xff; |
| 25 | com_port->lcr = LCR_8N1; /* 8 data, 1 stop, no parity */ |
| 26 | com_port->mcr = MCR_RTS; /* RTS/DTR */ |
| 27 | com_port->fcr = FCR_FIFO_EN | FCR_RXSR | FCR_TXSR; /* Clear & enable FIFOs */ |
| 28 | return (com_port); |
wdenk | 71fc6c5 | 2002-08-06 19:52:25 +0000 | [diff] [blame] | 29 | } |
| 30 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame^] | 31 | void NS16550_reinit (volatile struct NS16550 *com_port, int baud_divisor) |
wdenk | 71fc6c5 | 2002-08-06 19:52:25 +0000 | [diff] [blame] | 32 | { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame^] | 33 | com_port->ier = 0x00; |
| 34 | com_port->lcr = LCR_BKSE; /* Access baud rate */ |
| 35 | com_port->dll = baud_divisor & 0xff; /* 9600 baud */ |
| 36 | com_port->dlm = (baud_divisor >> 8) & 0xff; |
| 37 | com_port->lcr = LCR_8N1; /* 8 data, 1 stop, no parity */ |
| 38 | com_port->mcr = MCR_RTS; /* RTS/DTR */ |
| 39 | com_port->fcr = FCR_FIFO_EN | FCR_RXSR | FCR_TXSR; /* Clear & enable FIFOs */ |
wdenk | 71fc6c5 | 2002-08-06 19:52:25 +0000 | [diff] [blame] | 40 | } |
| 41 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame^] | 42 | void NS16550_putc (volatile struct NS16550 *com_port, unsigned char c) |
wdenk | 71fc6c5 | 2002-08-06 19:52:25 +0000 | [diff] [blame] | 43 | { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame^] | 44 | while ((com_port->lsr & LSR_THRE) == 0); |
| 45 | com_port->thr = c; |
wdenk | 71fc6c5 | 2002-08-06 19:52:25 +0000 | [diff] [blame] | 46 | } |
| 47 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame^] | 48 | unsigned char NS16550_getc (volatile struct NS16550 *com_port) |
wdenk | 71fc6c5 | 2002-08-06 19:52:25 +0000 | [diff] [blame] | 49 | { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame^] | 50 | while ((com_port->lsr & LSR_DR) == 0); |
| 51 | return (com_port->rbr); |
wdenk | 71fc6c5 | 2002-08-06 19:52:25 +0000 | [diff] [blame] | 52 | } |
| 53 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame^] | 54 | int NS16550_tstc (volatile struct NS16550 *com_port) |
wdenk | 71fc6c5 | 2002-08-06 19:52:25 +0000 | [diff] [blame] | 55 | { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame^] | 56 | return ((com_port->lsr & LSR_DR) != 0); |
wdenk | 71fc6c5 | 2002-08-06 19:52:25 +0000 | [diff] [blame] | 57 | } |