blob: 1327c62a75af7fa23c1c65ad6e601fd4c53ccceb [file] [log] [blame]
wdenk3a473b22004-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>
Marek Vasutafe4c382012-09-13 12:26:39 +020035#include <serial.h>
36#include <linux/compiler.h>
37
wdenk3a473b22004-01-03 00:43:19 +000038#include "../include/memory.h"
39#include "serial.h"
40
41#ifdef CONFIG_DB64360
42#include "../db64360/mpsc.h"
43#endif
44
45#ifdef CONFIG_DB64460
46#include "../db64460/mpsc.h"
47#endif
48
49#include "ns16550.h"
50
Wolfgang Denkd87080b2006-03-31 18:32:53 +020051DECLARE_GLOBAL_DATA_PTR;
52
wdenk3a473b22004-01-03 00:43:19 +000053#ifdef CONFIG_MPSC
Marek Vasutafe4c382012-09-13 12:26:39 +020054static int marvell_serial_init(void)
wdenk3a473b22004-01-03 00:43:19 +000055{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020056#if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
wdenk3a473b22004-01-03 00:43:19 +000057 int clock_divisor = 230400 / gd->baudrate;
58#endif
59
60 mpsc_init (gd->baudrate);
61
62 /* init the DUART chans so that KGDB in the kernel can use them */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020063#ifdef CONFIG_SYS_INIT_CHAN1
wdenk3a473b22004-01-03 00:43:19 +000064 NS16550_reinit (COM_PORTS[0], clock_divisor);
65#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020066#ifdef CONFIG_SYS_INIT_CHAN2
wdenk3a473b22004-01-03 00:43:19 +000067 NS16550_reinit (COM_PORTS[1], clock_divisor);
68#endif
69 return (0);
70}
71
Marek Vasutafe4c382012-09-13 12:26:39 +020072static void marvell_serial_putc(const char c)
wdenk3a473b22004-01-03 00:43:19 +000073{
74 if (c == '\n')
75 mpsc_putchar ('\r');
76
77 mpsc_putchar (c);
78}
79
Marek Vasutafe4c382012-09-13 12:26:39 +020080static int marvell_serial_getc(void)
wdenk3a473b22004-01-03 00:43:19 +000081{
82 return mpsc_getchar ();
83}
84
Marek Vasutafe4c382012-09-13 12:26:39 +020085static int marvell_serial_tstc(void)
wdenk3a473b22004-01-03 00:43:19 +000086{
87 return mpsc_test_char ();
88}
89
Marek Vasutafe4c382012-09-13 12:26:39 +020090static void marvell_serial_setbrg(void)
wdenk3a473b22004-01-03 00:43:19 +000091{
wdenk3a473b22004-01-03 00:43:19 +000092 galbrg_set_baudrate (CONFIG_MPSC_PORT, gd->baudrate);
93}
94
95#else /* ! CONFIG_MPSC */
96
Marek Vasutafe4c382012-09-13 12:26:39 +020097static int marvell_serial_init(void)
wdenk3a473b22004-01-03 00:43:19 +000098{
wdenk3a473b22004-01-03 00:43:19 +000099 int clock_divisor = 230400 / gd->baudrate;
100
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200101#ifdef CONFIG_SYS_INIT_CHAN1
wdenk3a473b22004-01-03 00:43:19 +0000102 (void) NS16550_init (0, clock_divisor);
103#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200104#ifdef CONFIG_SYS_INIT_CHAN2
wdenk3a473b22004-01-03 00:43:19 +0000105 (void) NS16550_init (1, clock_divisor);
106#endif
107 return (0);
108}
109
Marek Vasutafe4c382012-09-13 12:26:39 +0200110static void marvell_serial_putc(const char c)
wdenk3a473b22004-01-03 00:43:19 +0000111{
112 if (c == '\n')
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200113 NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r');
wdenk3a473b22004-01-03 00:43:19 +0000114
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200115 NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], c);
wdenk3a473b22004-01-03 00:43:19 +0000116}
117
Marek Vasutafe4c382012-09-13 12:26:39 +0200118static int marvell_serial_getc(void)
wdenk3a473b22004-01-03 00:43:19 +0000119{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200120 return NS16550_getc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
wdenk3a473b22004-01-03 00:43:19 +0000121}
122
Marek Vasutafe4c382012-09-13 12:26:39 +0200123static int marvell_serial_tstc(void)
wdenk3a473b22004-01-03 00:43:19 +0000124{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200125 return NS16550_tstc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
wdenk3a473b22004-01-03 00:43:19 +0000126}
127
Marek Vasutafe4c382012-09-13 12:26:39 +0200128static void marvell_serial_setbrg(void)
wdenk3a473b22004-01-03 00:43:19 +0000129{
wdenk3a473b22004-01-03 00:43:19 +0000130 int clock_divisor = 230400 / gd->baudrate;
131
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200132#ifdef CONFIG_SYS_INIT_CHAN1
wdenk3a473b22004-01-03 00:43:19 +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
wdenk3a473b22004-01-03 00:43:19 +0000136 NS16550_reinit (COM_PORTS[1], clock_divisor);
137#endif
138}
139
140#endif /* CONFIG_MPSC */
141
Marek Vasutafe4c382012-09-13 12:26:39 +0200142static void marvell_serial_puts(const char *s)
wdenk3a473b22004-01-03 00:43:19 +0000143{
144 while (*s) {
145 serial_putc (*s++);
146 }
147}
148
Marek Vasutafe4c382012-09-13 12:26:39 +0200149static struct serial_device marvell_serial_drv = {
150 .name = "marvell_serial",
151 .start = marvell_serial_init,
152 .stop = NULL,
153 .setbrg = marvell_serial_setbrg,
154 .putc = marvell_serial_putc,
155 .puts = marvell_serial_puts,
156 .getc = marvell_serial_getc,
157 .tstc = marvell_serial_tstc,
158};
159
160void marvell_serial_initialize(void)
161{
162 serial_register(&marvell_serial_drv);
163}
164
165__weak struct serial_device *default_serial_console(void)
166{
167 return &marvell_serial_drv;
168}
Marek Vasutafe4c382012-09-13 12:26:39 +0200169
Jon Loeligerfcec2eb2007-07-09 18:19:09 -0500170#if defined(CONFIG_CMD_KGDB)
wdenk3a473b22004-01-03 00:43:19 +0000171void kgdb_serial_init (void)
172{
173}
174
175void putDebugChar (int c)
176{
177 serial_putc (c);
178}
179
180void putDebugStr (const char *str)
181{
182 serial_puts (str);
183}
184
185int getDebugChar (void)
186{
187 return serial_getc ();
188}
189
190void kgdb_interruptible (int yes)
191{
192 return;
193}
Jon Loeliger77a31852007-07-10 10:39:10 -0500194#endif