]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/evb64260/serial.c
cf46a4d1270a93fda4547143cb50fa99b0ae8ed3
[karo-tx-uboot.git] / board / evb64260 / serial.c
1 /*
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 #include <serial.h>
34 #include <linux/compiler.h>
35
36 #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
37 #include <ns16550.h>
38 #endif
39
40 #include "serial.h"
41
42 #include "mpsc.h"
43
44 DECLARE_GLOBAL_DATA_PTR;
45
46 #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
47 const NS16550_t COM_PORTS[] = { (NS16550_t) CONFIG_SYS_NS16550_COM1,
48                                 (NS16550_t) CONFIG_SYS_NS16550_COM2 };
49 #endif
50
51 #ifdef CONFIG_MPSC
52
53 static int evb64260_serial_init(void)
54 {
55 #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
56         int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
57 #endif
58
59         mpsc_init(gd->baudrate);
60
61         /* init the DUART chans so that KGDB in the kernel can use them */
62 #ifdef CONFIG_SYS_INIT_CHAN1
63         NS16550_reinit(COM_PORTS[0], clock_divisor);
64 #endif
65 #ifdef CONFIG_SYS_INIT_CHAN2
66         NS16550_reinit(COM_PORTS[1], clock_divisor);
67 #endif
68         return (0);
69 }
70
71 static void evb64260_serial_putc(const char c)
72 {
73         if (c == '\n')
74                 mpsc_putchar('\r');
75
76         mpsc_putchar(c);
77 }
78
79 static int evb64260_serial_getc(void)
80 {
81         return mpsc_getchar();
82 }
83
84 static int evb64260_serial_tstc(void)
85 {
86         return mpsc_test_char();
87 }
88
89 static void evb64260_serial_setbrg(void)
90 {
91         galbrg_set_baudrate(CONFIG_MPSC_PORT, gd->baudrate);
92 }
93
94 #else /* ! CONFIG_MPSC */
95
96 static int evb64260_serial_init(void)
97 {
98         int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
99
100 #ifdef CONFIG_SYS_INIT_CHAN1
101         (void)NS16550_init(COM_PORTS[0], clock_divisor);
102 #endif
103 #ifdef CONFIG_SYS_INIT_CHAN2
104         (void)NS16550_init(COM_PORTS[1], clock_divisor);
105 #endif
106
107         return (0);
108 }
109
110 static void evb64260_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 evb64260_serial_getc(void)
119 {
120         return NS16550_getc(COM_PORTS[CONFIG_SYS_DUART_CHAN]);
121 }
122
123 static int evb64260_serial_tstc(void)
124 {
125         return NS16550_tstc(COM_PORTS[CONFIG_SYS_DUART_CHAN]);
126 }
127
128 static void evb64260_serial_setbrg(void)
129 {
130         int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / 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 evb64260_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 evb64260_serial_drv = {
151         .name   = "evb64260_serial",
152         .start  = evb64260_serial_init,
153         .stop   = NULL,
154         .setbrg = evb64260_serial_setbrg,
155         .putc   = evb64260_serial_putc,
156         .puts   = evb64260_serial_puts,
157         .getc   = evb64260_serial_getc,
158         .tstc   = evb64260_serial_tstc,
159 };
160
161 void evb64260_serial_initialize(void)
162 {
163         serial_register(&evb64260_serial_drv);
164 }
165
166 __weak struct serial_device *default_serial_console(void)
167 {
168         return &evb64260_serial_drv;
169 }
170 #else
171 int serial_init(void)
172 {
173         return evb64260_serial_init();
174 }
175
176 void serial_setbrg(void)
177 {
178         evb64260_serial_setbrg();
179 }
180
181 void serial_putc(const char c)
182 {
183         evb64260_serial_putc(c);
184 }
185
186 void serial_puts(const char *s)
187 {
188         evb64260_serial_puts(s);
189 }
190
191 int serial_getc(void)
192 {
193         return evb64260_serial_getc();
194 }
195
196 int serial_tstc(void)
197 {
198         return evb64260_serial_tstc();
199 }
200 #endif
201 #if defined(CONFIG_CMD_KGDB)
202 void
203 kgdb_serial_init(void)
204 {
205 }
206
207 void
208 putDebugChar (int c)
209 {
210         serial_putc (c);
211 }
212
213 void
214 putDebugStr (const char *str)
215 {
216         serial_puts (str);
217 }
218
219 int
220 getDebugChar (void)
221 {
222         return serial_getc();
223 }
224
225 void
226 kgdb_interruptible (int yes)
227 {
228         return;
229 }
230 #endif