blob: 2fcc8c31633ab9d41e859847c17b02e9d0805545 [file] [log] [blame]
wdenke85390d2002-04-01 14:29:03 +00001/*
2 * COM1 NS16550 support
3 * originally from linux source (arch/ppc/boot/ns16550.c)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02004 * modified to use CONFIG_SYS_ISA_MEM and new defines
wdenke85390d2002-04-01 14:29:03 +00005 */
6
7#include <config.h>
wdenke85390d2002-04-01 14:29:03 +00008#include <ns16550.h>
9
Detlev Zundel166fb542009-04-03 11:53:01 +020010#define UART_LCRVAL UART_LCR_8N1 /* 8 data, 1 stop, no parity */
11#define UART_MCRVAL (UART_MCR_DTR | \
12 UART_MCR_RTS) /* RTS/DTR */
13#define UART_FCRVAL (UART_FCR_FIFO_EN | \
14 UART_FCR_RXSR | \
15 UART_FCR_TXSR) /* Clear & enable FIFOs */
wdenke85390d2002-04-01 14:29:03 +000016
17void NS16550_init (NS16550_t com_port, int baud_divisor)
18{
19 com_port->ier = 0x00;
Tom Rix93bed9b2009-05-31 12:44:37 +020020#if defined(CONFIG_OMAP) && !defined(CONFIG_OMAP3_ZOOM2)
wdenk29e7f5a2004-03-12 00:14:09 +000021 com_port->mdr1 = 0x7; /* mode select reset TL16C750*/
wdenk21136db2003-07-16 21:53:01 +000022#endif
Detlev Zundel166fb542009-04-03 11:53:01 +020023 com_port->lcr = UART_LCR_BKSE | UART_LCRVAL;
Wolfgang Denkfd1569d2007-12-27 10:56:54 +010024 com_port->dll = 0;
25 com_port->dlm = 0;
Detlev Zundel166fb542009-04-03 11:53:01 +020026 com_port->lcr = UART_LCRVAL;
27 com_port->mcr = UART_MCRVAL;
28 com_port->fcr = UART_FCRVAL;
29 com_port->lcr = UART_LCR_BKSE | UART_LCRVAL;
Wolfgang Denkfd1569d2007-12-27 10:56:54 +010030 com_port->dll = baud_divisor & 0xff;
31 com_port->dlm = (baud_divisor >> 8) & 0xff;
Detlev Zundel166fb542009-04-03 11:53:01 +020032 com_port->lcr = UART_LCRVAL;
Tom Rix93bed9b2009-05-31 12:44:37 +020033#if defined(CONFIG_OMAP) && !defined(CONFIG_OMAP3_ZOOM2)
wdenkf8062712005-01-09 23:16:25 +000034#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
Mike Frysingerd0e97862009-02-11 20:26:52 -050039#endif /* CONFIG_OMAP */
wdenke85390d2002-04-01 14:29:03 +000040}
41
Ron Madriddfa028a2009-02-18 14:30:44 -080042#ifndef CONFIG_NS16550_MIN_FUNCTIONS
wdenke85390d2002-04-01 14:29:03 +000043void NS16550_reinit (NS16550_t com_port, int baud_divisor)
44{
45 com_port->ier = 0x00;
Detlev Zundel166fb542009-04-03 11:53:01 +020046 com_port->lcr = UART_LCR_BKSE | UART_LCRVAL;
Wolfgang Denkfd1569d2007-12-27 10:56:54 +010047 com_port->dll = 0;
48 com_port->dlm = 0;
Detlev Zundel166fb542009-04-03 11:53:01 +020049 com_port->lcr = UART_LCRVAL;
50 com_port->mcr = UART_MCRVAL;
51 com_port->fcr = UART_FCRVAL;
52 com_port->lcr = UART_LCR_BKSE;
wdenke85390d2002-04-01 14:29:03 +000053 com_port->dll = baud_divisor & 0xff;
54 com_port->dlm = (baud_divisor >> 8) & 0xff;
Detlev Zundel166fb542009-04-03 11:53:01 +020055 com_port->lcr = UART_LCRVAL;
wdenke85390d2002-04-01 14:29:03 +000056}
Ron Madriddfa028a2009-02-18 14:30:44 -080057#endif /* CONFIG_NS16550_MIN_FUNCTIONS */
wdenke85390d2002-04-01 14:29:03 +000058
59void NS16550_putc (NS16550_t com_port, char c)
60{
Detlev Zundel166fb542009-04-03 11:53:01 +020061 while ((com_port->lsr & UART_LSR_THRE) == 0);
wdenke85390d2002-04-01 14:29:03 +000062 com_port->thr = c;
63}
64
Ron Madriddfa028a2009-02-18 14:30:44 -080065#ifndef CONFIG_NS16550_MIN_FUNCTIONS
wdenke85390d2002-04-01 14:29:03 +000066char NS16550_getc (NS16550_t com_port)
67{
Detlev Zundel166fb542009-04-03 11:53:01 +020068 while ((com_port->lsr & UART_LSR_DR) == 0) {
wdenk29e7f5a2004-03-12 00:14:09 +000069#ifdef CONFIG_USB_TTY
70 extern void usbtty_poll(void);
71 usbtty_poll();
72#endif
73 }
wdenke85390d2002-04-01 14:29:03 +000074 return (com_port->rbr);
75}
76
77int NS16550_tstc (NS16550_t com_port)
78{
Detlev Zundel166fb542009-04-03 11:53:01 +020079 return ((com_port->lsr & UART_LSR_DR) != 0);
wdenke85390d2002-04-01 14:29:03 +000080}
81
Ron Madriddfa028a2009-02-18 14:30:44 -080082#endif /* CONFIG_NS16550_MIN_FUNCTIONS */