wdenk | 3a473b2 | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 1 | /* |
| 2 | * COM1 NS16550 support |
| 3 | * originally from linux source (arch/ppc/boot/ns16550.c) |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame^] | 4 | * modified to use CONFIG_SYS_ISA_MEM and new defines |
wdenk | 3a473b2 | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 5 | * |
| 6 | * further modified by Josh Huber <huber@mclx.com> to support |
| 7 | * the DUART on the Galileo Eval board. (db64360) |
| 8 | */ |
| 9 | |
| 10 | #include <config.h> |
| 11 | #include "ns16550.h" |
| 12 | |
| 13 | #ifdef ZUMA_NTL |
| 14 | /* no 16550 device */ |
| 15 | #else |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame^] | 16 | const NS16550_t COM_PORTS[] = { (NS16550_t) (CONFIG_SYS_DUART_IO + 0), |
| 17 | (NS16550_t) (CONFIG_SYS_DUART_IO + 0x20) |
wdenk | 3a473b2 | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 18 | }; |
| 19 | |
| 20 | volatile struct NS16550 *NS16550_init (int chan, int baud_divisor) |
| 21 | { |
| 22 | volatile struct NS16550 *com_port; |
| 23 | |
| 24 | com_port = (struct NS16550 *) COM_PORTS[chan]; |
| 25 | com_port->ier = 0x00; |
| 26 | com_port->lcr = LCR_BKSE; /* Access baud rate */ |
| 27 | com_port->dll = baud_divisor & 0xff; /* 9600 baud */ |
| 28 | com_port->dlm = (baud_divisor >> 8) & 0xff; |
| 29 | com_port->lcr = LCR_8N1; /* 8 data, 1 stop, no parity */ |
| 30 | com_port->mcr = MCR_DTR | MCR_RTS; /* RTS/DTR */ |
| 31 | |
| 32 | /* Clear & enable FIFOs */ |
| 33 | com_port->fcr = FCR_FIFO_EN | FCR_RXSR | FCR_TXSR; |
| 34 | return (com_port); |
| 35 | } |
| 36 | |
| 37 | void NS16550_reinit (volatile struct NS16550 *com_port, int baud_divisor) |
| 38 | { |
| 39 | com_port->ier = 0x00; |
| 40 | com_port->lcr = LCR_BKSE; /* Access baud rate */ |
| 41 | com_port->dll = baud_divisor & 0xff; /* 9600 baud */ |
| 42 | com_port->dlm = (baud_divisor >> 8) & 0xff; |
| 43 | com_port->lcr = LCR_8N1; /* 8 data, 1 stop, no parity */ |
| 44 | com_port->mcr = MCR_DTR | MCR_RTS; /* RTS/DTR */ |
| 45 | |
| 46 | /* Clear & enable FIFOs */ |
| 47 | com_port->fcr = FCR_FIFO_EN | FCR_RXSR | FCR_TXSR; |
| 48 | } |
| 49 | |
| 50 | void NS16550_putc (volatile struct NS16550 *com_port, unsigned char c) |
| 51 | { |
| 52 | while ((com_port->lsr & LSR_THRE) == 0); |
| 53 | com_port->thr = c; |
| 54 | } |
| 55 | |
| 56 | unsigned char NS16550_getc (volatile struct NS16550 *com_port) |
| 57 | { |
| 58 | while ((com_port->lsr & LSR_DR) == 0); |
| 59 | return (com_port->rbr); |
| 60 | } |
| 61 | |
| 62 | int NS16550_tstc (volatile struct NS16550 *com_port) |
| 63 | { |
| 64 | return ((com_port->lsr & LSR_DR) != 0); |
| 65 | } |
| 66 | #endif |