blob: be455bbefe9e14ef94520ded0e39c90b21b28e51 [file] [log] [blame]
wdenk71fc6c52002-08-06 19:52:25 +00001/*
2 * COM1 NS16550 support
Stefan Roesea47a12b2010-04-15 16:07:28 +02003 * originally from linux source (arch/powerpc/boot/ns16550.c)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02004 * modified to use CONFIG_SYS_ISA_MEM and new defines
wdenk71fc6c52002-08-06 19:52:25 +00005 */
6
7#include <config.h>
8#include "ns16550.h"
9
10typedef struct NS16550 *NS16550_t;
11
wdenkbf9e3b32004-02-12 00:47:09 +000012const NS16550_t COM_PORTS[] =
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020013 { (NS16550_t) ((CONFIG_SYS_EUMB_ADDR) + 0x4500),
14(NS16550_t) ((CONFIG_SYS_EUMB_ADDR) + 0x4600) };
wdenk71fc6c52002-08-06 19:52:25 +000015
wdenkbf9e3b32004-02-12 00:47:09 +000016volatile struct NS16550 *NS16550_init (int chan, int baud_divisor)
wdenk71fc6c52002-08-06 19:52:25 +000017{
wdenkbf9e3b32004-02-12 00:47:09 +000018 volatile struct NS16550 *com_port;
19
20 com_port = (struct NS16550 *) COM_PORTS[chan];
21 com_port->ier = 0x00;
22 com_port->lcr = LCR_BKSE; /* Access baud rate */
23 com_port->dll = baud_divisor & 0xff; /* 9600 baud */
24 com_port->dlm = (baud_divisor >> 8) & 0xff;
25 com_port->lcr = LCR_8N1; /* 8 data, 1 stop, no parity */
26 com_port->mcr = MCR_RTS; /* RTS/DTR */
27 com_port->fcr = FCR_FIFO_EN | FCR_RXSR | FCR_TXSR; /* Clear & enable FIFOs */
28 return (com_port);
wdenk71fc6c52002-08-06 19:52:25 +000029}
30
wdenkbf9e3b32004-02-12 00:47:09 +000031void NS16550_reinit (volatile struct NS16550 *com_port, int baud_divisor)
wdenk71fc6c52002-08-06 19:52:25 +000032{
wdenkbf9e3b32004-02-12 00:47:09 +000033 com_port->ier = 0x00;
34 com_port->lcr = LCR_BKSE; /* Access baud rate */
35 com_port->dll = baud_divisor & 0xff; /* 9600 baud */
36 com_port->dlm = (baud_divisor >> 8) & 0xff;
37 com_port->lcr = LCR_8N1; /* 8 data, 1 stop, no parity */
38 com_port->mcr = MCR_RTS; /* RTS/DTR */
39 com_port->fcr = FCR_FIFO_EN | FCR_RXSR | FCR_TXSR; /* Clear & enable FIFOs */
wdenk71fc6c52002-08-06 19:52:25 +000040}
41
wdenkbf9e3b32004-02-12 00:47:09 +000042void NS16550_putc (volatile struct NS16550 *com_port, unsigned char c)
wdenk71fc6c52002-08-06 19:52:25 +000043{
wdenkbf9e3b32004-02-12 00:47:09 +000044 while ((com_port->lsr & LSR_THRE) == 0);
45 com_port->thr = c;
wdenk71fc6c52002-08-06 19:52:25 +000046}
47
wdenkbf9e3b32004-02-12 00:47:09 +000048unsigned char NS16550_getc (volatile struct NS16550 *com_port)
wdenk71fc6c52002-08-06 19:52:25 +000049{
wdenkbf9e3b32004-02-12 00:47:09 +000050 while ((com_port->lsr & LSR_DR) == 0);
51 return (com_port->rbr);
wdenk71fc6c52002-08-06 19:52:25 +000052}
53
wdenkbf9e3b32004-02-12 00:47:09 +000054int NS16550_tstc (volatile struct NS16550 *com_port)
wdenk71fc6c52002-08-06 19:52:25 +000055{
wdenkbf9e3b32004-02-12 00:47:09 +000056 return ((com_port->lsr & LSR_DR) != 0);
wdenk71fc6c52002-08-06 19:52:25 +000057}