]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - drivers/ns16550.c
f9fe819c1d3421d3406c171d3a0b7cf999bcb647
[karo-tx-uboot.git] / drivers / ns16550.c
1 /*
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
17 void NS16550_init (NS16550_t com_port, int baud_divisor)
18 {
19         com_port->ier = 0x00;
20 #ifdef CONFIG_OMAP1510
21         com_port->mdr1 = 0x7;   /* mode select reset TL16C750*/
22 #endif
23         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;
29 #if defined(CONFIG_OMAP1510) || defined(CONFIG_OMAP1610) || defined(CONFIG_OMAP730)
30         com_port->mdr1 = 0;     /* select uart mode */
31 #endif
32 }
33
34 void NS16550_reinit (NS16550_t com_port, int baud_divisor)
35 {
36         com_port->ier = 0x00;
37         com_port->lcr = LCR_BKSE;
38         com_port->dll = baud_divisor & 0xff;
39         com_port->dlm = (baud_divisor >> 8) & 0xff;
40         com_port->lcr = LCRVAL;
41         com_port->mcr = MCRVAL;
42         com_port->fcr = FCRVAL;
43 }
44
45 void NS16550_putc (NS16550_t com_port, char c)
46 {
47         while ((com_port->lsr & LSR_THRE) == 0);
48         com_port->thr = c;
49 }
50
51 char NS16550_getc (NS16550_t com_port)
52 {
53         while ((com_port->lsr & LSR_DR) == 0) {
54 #ifdef CONFIG_USB_TTY
55                 extern void usbtty_poll(void);
56                 usbtty_poll();
57 #endif
58         }
59         return (com_port->rbr);
60 }
61
62 int NS16550_tstc (NS16550_t com_port)
63 {
64         return ((com_port->lsr & LSR_DR) != 0);
65 }
66
67 #endif