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