]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/Marvell/common/serial.c
a5231eb434e7429f9cb99c6170146b6261d23ded
[karo-tx-uboot.git] / board / Marvell / common / serial.c
1 /*
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 <serial.h>
36 #include <linux/compiler.h>
37
38 #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
51 DECLARE_GLOBAL_DATA_PTR;
52
53 #ifdef CONFIG_MPSC
54 static int marvell_serial_init(void)
55 {
56 #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
57         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 */
63 #ifdef CONFIG_SYS_INIT_CHAN1
64         NS16550_reinit (COM_PORTS[0], clock_divisor);
65 #endif
66 #ifdef CONFIG_SYS_INIT_CHAN2
67         NS16550_reinit (COM_PORTS[1], clock_divisor);
68 #endif
69         return (0);
70 }
71
72 static void marvell_serial_putc(const char c)
73 {
74         if (c == '\n')
75                 mpsc_putchar ('\r');
76
77         mpsc_putchar (c);
78 }
79
80 static int marvell_serial_getc(void)
81 {
82         return mpsc_getchar ();
83 }
84
85 static int marvell_serial_tstc(void)
86 {
87         return mpsc_test_char ();
88 }
89
90 static void marvell_serial_setbrg(void)
91 {
92         galbrg_set_baudrate (CONFIG_MPSC_PORT, gd->baudrate);
93 }
94
95 #else  /* ! CONFIG_MPSC */
96
97 static int marvell_serial_init(void)
98 {
99         int clock_divisor = 230400 / gd->baudrate;
100
101 #ifdef CONFIG_SYS_INIT_CHAN1
102         (void) NS16550_init (0, clock_divisor);
103 #endif
104 #ifdef CONFIG_SYS_INIT_CHAN2
105         (void) NS16550_init (1, clock_divisor);
106 #endif
107         return (0);
108 }
109
110 static void marvell_serial_putc(const char c)
111 {
112         if (c == '\n')
113                 NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r');
114
115         NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], c);
116 }
117
118 static int marvell_serial_getc(void)
119 {
120         return NS16550_getc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
121 }
122
123 static int marvell_serial_tstc(void)
124 {
125         return NS16550_tstc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
126 }
127
128 static void marvell_serial_setbrg(void)
129 {
130         int clock_divisor = 230400 / gd->baudrate;
131
132 #ifdef CONFIG_SYS_INIT_CHAN1
133         NS16550_reinit (COM_PORTS[0], clock_divisor);
134 #endif
135 #ifdef CONFIG_SYS_INIT_CHAN2
136         NS16550_reinit (COM_PORTS[1], clock_divisor);
137 #endif
138 }
139
140 #endif /* CONFIG_MPSC */
141
142 static void marvell_serial_puts(const char *s)
143 {
144         while (*s) {
145                 serial_putc (*s++);
146         }
147 }
148
149 #ifdef CONFIG_SERIAL_MULTI
150 static struct serial_device marvell_serial_drv = {
151         .name   = "marvell_serial",
152         .start  = marvell_serial_init,
153         .stop   = NULL,
154         .setbrg = marvell_serial_setbrg,
155         .putc   = marvell_serial_putc,
156         .puts   = marvell_serial_puts,
157         .getc   = marvell_serial_getc,
158         .tstc   = marvell_serial_tstc,
159 };
160
161 void marvell_serial_initialize(void)
162 {
163         serial_register(&marvell_serial_drv);
164 }
165
166 __weak struct serial_device *default_serial_console(void)
167 {
168         return &marvell_serial_drv;
169 }
170 #else
171 int serial_init(void)
172 {
173         return marvell_serial_init();
174 }
175
176 void serial_setbrg(void)
177 {
178         marvell_serial_setbrg();
179 }
180
181 void serial_putc(const char c)
182 {
183         marvell_serial_putc(c);
184 }
185
186 void serial_puts(const char *s)
187 {
188         marvell_serial_puts(s);
189 }
190
191 int serial_getc(void)
192 {
193         return marvell_serial_getc();
194 }
195
196 int serial_tstc(void)
197 {
198         return marvell_serial_tstc();
199 }
200 #endif
201
202 #if defined(CONFIG_CMD_KGDB)
203 void kgdb_serial_init (void)
204 {
205 }
206
207 void putDebugChar (int c)
208 {
209         serial_putc (c);
210 }
211
212 void putDebugStr (const char *str)
213 {
214         serial_puts (str);
215 }
216
217 int getDebugChar (void)
218 {
219         return serial_getc ();
220 }
221
222 void kgdb_interruptible (int yes)
223 {
224         return;
225 }
226 #endif