cons.c revision 1.7 1 /* $NetBSD: cons.c,v 1.7 2008/03/16 10:10:43 tsutsui Exp $ */
2
3 /*
4 * Copyright (c) 1990, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * the Systems Programming Group of the University of Utah Computer
9 * Science Department.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * from: Utah Hdr: cons.c 1.7 92/02/28
36 *
37 * @(#)cons.c 8.1 (Berkeley) 6/10/93
38 */
39 /*
40 * Copyright (c) 1988 University of Utah.
41 *
42 * This code is derived from software contributed to Berkeley by
43 * the Systems Programming Group of the University of Utah Computer
44 * Science Department.
45 *
46 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
48 * are met:
49 * 1. Redistributions of source code must retain the above copyright
50 * notice, this list of conditions and the following disclaimer.
51 * 2. Redistributions in binary form must reproduce the above copyright
52 * notice, this list of conditions and the following disclaimer in the
53 * documentation and/or other materials provided with the distribution.
54 * 3. All advertising materials mentioning features or use of this software
55 * must display the following acknowledgement:
56 * This product includes software developed by the University of
57 * California, Berkeley and its contributors.
58 * 4. Neither the name of the University nor the names of its contributors
59 * may be used to endorse or promote products derived from this software
60 * without specific prior written permission.
61 *
62 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
63 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
64 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
65 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
66 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
67 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
68 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
69 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
70 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
71 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72 * SUCH DAMAGE.
73 *
74 * from: Utah Hdr: cons.c 1.7 92/02/28
75 *
76 * @(#)cons.c 8.1 (Berkeley) 6/10/93
77 */
78
79 #include <lib/libsa/stand.h>
80
81 #include "boot.h"
82 #include "cons.h"
83
84 #ifdef CONS_SERIAL
85 void siocnprobe(struct consdev *);
86 void siocninit(struct consdev *);
87 void siocnputchar(void *, int);
88 int siocngetchar(void *);
89 int siocnscan(void *);
90 # include "ns16550.h"
91 # ifndef COMPORT
92 # define COMPORT COM1
93 # endif
94 # ifndef COMSPEED
95 # define COMSPEED 9600
96 # endif
97 #endif
98
99 #ifdef CONS_ZS
100 void zscnprobe(struct consdev *);
101 void zscninit(struct consdev *);
102 void zscnputchar(void *, int);
103 int zscngetchar(void *);
104 int zscnscan(void *);
105 #include "zs.h"
106 #ifndef ZSCHAN
107 #define ZSCHAN ZS_CHAN_A
108 #endif
109 #ifndef ZSSPEED
110 #define ZSSPEED 115200
111 #endif
112 #endif
113
114 struct consdev constab[] = {
115 #ifdef CONS_SERIAL
116 { "com", COMPORT, COMSPEED,
117 siocnprobe, siocninit, siocngetchar, siocnputchar, siocnscan },
118 #endif
119 #ifdef CONS_ZS
120 { "zs", ZSCHAN, ZSSPEED,
121 zscnprobe, zscninit, zscngetchar, zscnputchar, zscnscan },
122 #endif
123 { 0 }
124 };
125
126 struct consdev *cn_tab;
127
128 char *
129 cninit(int *addr, int *speed)
130 {
131 register struct consdev *cp;
132
133 cn_tab = NULL;
134 for (cp = constab; cp->cn_probe; cp++) {
135 (*cp->cn_probe)(cp);
136 if (cp->cn_pri > CN_DEAD &&
137 (cn_tab == NULL || cp->cn_pri > cn_tab->cn_pri))
138 cn_tab = cp;
139 }
140 if (cn_tab) {
141 (*cn_tab->cn_init)(cn_tab);
142 *addr = cn_tab->address;
143 *speed = cn_tab->speed;
144 return cn_tab->cn_name;
145 }
146
147 return NULL;
148 }
149
150 int
151 cngetc(void)
152 {
153
154 if (cn_tab)
155 return (*cn_tab->cn_getc)(cn_tab->cn_dev);
156 return 0;
157 }
158
159 void
160 cnputc(int c)
161 {
162
163 if (cn_tab)
164 (*cn_tab->cn_putc)(cn_tab->cn_dev, c);
165 }
166
167 int
168 cnscan(void)
169 {
170
171 if (cn_tab)
172 return (*cn_tab->cn_scan)(cn_tab->cn_dev);
173 return -1;
174 }
175
176 #ifdef CONS_FB
177 /*
178 * frame buffer console
179 */
180 void
181 fbcnprobe(struct consdev *cp)
182 {
183
184 cp->cn_pri = CN_INTERNAL;
185 }
186
187 void
188 fbcninit(struct consdev *cp)
189 {
190
191 video_init((uint8_t *)cp->address);
192 kbdreset();
193 }
194
195 int
196 fbcngetchar(void *dev)
197 {
198
199 return kbd_getc();
200 }
201
202 void
203 fbcnputchar(void *dev, int c)
204 {
205
206 video_putc(c);
207 }
208
209 int
210 fbcnscan(void *dev)
211 {
212
213 return kbd(1);
214 }
215 #endif /* CONS_FB */
216
217 #ifdef CONS_VGA
218 /*
219 * VGA console
220 */
221 void
222 vgacnprobe(struct consdev *cp)
223 {
224
225 cp->cn_pri = CN_NORMAL;
226 }
227
228 void
229 vgacninit(struct consdev *cp)
230 {
231
232 vga_reset((uint8_t *)cp->address);
233 vga_init((uint8_t *)cp->address);
234 kbdreset();
235 }
236
237 int
238 vgacngetchar(void *dev)
239 {
240
241 return kbd_getc();
242 }
243
244 void
245 vgacnputchar(void *dev, int c)
246 {
247
248 vga_putc(c);
249 }
250
251 int
252 vgacnscan(void *dev)
253 {
254
255 return kbd(1);
256 }
257 #endif /* CONS_VGA */
258
259 #ifdef CONS_SERIAL
260 /*
261 * serial console
262 */
263 void
264 siocnprobe(struct consdev *cp)
265 {
266
267 if (*((uint32_t *)COMPROBE) != 0 &&
268 cobalt_id != COBALT_ID_QUBE2700)
269 cp->cn_pri = CN_REMOTE;
270 }
271
272 void
273 siocninit(struct consdev *cp)
274 {
275
276 cp->cn_dev = (void *)NS16550_init(cp->address, cp->speed);
277 }
278
279 int
280 siocngetchar(void *dev)
281 {
282
283 return NS16550_getc((struct NS16550 *)dev);
284 }
285
286 void
287 siocnputchar(void *dev, int c)
288 {
289
290 if (c == '\n')
291 NS16550_putc((struct NS16550 *)dev, '\r');
292 NS16550_putc((struct NS16550 *)dev, c);
293 }
294
295 int
296 siocnscan(void *dev)
297 {
298
299 return NS16550_scankbd((struct NS16550 *)dev);
300 }
301 #endif /* CONS_SERIAL */
302
303 #ifdef CONS_ZS
304 /*
305 * optional z85c30 serial console on Qube2700
306 */
307 void
308 zscnprobe(struct consdev *cp)
309 {
310
311 if (*((uint32_t *)ZSPROBE) != 0 &&
312 cobalt_id == COBALT_ID_QUBE2700)
313 cp->cn_pri = CN_REMOTE;
314 }
315
316 void
317 zscninit(struct consdev *cp)
318 {
319
320 cp->cn_dev = zs_init(cp->address, cp->speed);
321 }
322
323 int
324 zscngetchar(void *dev)
325 {
326
327 return zs_getc(dev);
328 }
329
330 void
331 zscnputchar(void *dev, int c)
332 {
333
334 if (c == '\n')
335 zs_putc(dev, '\r');
336 zs_putc(dev, c);
337 }
338
339 int
340 zscnscan(void *dev)
341 {
342
343 return zs_scan(dev);
344 }
345 #endif /* CONS_ZS */
346