wdenk | e85390d | 2002-04-01 14:29:03 +0000 | [diff] [blame] | 1 | /* |
| 2 | * COM1 NS16550 support |
Stefan Roese | 88fbf93 | 2010-04-15 16:07:28 +0200 | [diff] [blame^] | 3 | * originally from linux source (arch/powerpc/boot/ns16550.c) |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 4 | * modified to use CONFIG_SYS_ISA_MEM and new defines |
wdenk | e85390d | 2002-04-01 14:29:03 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <config.h> |
wdenk | e85390d | 2002-04-01 14:29:03 +0000 | [diff] [blame] | 8 | #include <ns16550.h> |
Ladislav Michl | cc29442 | 2010-02-01 23:34:25 +0100 | [diff] [blame] | 9 | #include <watchdog.h> |
wdenk | e85390d | 2002-04-01 14:29:03 +0000 | [diff] [blame] | 10 | |
Detlev Zundel | 166fb54 | 2009-04-03 11:53:01 +0200 | [diff] [blame] | 11 | #define UART_LCRVAL UART_LCR_8N1 /* 8 data, 1 stop, no parity */ |
| 12 | #define UART_MCRVAL (UART_MCR_DTR | \ |
| 13 | UART_MCR_RTS) /* RTS/DTR */ |
| 14 | #define UART_FCRVAL (UART_FCR_FIFO_EN | \ |
| 15 | UART_FCR_RXSR | \ |
| 16 | UART_FCR_TXSR) /* Clear & enable FIFOs */ |
wdenk | e85390d | 2002-04-01 14:29:03 +0000 | [diff] [blame] | 17 | |
| 18 | void NS16550_init (NS16550_t com_port, int baud_divisor) |
| 19 | { |
| 20 | com_port->ier = 0x00; |
Tom Rix | 93bed9b | 2009-05-31 12:44:37 +0200 | [diff] [blame] | 21 | #if defined(CONFIG_OMAP) && !defined(CONFIG_OMAP3_ZOOM2) |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 22 | com_port->mdr1 = 0x7; /* mode select reset TL16C750*/ |
wdenk | 21136db | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 23 | #endif |
Detlev Zundel | 166fb54 | 2009-04-03 11:53:01 +0200 | [diff] [blame] | 24 | com_port->lcr = UART_LCR_BKSE | UART_LCRVAL; |
Wolfgang Denk | fd1569d | 2007-12-27 10:56:54 +0100 | [diff] [blame] | 25 | com_port->dll = 0; |
| 26 | com_port->dlm = 0; |
Detlev Zundel | 166fb54 | 2009-04-03 11:53:01 +0200 | [diff] [blame] | 27 | com_port->lcr = UART_LCRVAL; |
| 28 | com_port->mcr = UART_MCRVAL; |
| 29 | com_port->fcr = UART_FCRVAL; |
| 30 | com_port->lcr = UART_LCR_BKSE | UART_LCRVAL; |
Wolfgang Denk | fd1569d | 2007-12-27 10:56:54 +0100 | [diff] [blame] | 31 | com_port->dll = baud_divisor & 0xff; |
| 32 | com_port->dlm = (baud_divisor >> 8) & 0xff; |
Detlev Zundel | 166fb54 | 2009-04-03 11:53:01 +0200 | [diff] [blame] | 33 | com_port->lcr = UART_LCRVAL; |
Tom Rix | 93bed9b | 2009-05-31 12:44:37 +0200 | [diff] [blame] | 34 | #if defined(CONFIG_OMAP) && !defined(CONFIG_OMAP3_ZOOM2) |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 35 | #if defined(CONFIG_APTIX) |
| 36 | com_port->mdr1 = 3; /* /13 mode so Aptix 6MHz can hit 115200 */ |
| 37 | #else |
| 38 | com_port->mdr1 = 0; /* /16 is proper to hit 115200 with 48MHz */ |
| 39 | #endif |
Mike Frysinger | d0e9786 | 2009-02-11 20:26:52 -0500 | [diff] [blame] | 40 | #endif /* CONFIG_OMAP */ |
wdenk | e85390d | 2002-04-01 14:29:03 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Ron Madrid | dfa028a | 2009-02-18 14:30:44 -0800 | [diff] [blame] | 43 | #ifndef CONFIG_NS16550_MIN_FUNCTIONS |
wdenk | e85390d | 2002-04-01 14:29:03 +0000 | [diff] [blame] | 44 | void NS16550_reinit (NS16550_t com_port, int baud_divisor) |
| 45 | { |
| 46 | com_port->ier = 0x00; |
Detlev Zundel | 166fb54 | 2009-04-03 11:53:01 +0200 | [diff] [blame] | 47 | com_port->lcr = UART_LCR_BKSE | UART_LCRVAL; |
Wolfgang Denk | fd1569d | 2007-12-27 10:56:54 +0100 | [diff] [blame] | 48 | com_port->dll = 0; |
| 49 | com_port->dlm = 0; |
Detlev Zundel | 166fb54 | 2009-04-03 11:53:01 +0200 | [diff] [blame] | 50 | com_port->lcr = UART_LCRVAL; |
| 51 | com_port->mcr = UART_MCRVAL; |
| 52 | com_port->fcr = UART_FCRVAL; |
| 53 | com_port->lcr = UART_LCR_BKSE; |
wdenk | e85390d | 2002-04-01 14:29:03 +0000 | [diff] [blame] | 54 | com_port->dll = baud_divisor & 0xff; |
| 55 | com_port->dlm = (baud_divisor >> 8) & 0xff; |
Detlev Zundel | 166fb54 | 2009-04-03 11:53:01 +0200 | [diff] [blame] | 56 | com_port->lcr = UART_LCRVAL; |
wdenk | e85390d | 2002-04-01 14:29:03 +0000 | [diff] [blame] | 57 | } |
Ron Madrid | dfa028a | 2009-02-18 14:30:44 -0800 | [diff] [blame] | 58 | #endif /* CONFIG_NS16550_MIN_FUNCTIONS */ |
wdenk | e85390d | 2002-04-01 14:29:03 +0000 | [diff] [blame] | 59 | |
| 60 | void NS16550_putc (NS16550_t com_port, char c) |
| 61 | { |
Detlev Zundel | 166fb54 | 2009-04-03 11:53:01 +0200 | [diff] [blame] | 62 | while ((com_port->lsr & UART_LSR_THRE) == 0); |
wdenk | e85390d | 2002-04-01 14:29:03 +0000 | [diff] [blame] | 63 | com_port->thr = c; |
| 64 | } |
| 65 | |
Ron Madrid | dfa028a | 2009-02-18 14:30:44 -0800 | [diff] [blame] | 66 | #ifndef CONFIG_NS16550_MIN_FUNCTIONS |
wdenk | e85390d | 2002-04-01 14:29:03 +0000 | [diff] [blame] | 67 | char NS16550_getc (NS16550_t com_port) |
| 68 | { |
Detlev Zundel | 166fb54 | 2009-04-03 11:53:01 +0200 | [diff] [blame] | 69 | while ((com_port->lsr & UART_LSR_DR) == 0) { |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 70 | #ifdef CONFIG_USB_TTY |
| 71 | extern void usbtty_poll(void); |
| 72 | usbtty_poll(); |
| 73 | #endif |
Ladislav Michl | cc29442 | 2010-02-01 23:34:25 +0100 | [diff] [blame] | 74 | WATCHDOG_RESET(); |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 75 | } |
wdenk | e85390d | 2002-04-01 14:29:03 +0000 | [diff] [blame] | 76 | return (com_port->rbr); |
| 77 | } |
| 78 | |
| 79 | int NS16550_tstc (NS16550_t com_port) |
| 80 | { |
Detlev Zundel | 166fb54 | 2009-04-03 11:53:01 +0200 | [diff] [blame] | 81 | return ((com_port->lsr & UART_LSR_DR) != 0); |
wdenk | e85390d | 2002-04-01 14:29:03 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Ron Madrid | dfa028a | 2009-02-18 14:30:44 -0800 | [diff] [blame] | 84 | #endif /* CONFIG_NS16550_MIN_FUNCTIONS */ |