blob: 2429464d89656f167480ba0efc4af7fb4584adf0 [file] [log] [blame]
wdenke85390d2002-04-01 14:29:03 +00001/*
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
17void NS16550_init (NS16550_t com_port, int baud_divisor)
18{
19 com_port->ier = 0x00;
wdenkf8062712005-01-09 23:16:25 +000020#ifdef CONFIG_OMAP
wdenk29e7f5a2004-03-12 00:14:09 +000021 com_port->mdr1 = 0x7; /* mode select reset TL16C750*/
wdenk21136db2003-07-16 21:53:01 +000022#endif
wdenke85390d2002-04-01 14:29:03 +000023 com_port->lcr = LCR_BKSE | LCRVAL;
24 com_port->dll = baud_divisor & 0xff;
25 com_port->dlm = (baud_divisor >> 8) & 0xff;
26 com_port->lcr = LCRVAL;
27 com_port->mcr = MCRVAL;
28 com_port->fcr = FCRVAL;
wdenkf8062712005-01-09 23:16:25 +000029#if defined(CONFIG_OMAP)
30#if defined(CONFIG_APTIX)
31 com_port->mdr1 = 3; /* /13 mode so Aptix 6MHz can hit 115200 */
32#else
33 com_port->mdr1 = 0; /* /16 is proper to hit 115200 with 48MHz */
34#endif
wdenkf6f96f72003-07-15 20:04:06 +000035#endif
wdenke85390d2002-04-01 14:29:03 +000036}
37
38void NS16550_reinit (NS16550_t com_port, int baud_divisor)
39{
40 com_port->ier = 0x00;
41 com_port->lcr = LCR_BKSE;
42 com_port->dll = baud_divisor & 0xff;
43 com_port->dlm = (baud_divisor >> 8) & 0xff;
44 com_port->lcr = LCRVAL;
45 com_port->mcr = MCRVAL;
46 com_port->fcr = FCRVAL;
47}
48
49void NS16550_putc (NS16550_t com_port, char c)
50{
51 while ((com_port->lsr & LSR_THRE) == 0);
52 com_port->thr = c;
53}
54
55char NS16550_getc (NS16550_t com_port)
56{
wdenk29e7f5a2004-03-12 00:14:09 +000057 while ((com_port->lsr & LSR_DR) == 0) {
58#ifdef CONFIG_USB_TTY
59 extern void usbtty_poll(void);
60 usbtty_poll();
61#endif
62 }
wdenke85390d2002-04-01 14:29:03 +000063 return (com_port->rbr);
64}
65
66int NS16550_tstc (NS16550_t com_port)
67{
68 return ((com_port->lsr & LSR_DR) != 0);
69}
70
71#endif