blob: 9d711151f0cf455030b0b893fa9b477bcb8a1a10 [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
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020034#if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
wdenkc6097192002-11-03 00:24:07 +000035#include <ns16550.h>
36#endif
37
38#include "serial.h"
39
40#include "mpsc.h"
41
Wolfgang Denk6405a152006-03-31 18:32:53 +020042DECLARE_GLOBAL_DATA_PTR;
43
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020044#if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
45const NS16550_t COM_PORTS[] = { (NS16550_t) CONFIG_SYS_NS16550_COM1,
46 (NS16550_t) CONFIG_SYS_NS16550_COM2 };
wdenkc6097192002-11-03 00:24:07 +000047#endif
48
49#ifdef CONFIG_MPSC
50
51int serial_init (void)
52{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020053#if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
54 int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
wdenkc6097192002-11-03 00:24:07 +000055#endif
56
57 mpsc_init(gd->baudrate);
58
59 /* init the DUART chans so that KGDB in the kernel can use them */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020060#ifdef CONFIG_SYS_INIT_CHAN1
wdenkc6097192002-11-03 00:24:07 +000061 NS16550_reinit(COM_PORTS[0], clock_divisor);
62#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020063#ifdef CONFIG_SYS_INIT_CHAN2
wdenkc6097192002-11-03 00:24:07 +000064 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{
wdenkc6097192002-11-03 00:24:07 +000093 galbrg_set_baudrate(CONFIG_MPSC_PORT, gd->baudrate);
94}
95
96#else /* ! CONFIG_MPSC */
97
98int serial_init (void)
99{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200100 int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
wdenkc6097192002-11-03 00:24:07 +0000101
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200102#ifdef CONFIG_SYS_INIT_CHAN1
wdenkc6097192002-11-03 00:24:07 +0000103 (void)NS16550_init(COM_PORTS[0], clock_divisor);
104#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200105#ifdef CONFIG_SYS_INIT_CHAN2
wdenkc6097192002-11-03 00:24:07 +0000106 (void)NS16550_init(COM_PORTS[1], clock_divisor);
107#endif
108
109 return (0);
110}
111
112void
113serial_putc(const char c)
114{
115 if (c == '\n')
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200116 NS16550_putc(COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r');
wdenkc6097192002-11-03 00:24:07 +0000117
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200118 NS16550_putc(COM_PORTS[CONFIG_SYS_DUART_CHAN], c);
wdenkc6097192002-11-03 00:24:07 +0000119}
120
121int
122serial_getc(void)
123{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200124 return NS16550_getc(COM_PORTS[CONFIG_SYS_DUART_CHAN]);
wdenkc6097192002-11-03 00:24:07 +0000125}
126
127int
128serial_tstc(void)
129{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200130 return NS16550_tstc(COM_PORTS[CONFIG_SYS_DUART_CHAN]);
wdenkc6097192002-11-03 00:24:07 +0000131}
132
133void
134serial_setbrg (void)
135{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200136 int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
wdenkc6097192002-11-03 00:24:07 +0000137
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200138#ifdef CONFIG_SYS_INIT_CHAN1
wdenkc6097192002-11-03 00:24:07 +0000139 NS16550_reinit(COM_PORTS[0], clock_divisor);
140#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200141#ifdef CONFIG_SYS_INIT_CHAN2
wdenkc6097192002-11-03 00:24:07 +0000142 NS16550_reinit(COM_PORTS[1], clock_divisor);
143#endif
144}
145
146#endif /* CONFIG_MPSC */
147
148void
149serial_puts (const char *s)
150{
151 while (*s) {
152 serial_putc (*s++);
153 }
154}
155
Jon Loeliger4ed9ed62007-07-09 18:24:55 -0500156#if defined(CONFIG_CMD_KGDB)
wdenkc6097192002-11-03 00:24:07 +0000157void
158kgdb_serial_init(void)
159{
160}
161
162void
163putDebugChar (int c)
164{
165 serial_putc (c);
166}
167
168void
169putDebugStr (const char *str)
170{
171 serial_puts (str);
172}
173
174int
175getDebugChar (void)
176{
177 return serial_getc();
178}
179
180void
181kgdb_interruptible (int yes)
182{
183 return;
184}
Jon Loeliger13f75992007-07-10 10:39:10 -0500185#endif