blob: d9c7a157c10abd616c24048408cf67433a2571b7 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
2 * (C) Copyright 2001
3 * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc.
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/*
25 * serial.c - serial support for the gal ev board
26 */
27
28/* supports both the 16650 duart and the MPSC */
29
30#include <common.h>
31#include <command.h>
32#include <galileo/memory.h>
33
34#if (defined CFG_INIT_CHAN1) || (defined CFG_INIT_CHAN2)
35#include <ns16550.h>
36#endif
37
38#include "serial.h"
39
40#include "mpsc.h"
41
42#if (defined CFG_INIT_CHAN1) || (defined CFG_INIT_CHAN2)
43const NS16550_t COM_PORTS[] = { (NS16550_t) CFG_NS16550_COM1,
44 (NS16550_t) CFG_NS16550_COM2 };
45#endif
46
47#ifdef CONFIG_MPSC
48
49int serial_init (void)
50{
51 DECLARE_GLOBAL_DATA_PTR;
52
53#if (defined CFG_INIT_CHAN1) || (defined CFG_INIT_CHAN2)
54 int clock_divisor = CFG_NS16550_CLK / 16 / gd->baudrate;
55#endif
56
57 mpsc_init(gd->baudrate);
58
59 /* init the DUART chans so that KGDB in the kernel can use them */
60#ifdef CFG_INIT_CHAN1
61 NS16550_reinit(COM_PORTS[0], clock_divisor);
62#endif
63#ifdef CFG_INIT_CHAN2
64 NS16550_reinit(COM_PORTS[1], clock_divisor);
65#endif
66 return (0);
67}
68
69void
70serial_putc(const char c)
71{
72 if (c == '\n')
73 mpsc_putchar('\r');
74
75 mpsc_putchar(c);
76}
77
78int
79serial_getc(void)
80{
81 return mpsc_getchar();
82}
83
84int
85serial_tstc(void)
86{
87 return mpsc_test_char();
88}
89
90void
91serial_setbrg (void)
92{
93 DECLARE_GLOBAL_DATA_PTR;
94
95 galbrg_set_baudrate(CONFIG_MPSC_PORT, gd->baudrate);
96}
97
98#else /* ! CONFIG_MPSC */
99
100int serial_init (void)
101{
102 DECLARE_GLOBAL_DATA_PTR;
103
104 int clock_divisor = CFG_NS16550_CLK / 16 / gd->baudrate;
105
106#ifdef CFG_INIT_CHAN1
107 (void)NS16550_init(COM_PORTS[0], clock_divisor);
108#endif
109#ifdef CFG_INIT_CHAN2
110 (void)NS16550_init(COM_PORTS[1], clock_divisor);
111#endif
112
113 return (0);
114}
115
116void
117serial_putc(const char c)
118{
119 if (c == '\n')
120 NS16550_putc(COM_PORTS[CFG_DUART_CHAN], '\r');
121
122 NS16550_putc(COM_PORTS[CFG_DUART_CHAN], c);
123}
124
125int
126serial_getc(void)
127{
128 return NS16550_getc(COM_PORTS[CFG_DUART_CHAN]);
129}
130
131int
132serial_tstc(void)
133{
134 return NS16550_tstc(COM_PORTS[CFG_DUART_CHAN]);
135}
136
137void
138serial_setbrg (void)
139{
140 DECLARE_GLOBAL_DATA_PTR;
141
142 int clock_divisor = CFG_NS16550_CLK / 16 / gd->baudrate;
143
144#ifdef CFG_INIT_CHAN1
145 NS16550_reinit(COM_PORTS[0], clock_divisor);
146#endif
147#ifdef CFG_INIT_CHAN2
148 NS16550_reinit(COM_PORTS[1], clock_divisor);
149#endif
150}
151
152#endif /* CONFIG_MPSC */
153
154void
155serial_puts (const char *s)
156{
157 while (*s) {
158 serial_putc (*s++);
159 }
160}
161
162#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
163void
164kgdb_serial_init(void)
165{
166}
167
168void
169putDebugChar (int c)
170{
171 serial_putc (c);
172}
173
174void
175putDebugStr (const char *str)
176{
177 serial_puts (str);
178}
179
180int
181getDebugChar (void)
182{
183 return serial_getc();
184}
185
186void
187kgdb_interruptible (int yes)
188{
189 return;
190}
191#endif /* CFG_CMD_KGDB */