blob: 0c97f1288f12662ffdd38668ae3d0d28d9609bcf [file] [log] [blame]
wdenkf8cac652002-08-26 22:36:39 +00001/*
2 * (C) Copyright 2000
3 * Rob Taylor, Flying Pig Systems. robt@flyingpig.com.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
25#include "ns16550.h"
26
Wolfgang Denkd87080b2006-03-31 18:32:53 +020027DECLARE_GLOBAL_DATA_PTR;
28
wdenkf8cac652002-08-26 22:36:39 +000029#if CONFIG_CONS_INDEX == 1
30static struct NS16550 *console =
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020031 (struct NS16550 *) (CONFIG_SYS_EUMB_ADDR + 0x4500);
wdenkf8cac652002-08-26 22:36:39 +000032#elif CONFIG_CONS_INDEX == 2
33static struct NS16550 *console =
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020034 (struct NS16550 *) (CONFIG_SYS_EUMB_ADDR + 0x4500);
wdenkf8cac652002-08-26 22:36:39 +000035#else
36#error no valid console defined
37#endif
38
39extern ulong get_bus_freq (ulong);
40
41int serial_init (void)
42{
wdenkf8cac652002-08-26 22:36:39 +000043 int clock_divisor = gd->bus_clk / 16 / gd->baudrate;
44
45 NS16550_init (CONFIG_CONS_INDEX - 1, clock_divisor);
46
47 return (0);
48}
49
50void serial_putc (const char c)
51{
52 if (c == '\n') {
53 serial_putc ('\r');
54 }
55 NS16550_putc (console, c);
56}
57
58void serial_puts (const char *s)
59{
60 while (*s) {
61 serial_putc (*s++);
62 }
63}
64
65
66int serial_getc (void)
67{
68 return NS16550_getc (console);
69}
70
71int serial_tstc (void)
72{
73 return NS16550_tstc (console);
74}
75
76void serial_setbrg (void)
77{
wdenkf8cac652002-08-26 22:36:39 +000078 int clock_divisor = get_bus_freq (0) / 16 / gd->baudrate;
79
80 NS16550_reinit (console, clock_divisor);
81}