blob: 36d0e6e1f69cec306528dba32f18721e38bd9e3b [file] [log] [blame]
wdenk78f66222002-08-27 10:27:51 +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
26#ifdef CFG_NS16550_SERIAL
27
28#include <ns16550.h>
29#ifdef CFG_NS87308
30#include <ns87308.h>
31#endif
32
33#if CONFIG_CONS_INDEX == 1
34static NS16550_t console = (NS16550_t) CFG_NS16550_COM1;
35#elif CONFIG_CONS_INDEX == 2
36static NS16550_t console = (NS16550_t) CFG_NS16550_COM2;
37#elif CONFIG_CONS_INDEX == 3
38static NS16550_t console = (NS16550_t) CFG_NS16550_COM3;
39#elif CONFIG_CONS_INDEX == 4
40static NS16550_t console = (NS16550_t) CFG_NS16550_COM4;
41#else
42#error no valid console defined
43#endif
44
45int serial_init (void)
46{
47 DECLARE_GLOBAL_DATA_PTR;
48
wdenk03329902003-06-20 22:36:30 +000049 int clock_divisor = (CFG_NS16550_CLK + gd->baudrate * 8 )
50 / (gd->baudrate * 16);
wdenk78f66222002-08-27 10:27:51 +000051
52#ifdef CFG_NS87308
53 initialise_ns87308();
54#endif
55
56 NS16550_init(console, clock_divisor);
57
58 return (0);
59}
60
61void
62serial_putc(const char c)
63{
64 if (c == '\n')
65 NS16550_putc(console, '\r');
66
67 NS16550_putc(console, c);
68}
69
70void
71serial_puts (const char *s)
72{
73 while (*s) {
74 serial_putc (*s++);
75 }
76}
77
78
79int
80serial_getc(void)
81{
82 return NS16550_getc(console);
83}
84
85int
86serial_tstc(void)
87{
88 return NS16550_tstc(console);
89}
90
91void
92serial_setbrg (void)
93{
94 DECLARE_GLOBAL_DATA_PTR;
95
96 int clock_divisor = CFG_NS16550_CLK / 16 / gd->baudrate;
97
98 NS16550_reinit(console, clock_divisor);
99}
100
101#endif