blob: 9d0d2138e21785d9193e531bad74bbfa7c235ba2 [file] [log] [blame]
wdenk5da7f2f2004-01-03 00:43:19 +00001/*
2 * (C) Copyright 2001
3 * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc.
4 *
5 * modified for marvell db64360 eval board by
6 * Ingo Assmus <ingo.assmus@keymile.com>
7 *
8 * See file CREDITS for list of people who contributed to this
9 * project.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 * MA 02111-1307 USA
25 */
26
27/*
28 * serial.c - serial support for the gal ev board
29 */
30
31/* supports both the 16650 duart and the MPSC */
32
33#include <common.h>
34#include <command.h>
35#include "../include/memory.h"
36#include "serial.h"
37
38#ifdef CONFIG_DB64360
39#include "../db64360/mpsc.h"
40#endif
41
42#ifdef CONFIG_DB64460
43#include "../db64460/mpsc.h"
44#endif
45
46#include "ns16550.h"
47
48#ifdef CONFIG_MPSC
49
50
51int serial_init (void)
52{
53 DECLARE_GLOBAL_DATA_PTR;
54
55#if (defined CFG_INIT_CHAN1) || (defined CFG_INIT_CHAN2)
56 int clock_divisor = 230400 / gd->baudrate;
57#endif
58
59 mpsc_init (gd->baudrate);
60
61 /* init the DUART chans so that KGDB in the kernel can use them */
62#ifdef CFG_INIT_CHAN1
63 NS16550_reinit (COM_PORTS[0], clock_divisor);
64#endif
65#ifdef CFG_INIT_CHAN2
66 NS16550_reinit (COM_PORTS[1], clock_divisor);
67#endif
68 return (0);
69}
70
71void serial_putc (const char c)
72{
73 if (c == '\n')
74 mpsc_putchar ('\r');
75
76 mpsc_putchar (c);
77}
78
79int serial_getc (void)
80{
81 return mpsc_getchar ();
82}
83
84int serial_tstc (void)
85{
86 return mpsc_test_char ();
87}
88
89void serial_setbrg (void)
90{
91 DECLARE_GLOBAL_DATA_PTR;
92
93 galbrg_set_baudrate (CONFIG_MPSC_PORT, gd->baudrate);
94}
95
96#else /* ! CONFIG_MPSC */
97
98int serial_init (void)
99{
100 DECLARE_GLOBAL_DATA_PTR;
101
102 int clock_divisor = 230400 / gd->baudrate;
103
104#ifdef CFG_INIT_CHAN1
105 (void) NS16550_init (0, clock_divisor);
106#endif
107#ifdef CFG_INIT_CHAN2
108 (void) NS16550_init (1, clock_divisor);
109#endif
110 return (0);
111}
112
113void serial_putc (const char c)
114{
115 if (c == '\n')
116 NS16550_putc (COM_PORTS[CFG_DUART_CHAN], '\r');
117
118 NS16550_putc (COM_PORTS[CFG_DUART_CHAN], c);
119}
120
121int serial_getc (void)
122{
123 return NS16550_getc (COM_PORTS[CFG_DUART_CHAN]);
124}
125
126int serial_tstc (void)
127{
128 return NS16550_tstc (COM_PORTS[CFG_DUART_CHAN]);
129}
130
131void serial_setbrg (void)
132{
133 DECLARE_GLOBAL_DATA_PTR;
134
135 int clock_divisor = 230400 / gd->baudrate;
136
137#ifdef CFG_INIT_CHAN1
138 NS16550_reinit (COM_PORTS[0], clock_divisor);
139#endif
140#ifdef CFG_INIT_CHAN2
141 NS16550_reinit (COM_PORTS[1], clock_divisor);
142#endif
143}
144
145#endif /* CONFIG_MPSC */
146
147void serial_puts (const char *s)
148{
149 while (*s) {
150 serial_putc (*s++);
151 }
152}
153
154#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
155void kgdb_serial_init (void)
156{
157}
158
159void putDebugChar (int c)
160{
161 serial_putc (c);
162}
163
164void putDebugStr (const char *str)
165{
166 serial_puts (str);
167}
168
169int getDebugChar (void)
170{
171 return serial_getc ();
172}
173
174void kgdb_interruptible (int yes)
175{
176 return;
177}
178#endif /* CFG_CMD_KGDB */