xref: /netbsd-src/sys/arch/mmeye/stand/boot/cons.c (revision 8e33eff89e26cf71871ead62f0d5063e1313c33a)
1 /*	$NetBSD: cons.c,v 1.1 2011/03/03 05:59:37 kiyohara 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 <machine/cpu.h>
82 
83 #include "boot.h"
84 #include "cons.h"
85 
86 #ifdef CONS_SCIF
87 static void scifcnprobe(struct consdev *);
88 static void scifcninit(struct consdev *);
89 static void scifcnputchar(void *, int);
90 static int scifcngetchar(void *);
91 static int scifcnscan(void *);
92 # include "scif.h"
93 # ifndef SCIFSPEED
94 #  define SCIFSPEED 19200
95 # endif
96 #endif
97 
98 #ifdef CONS_COM
99 static void comcnprobe(struct consdev *);
100 static void comcninit(struct consdev *);
101 static void comcnputchar(void *, int);
102 static int comcngetchar(void *);
103 static int comcnscan(void *);
104 # include "ns16550.h"
105 # ifndef COMPORT
106 #  define COMPORT 0xa4000000
107 # endif
108 # ifndef COMSPEED
109 #  define COMSPEED 19200
110 # endif
111 #endif
112 
113 static struct consdev constab[] = {
114 #ifdef CONS_SCIF
115 	{ "scif", 0, SCIFSPEED,
116 	    scifcnprobe, scifcninit, scifcngetchar, scifcnputchar, scifcnscan },
117 #endif
118 #ifdef CONS_COM
119 	{ "com", 0, COMSPEED,
120 	    comcnprobe, comcninit, comcngetchar, comcnputchar, comcnscan },
121 #endif
122 	{ 0 }
123 };
124 
125 static struct consdev *cn_tab;
126 
127 char *
128 cninit()
129 {
130 	register struct consdev *cp;
131 
132 	cn_tab = NULL;
133 	for (cp = constab; cp->cn_probe; cp++) {
134 		(*cp->cn_probe)(cp);
135 		if (cp->cn_pri > CN_DEAD &&
136 		    (cn_tab == NULL || cp->cn_pri > cn_tab->cn_pri))
137 			cn_tab = cp;
138 	}
139 	if (cn_tab) {
140 		(*cn_tab->cn_init)(cn_tab);
141 		return cn_tab->cn_name;
142 	}
143 
144 	return NULL;
145 }
146 
147 int
148 cngetc(void)
149 {
150 
151 	if (cn_tab)
152 		return (*cn_tab->cn_getc)(cn_tab->cn_dev);
153 	return 0;
154 }
155 
156 void
157 cnputc(int c)
158 {
159 
160 	if (cn_tab)
161 		(*cn_tab->cn_putc)(cn_tab->cn_dev, c);
162 }
163 
164 int
165 cnscan(void)
166 {
167 
168 	if (cn_tab)
169 		return (*cn_tab->cn_scan)(cn_tab->cn_dev);
170 	return -1;
171 }
172 
173 #ifdef CONS_SCIF
174 /*
175  * sh3 scif console
176  */
177 static void
178 scifcnprobe(struct consdev *cp)
179 {
180 
181 	cp->cn_pri = CN_REMOTE;
182 }
183 
184 static void
185 scifcninit(struct consdev *cp)
186 {
187 
188 	cp->cn_dev = scif_init(cp->speed);
189 }
190 
191 static int
192 scifcngetchar(void *dev)
193 {
194 
195 	return scif_getc();
196 }
197 
198 static void
199 scifcnputchar(void *dev, int c)
200 {
201 
202 	if (c == '\n')
203 		scif_putc('\r');
204 	scif_putc(c);
205 }
206 
207 static int
208 scifcnscan(void *dev)
209 {
210 
211 	return scif_scankbd();
212 }
213 #endif /* CONS_SCIF */
214 
215 #ifdef CONS_COM
216 /*
217  * com console
218  */
219 static void
220 comcnprobe(struct consdev *cp)
221 {
222 
223 	cp->cn_pri = CN_REMOTE;
224 }
225 
226 static void
227 comcninit(struct consdev *cp)
228 {
229 
230 	cp->cn_dev = com_init(cp->address, cp->speed);
231 }
232 
233 static int
234 comcngetchar(void *dev)
235 {
236 
237 	return com_getc(dev);
238 }
239 
240 static void
241 comcnputchar(void *dev, int c)
242 {
243 
244 	if (c == '\n')
245 		com_putc(dev, '\r');
246 	com_putc(dev, c);
247 }
248 
249 static int
250 comcnscan(void *dev)
251 {
252 
253 	return com_scankbd(dev);
254 }
255 #endif /* CONS_COM */
256