]> git.sur5r.net Git - u-boot/blob - board/evb64260/serial.c
powerpc/83xx/km: make local functions and structs static
[u-boot] / 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 struct serial_device evb64260_serial_drv = {
143         .name   = "evb64260_serial",
144         .start  = evb64260_serial_init,
145         .stop   = NULL,
146         .setbrg = evb64260_serial_setbrg,
147         .putc   = evb64260_serial_putc,
148         .puts   = default_serial_puts,
149         .getc   = evb64260_serial_getc,
150         .tstc   = evb64260_serial_tstc,
151 };
152
153 void evb64260_serial_initialize(void)
154 {
155         serial_register(&evb64260_serial_drv);
156 }
157
158 __weak struct serial_device *default_serial_console(void)
159 {
160         return &evb64260_serial_drv;
161 }
162
163 #if defined(CONFIG_CMD_KGDB)
164 void
165 kgdb_serial_init(void)
166 {
167 }
168
169 void
170 putDebugChar (int c)
171 {
172         serial_putc (c);
173 }
174
175 void
176 putDebugStr (const char *str)
177 {
178         serial_puts (str);
179 }
180
181 int
182 getDebugChar (void)
183 {
184         return serial_getc();
185 }
186
187 void
188 kgdb_interruptible (int yes)
189 {
190         return;
191 }
192 #endif