blob: 397f5df5d60b81139852037c35c9464ba6bece27 [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
10#define LCRVAL LCR_8N1 /* 8 data, 1 stop, no parity */
11#define MCRVAL (MCR_DTR | MCR_RTS) /* RTS/DTR */
12#define FCRVAL (FCR_FIFO_EN | FCR_RXSR | FCR_TXSR) /* Clear & enable FIFOs */
13
14void NS16550_init (NS16550_t com_port, int baud_divisor)
15{
16 com_port->ier = 0x00;
wdenkf8062712005-01-09 23:16:25 +000017#ifdef CONFIG_OMAP
wdenk29e7f5a2004-03-12 00:14:09 +000018 com_port->mdr1 = 0x7; /* mode select reset TL16C750*/
wdenk21136db2003-07-16 21:53:01 +000019#endif
wdenke85390d2002-04-01 14:29:03 +000020 com_port->lcr = LCR_BKSE | LCRVAL;
Wolfgang Denkfd1569d2007-12-27 10:56:54 +010021 com_port->dll = 0;
22 com_port->dlm = 0;
wdenke85390d2002-04-01 14:29:03 +000023 com_port->lcr = LCRVAL;
24 com_port->mcr = MCRVAL;
25 com_port->fcr = FCRVAL;
Wolfgang Denkfd1569d2007-12-27 10:56:54 +010026 com_port->lcr = LCR_BKSE | LCRVAL;
27 com_port->dll = baud_divisor & 0xff;
28 com_port->dlm = (baud_divisor >> 8) & 0xff;
29 com_port->lcr = LCRVAL;
wdenkf8062712005-01-09 23:16:25 +000030#if defined(CONFIG_OMAP)
31#if defined(CONFIG_APTIX)
32 com_port->mdr1 = 3; /* /13 mode so Aptix 6MHz can hit 115200 */
33#else
34 com_port->mdr1 = 0; /* /16 is proper to hit 115200 with 48MHz */
35#endif
Mike Frysingerd0e97862009-02-11 20:26:52 -050036#endif /* CONFIG_OMAP */
wdenke85390d2002-04-01 14:29:03 +000037}
38
Ron Madriddfa028a2009-02-18 14:30:44 -080039#ifndef CONFIG_NS16550_MIN_FUNCTIONS
wdenke85390d2002-04-01 14:29:03 +000040void NS16550_reinit (NS16550_t com_port, int baud_divisor)
41{
42 com_port->ier = 0x00;
Wolfgang Denkfd1569d2007-12-27 10:56:54 +010043 com_port->lcr = LCR_BKSE | LCRVAL;
44 com_port->dll = 0;
45 com_port->dlm = 0;
46 com_port->lcr = LCRVAL;
47 com_port->mcr = MCRVAL;
48 com_port->fcr = FCRVAL;
wdenke85390d2002-04-01 14:29:03 +000049 com_port->lcr = LCR_BKSE;
50 com_port->dll = baud_divisor & 0xff;
51 com_port->dlm = (baud_divisor >> 8) & 0xff;
52 com_port->lcr = LCRVAL;
wdenke85390d2002-04-01 14:29:03 +000053}
Ron Madriddfa028a2009-02-18 14:30:44 -080054#endif /* CONFIG_NS16550_MIN_FUNCTIONS */
wdenke85390d2002-04-01 14:29:03 +000055
56void NS16550_putc (NS16550_t com_port, char c)
57{
58 while ((com_port->lsr & LSR_THRE) == 0);
59 com_port->thr = c;
60}
61
Ron Madriddfa028a2009-02-18 14:30:44 -080062#ifndef CONFIG_NS16550_MIN_FUNCTIONS
wdenke85390d2002-04-01 14:29:03 +000063char NS16550_getc (NS16550_t com_port)
64{
wdenk29e7f5a2004-03-12 00:14:09 +000065 while ((com_port->lsr & LSR_DR) == 0) {
66#ifdef CONFIG_USB_TTY
67 extern void usbtty_poll(void);
68 usbtty_poll();
69#endif
70 }
wdenke85390d2002-04-01 14:29:03 +000071 return (com_port->rbr);
72}
73
74int NS16550_tstc (NS16550_t com_port)
75{
76 return ((com_port->lsr & LSR_DR) != 0);
77}
78
Ron Madriddfa028a2009-02-18 14:30:44 -080079#endif /* CONFIG_NS16550_MIN_FUNCTIONS */