]> git.ipfire.org Git - people/ms/u-boot.git/blame - drivers/serial/ns16550.c
x86: Fix copying of Real-Mode code into RAM
[people/ms/u-boot.git] / drivers / serial / ns16550.c
CommitLineData
e85390dc
WD
1/*
2 * COM1 NS16550 support
a47a12be 3 * originally from linux source (arch/powerpc/boot/ns16550.c)
6d0f6bcf 4 * modified to use CONFIG_SYS_ISA_MEM and new defines
e85390dc
WD
5 */
6
7#include <config.h>
e85390dc 8#include <ns16550.h>
a1b322a9 9#include <watchdog.h>
e85390dc 10
200779e3
DZ
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 */
e85390dc
WD
17
18void NS16550_init (NS16550_t com_port, int baud_divisor)
19{
20 com_port->ier = 0x00;
660888b7 21#if defined(CONFIG_OMAP) && !defined(CONFIG_OMAP3_ZOOM2)
232c150a 22 com_port->mdr1 = 0x7; /* mode select reset TL16C750*/
945af8d7 23#endif
200779e3 24 com_port->lcr = UART_LCR_BKSE | UART_LCRVAL;
7ec8bb15
WD
25 com_port->dll = 0;
26 com_port->dlm = 0;
200779e3
DZ
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;
7ec8bb15
WD
31 com_port->dll = baud_divisor & 0xff;
32 com_port->dlm = (baud_divisor >> 8) & 0xff;
200779e3 33 com_port->lcr = UART_LCRVAL;
660888b7 34#if defined(CONFIG_OMAP) && !defined(CONFIG_OMAP3_ZOOM2)
8ed96046
WD
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
b4746d8b 40#endif /* CONFIG_OMAP */
e85390dc
WD
41}
42
f5675aa5 43#ifndef CONFIG_NS16550_MIN_FUNCTIONS
e85390dc
WD
44void NS16550_reinit (NS16550_t com_port, int baud_divisor)
45{
46 com_port->ier = 0x00;
200779e3 47 com_port->lcr = UART_LCR_BKSE | UART_LCRVAL;
7ec8bb15
WD
48 com_port->dll = 0;
49 com_port->dlm = 0;
200779e3
DZ
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;
e85390dc
WD
54 com_port->dll = baud_divisor & 0xff;
55 com_port->dlm = (baud_divisor >> 8) & 0xff;
200779e3 56 com_port->lcr = UART_LCRVAL;
e85390dc 57}
f5675aa5 58#endif /* CONFIG_NS16550_MIN_FUNCTIONS */
e85390dc
WD
59
60void NS16550_putc (NS16550_t com_port, char c)
61{
200779e3 62 while ((com_port->lsr & UART_LSR_THRE) == 0);
e85390dc
WD
63 com_port->thr = c;
64}
65
f5675aa5 66#ifndef CONFIG_NS16550_MIN_FUNCTIONS
e85390dc
WD
67char NS16550_getc (NS16550_t com_port)
68{
200779e3 69 while ((com_port->lsr & UART_LSR_DR) == 0) {
232c150a
WD
70#ifdef CONFIG_USB_TTY
71 extern void usbtty_poll(void);
72 usbtty_poll();
73#endif
a1b322a9 74 WATCHDOG_RESET();
232c150a 75 }
e85390dc
WD
76 return (com_port->rbr);
77}
78
79int NS16550_tstc (NS16550_t com_port)
80{
200779e3 81 return ((com_port->lsr & UART_LSR_DR) != 0);
e85390dc
WD
82}
83
f5675aa5 84#endif /* CONFIG_NS16550_MIN_FUNCTIONS */