blob: 9fd429864a7c9e027806ea0bb9382167b43b3bf3 [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>
Marek Vasut829b3b22012-09-13 12:33:50 +020033#include <serial.h>
34#include <linux/compiler.h>
wdenkc6097192002-11-03 00:24:07 +000035
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020036#if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
wdenkc6097192002-11-03 00:24:07 +000037#include <ns16550.h>
38#endif
39
40#include "serial.h"
41
42#include "mpsc.h"
43
Wolfgang Denkd87080b2006-03-31 18:32:53 +020044DECLARE_GLOBAL_DATA_PTR;
45
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020046#if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
47const NS16550_t COM_PORTS[] = { (NS16550_t) CONFIG_SYS_NS16550_COM1,
48 (NS16550_t) CONFIG_SYS_NS16550_COM2 };
wdenkc6097192002-11-03 00:24:07 +000049#endif
50
51#ifdef CONFIG_MPSC
52
Marek Vasut829b3b22012-09-13 12:33:50 +020053static int evb64260_serial_init(void)
wdenkc6097192002-11-03 00:24:07 +000054{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020055#if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
56 int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
wdenkc6097192002-11-03 00:24:07 +000057#endif
58
59 mpsc_init(gd->baudrate);
60
61 /* init the DUART chans so that KGDB in the kernel can use them */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020062#ifdef CONFIG_SYS_INIT_CHAN1
wdenkc6097192002-11-03 00:24:07 +000063 NS16550_reinit(COM_PORTS[0], clock_divisor);
64#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020065#ifdef CONFIG_SYS_INIT_CHAN2
wdenkc6097192002-11-03 00:24:07 +000066 NS16550_reinit(COM_PORTS[1], clock_divisor);
67#endif
68 return (0);
69}
70
Marek Vasut829b3b22012-09-13 12:33:50 +020071static void evb64260_serial_putc(const char c)
wdenkc6097192002-11-03 00:24:07 +000072{
73 if (c == '\n')
74 mpsc_putchar('\r');
75
76 mpsc_putchar(c);
77}
78
Marek Vasut829b3b22012-09-13 12:33:50 +020079static int evb64260_serial_getc(void)
wdenkc6097192002-11-03 00:24:07 +000080{
81 return mpsc_getchar();
82}
83
Marek Vasut829b3b22012-09-13 12:33:50 +020084static int evb64260_serial_tstc(void)
wdenkc6097192002-11-03 00:24:07 +000085{
86 return mpsc_test_char();
87}
88
Marek Vasut829b3b22012-09-13 12:33:50 +020089static void evb64260_serial_setbrg(void)
wdenkc6097192002-11-03 00:24:07 +000090{
wdenkc6097192002-11-03 00:24:07 +000091 galbrg_set_baudrate(CONFIG_MPSC_PORT, gd->baudrate);
92}
93
94#else /* ! CONFIG_MPSC */
95
Marek Vasut829b3b22012-09-13 12:33:50 +020096static int evb64260_serial_init(void)
wdenkc6097192002-11-03 00:24:07 +000097{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020098 int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
wdenkc6097192002-11-03 00:24:07 +000099
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200100#ifdef CONFIG_SYS_INIT_CHAN1
wdenkc6097192002-11-03 00:24:07 +0000101 (void)NS16550_init(COM_PORTS[0], clock_divisor);
102#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200103#ifdef CONFIG_SYS_INIT_CHAN2
wdenkc6097192002-11-03 00:24:07 +0000104 (void)NS16550_init(COM_PORTS[1], clock_divisor);
105#endif
106
107 return (0);
108}
109
Marek Vasut829b3b22012-09-13 12:33:50 +0200110static void evb64260_serial_putc(const char c)
wdenkc6097192002-11-03 00:24:07 +0000111{
112 if (c == '\n')
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200113 NS16550_putc(COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r');
wdenkc6097192002-11-03 00:24:07 +0000114
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200115 NS16550_putc(COM_PORTS[CONFIG_SYS_DUART_CHAN], c);
wdenkc6097192002-11-03 00:24:07 +0000116}
117
Marek Vasut829b3b22012-09-13 12:33:50 +0200118static int evb64260_serial_getc(void)
wdenkc6097192002-11-03 00:24:07 +0000119{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200120 return NS16550_getc(COM_PORTS[CONFIG_SYS_DUART_CHAN]);
wdenkc6097192002-11-03 00:24:07 +0000121}
122
Marek Vasut829b3b22012-09-13 12:33:50 +0200123static int evb64260_serial_tstc(void)
wdenkc6097192002-11-03 00:24:07 +0000124{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200125 return NS16550_tstc(COM_PORTS[CONFIG_SYS_DUART_CHAN]);
wdenkc6097192002-11-03 00:24:07 +0000126}
127
Marek Vasut829b3b22012-09-13 12:33:50 +0200128static void evb64260_serial_setbrg(void)
wdenkc6097192002-11-03 00:24:07 +0000129{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200130 int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
wdenkc6097192002-11-03 00:24:07 +0000131
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200132#ifdef CONFIG_SYS_INIT_CHAN1
wdenkc6097192002-11-03 00:24:07 +0000133 NS16550_reinit(COM_PORTS[0], clock_divisor);
134#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200135#ifdef CONFIG_SYS_INIT_CHAN2
wdenkc6097192002-11-03 00:24:07 +0000136 NS16550_reinit(COM_PORTS[1], clock_divisor);
137#endif
138}
139
140#endif /* CONFIG_MPSC */
141
Marek Vasut829b3b22012-09-13 12:33:50 +0200142static void evb64260_serial_puts(const char *s)
wdenkc6097192002-11-03 00:24:07 +0000143{
144 while (*s) {
145 serial_putc (*s++);
146 }
147}
148
Marek Vasut829b3b22012-09-13 12:33:50 +0200149static struct serial_device evb64260_serial_drv = {
150 .name = "evb64260_serial",
151 .start = evb64260_serial_init,
152 .stop = NULL,
153 .setbrg = evb64260_serial_setbrg,
154 .putc = evb64260_serial_putc,
155 .puts = evb64260_serial_puts,
156 .getc = evb64260_serial_getc,
157 .tstc = evb64260_serial_tstc,
158};
159
160void evb64260_serial_initialize(void)
161{
162 serial_register(&evb64260_serial_drv);
163}
164
165__weak struct serial_device *default_serial_console(void)
166{
167 return &evb64260_serial_drv;
168}
Marek Vasut829b3b22012-09-13 12:33:50 +0200169
Jon Loeligerb9307262007-07-09 18:24:55 -0500170#if defined(CONFIG_CMD_KGDB)
wdenkc6097192002-11-03 00:24:07 +0000171void
172kgdb_serial_init(void)
173{
174}
175
176void
177putDebugChar (int c)
178{
179 serial_putc (c);
180}
181
182void
183putDebugStr (const char *str)
184{
185 serial_puts (str);
186}
187
188int
189getDebugChar (void)
190{
191 return serial_getc();
192}
193
194void
195kgdb_interruptible (int yes)
196{
197 return;
198}
Jon Loeliger77a31852007-07-10 10:39:10 -0500199#endif