blob: 23c0f76ddea928c205f62f58e09a315468ca8a43 [file] [log] [blame]
wdenke85390d2002-04-01 14:29:03 +00001/*
2 * COM1 NS16550 support
Stefan Roese88fbf932010-04-15 16:07:28 +02003 * originally from linux source (arch/powerpc/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>
Ladislav Michlcc294422010-02-01 23:34:25 +01009#include <watchdog.h>
wdenke85390d2002-04-01 14:29:03 +000010
Detlev Zundel166fb542009-04-03 11:53:01 +020011#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 */
wdenke85390d2002-04-01 14:29:03 +000017
18void NS16550_init (NS16550_t com_port, int baud_divisor)
19{
20 com_port->ier = 0x00;
Tom Rix93bed9b2009-05-31 12:44:37 +020021#if defined(CONFIG_OMAP) && !defined(CONFIG_OMAP3_ZOOM2)
wdenk29e7f5a2004-03-12 00:14:09 +000022 com_port->mdr1 = 0x7; /* mode select reset TL16C750*/
wdenk21136db2003-07-16 21:53:01 +000023#endif
Detlev Zundel166fb542009-04-03 11:53:01 +020024 com_port->lcr = UART_LCR_BKSE | UART_LCRVAL;
Wolfgang Denkfd1569d2007-12-27 10:56:54 +010025 com_port->dll = 0;
26 com_port->dlm = 0;
Detlev Zundel166fb542009-04-03 11:53:01 +020027 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 Denkfd1569d2007-12-27 10:56:54 +010031 com_port->dll = baud_divisor & 0xff;
32 com_port->dlm = (baud_divisor >> 8) & 0xff;
Detlev Zundel166fb542009-04-03 11:53:01 +020033 com_port->lcr = UART_LCRVAL;
Tom Rix93bed9b2009-05-31 12:44:37 +020034#if defined(CONFIG_OMAP) && !defined(CONFIG_OMAP3_ZOOM2)
wdenkf8062712005-01-09 23:16:25 +000035#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 Frysingerd0e97862009-02-11 20:26:52 -050040#endif /* CONFIG_OMAP */
wdenke85390d2002-04-01 14:29:03 +000041}
42
Ron Madriddfa028a2009-02-18 14:30:44 -080043#ifndef CONFIG_NS16550_MIN_FUNCTIONS
wdenke85390d2002-04-01 14:29:03 +000044void NS16550_reinit (NS16550_t com_port, int baud_divisor)
45{
46 com_port->ier = 0x00;
Detlev Zundel166fb542009-04-03 11:53:01 +020047 com_port->lcr = UART_LCR_BKSE | UART_LCRVAL;
Wolfgang Denkfd1569d2007-12-27 10:56:54 +010048 com_port->dll = 0;
49 com_port->dlm = 0;
Detlev Zundel166fb542009-04-03 11:53:01 +020050 com_port->lcr = UART_LCRVAL;
51 com_port->mcr = UART_MCRVAL;
52 com_port->fcr = UART_FCRVAL;
53 com_port->lcr = UART_LCR_BKSE;
wdenke85390d2002-04-01 14:29:03 +000054 com_port->dll = baud_divisor & 0xff;
55 com_port->dlm = (baud_divisor >> 8) & 0xff;
Detlev Zundel166fb542009-04-03 11:53:01 +020056 com_port->lcr = UART_LCRVAL;
wdenke85390d2002-04-01 14:29:03 +000057}
Ron Madriddfa028a2009-02-18 14:30:44 -080058#endif /* CONFIG_NS16550_MIN_FUNCTIONS */
wdenke85390d2002-04-01 14:29:03 +000059
60void NS16550_putc (NS16550_t com_port, char c)
61{
Detlev Zundel166fb542009-04-03 11:53:01 +020062 while ((com_port->lsr & UART_LSR_THRE) == 0);
wdenke85390d2002-04-01 14:29:03 +000063 com_port->thr = c;
64}
65
Ron Madriddfa028a2009-02-18 14:30:44 -080066#ifndef CONFIG_NS16550_MIN_FUNCTIONS
wdenke85390d2002-04-01 14:29:03 +000067char NS16550_getc (NS16550_t com_port)
68{
Detlev Zundel166fb542009-04-03 11:53:01 +020069 while ((com_port->lsr & UART_LSR_DR) == 0) {
wdenk29e7f5a2004-03-12 00:14:09 +000070#ifdef CONFIG_USB_TTY
71 extern void usbtty_poll(void);
72 usbtty_poll();
73#endif
Ladislav Michlcc294422010-02-01 23:34:25 +010074 WATCHDOG_RESET();
wdenk29e7f5a2004-03-12 00:14:09 +000075 }
wdenke85390d2002-04-01 14:29:03 +000076 return (com_port->rbr);
77}
78
79int NS16550_tstc (NS16550_t com_port)
80{
Detlev Zundel166fb542009-04-03 11:53:01 +020081 return ((com_port->lsr & UART_LSR_DR) != 0);
wdenke85390d2002-04-01 14:29:03 +000082}
83
Ron Madriddfa028a2009-02-18 14:30:44 -080084#endif /* CONFIG_NS16550_MIN_FUNCTIONS */