wdenk | e85390d | 2002-04-01 14:29:03 +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 | |
| 9 | #ifdef CFG_NS16550 |
| 10 | |
| 11 | #include <ns16550.h> |
| 12 | |
| 13 | #define LCRVAL LCR_8N1 /* 8 data, 1 stop, no parity */ |
| 14 | #define MCRVAL (MCR_DTR | MCR_RTS) /* RTS/DTR */ |
| 15 | #define FCRVAL (FCR_FIFO_EN | FCR_RXSR | FCR_TXSR) /* Clear & enable FIFOs */ |
| 16 | |
| 17 | void NS16550_init (NS16550_t com_port, int baud_divisor) |
| 18 | { |
| 19 | com_port->ier = 0x00; |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 20 | #ifdef CONFIG_OMAP |
wdenk | 232c150 | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 21 | com_port->mdr1 = 0x7; /* mode select reset TL16C750*/ |
wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 22 | #endif |
wdenk | e85390d | 2002-04-01 14:29:03 +0000 | [diff] [blame] | 23 | com_port->lcr = LCR_BKSE | LCRVAL; |
Wolfgang Denk | 7ec8bb1 | 2007-12-27 10:56:54 +0100 | [diff] [blame] | 24 | com_port->dll = 0; |
| 25 | com_port->dlm = 0; |
wdenk | e85390d | 2002-04-01 14:29:03 +0000 | [diff] [blame] | 26 | com_port->lcr = LCRVAL; |
| 27 | com_port->mcr = MCRVAL; |
| 28 | com_port->fcr = FCRVAL; |
Wolfgang Denk | 7ec8bb1 | 2007-12-27 10:56:54 +0100 | [diff] [blame] | 29 | com_port->lcr = LCR_BKSE | LCRVAL; |
| 30 | com_port->dll = baud_divisor & 0xff; |
| 31 | com_port->dlm = (baud_divisor >> 8) & 0xff; |
| 32 | com_port->lcr = LCRVAL; |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 33 | #if defined(CONFIG_OMAP) |
| 34 | #if defined(CONFIG_APTIX) |
| 35 | com_port->mdr1 = 3; /* /13 mode so Aptix 6MHz can hit 115200 */ |
| 36 | #else |
| 37 | com_port->mdr1 = 0; /* /16 is proper to hit 115200 with 48MHz */ |
| 38 | #endif |
wdenk | 2e5983d | 2003-07-15 20:04:06 +0000 | [diff] [blame] | 39 | #endif |
wdenk | e85390d | 2002-04-01 14:29:03 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | void NS16550_reinit (NS16550_t com_port, int baud_divisor) |
| 43 | { |
| 44 | com_port->ier = 0x00; |
Wolfgang Denk | 7ec8bb1 | 2007-12-27 10:56:54 +0100 | [diff] [blame] | 45 | com_port->lcr = LCR_BKSE | LCRVAL; |
| 46 | com_port->dll = 0; |
| 47 | com_port->dlm = 0; |
| 48 | com_port->lcr = LCRVAL; |
| 49 | com_port->mcr = MCRVAL; |
| 50 | com_port->fcr = FCRVAL; |
wdenk | e85390d | 2002-04-01 14:29:03 +0000 | [diff] [blame] | 51 | com_port->lcr = LCR_BKSE; |
| 52 | com_port->dll = baud_divisor & 0xff; |
| 53 | com_port->dlm = (baud_divisor >> 8) & 0xff; |
| 54 | com_port->lcr = LCRVAL; |
wdenk | e85390d | 2002-04-01 14:29:03 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | void NS16550_putc (NS16550_t com_port, char c) |
| 58 | { |
| 59 | while ((com_port->lsr & LSR_THRE) == 0); |
| 60 | com_port->thr = c; |
| 61 | } |
| 62 | |
| 63 | char NS16550_getc (NS16550_t com_port) |
| 64 | { |
wdenk | 232c150 | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 65 | while ((com_port->lsr & LSR_DR) == 0) { |
| 66 | #ifdef CONFIG_USB_TTY |
| 67 | extern void usbtty_poll(void); |
| 68 | usbtty_poll(); |
| 69 | #endif |
| 70 | } |
wdenk | e85390d | 2002-04-01 14:29:03 +0000 | [diff] [blame] | 71 | return (com_port->rbr); |
| 72 | } |
| 73 | |
| 74 | int NS16550_tstc (NS16550_t com_port) |
| 75 | { |
| 76 | return ((com_port->lsr & LSR_DR) != 0); |
| 77 | } |
| 78 | |
| 79 | #endif |