xref: /netbsd/sys/arch/hpcsh/hpcsh/console.c (revision bf9ec67e)
1 /*	$NetBSD: console.c,v 1.9 2002/03/03 14:35:08 uch Exp $	*/
2 
3 /*-
4  * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by UCHIYAMA Yasushi.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #include "opt_kgdb.h"
40 #include "biconsdev.h"
41 #include "hpcfb.h"
42 #include "scif.h"
43 #include "hd64461uart.h"
44 #include "hd64465uart.h"
45 #include "hd64461video.h"
46 #include "wskbd.h"
47 #include "pfckbd.h"
48 
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/conf.h>
52 #include <dev/cons.h> /* consdev */
53 
54 #include <machine/bootinfo.h>
55 
56 #include <dev/wscons/wsdisplayvar.h>
57 #include <dev/rasops/rasops.h>
58 #include <dev/hpc/bicons.h>
59 #include <dev/hpc/biconsvar.h>
60 #include <dev/hpc/hpcfbvar.h>
61 #include <sh3/dev/scifvar.h>
62 #include <hpcsh/dev/pfckbdvar.h>
63 #include <hpcsh/dev/hd64461/hd64461uartvar.h>
64 #include <hpcsh/dev/hd64465/hd64465uartvar.h>
65 
66 /* Serial console */
67 #define scifcnpollc	nullcnpollc
68 cons_decl(scif);
69 #define	hd64461uartcnputc	comcnputc
70 #define	hd64461uartcngetc	comcngetc
71 #define	hd64461uartcnpollc	comcnpollc
72 cons_decl(hd64461uart);
73 #define	hd64465uartcnputc	comcnputc
74 #define	hd64465uartcngetc	comcngetc
75 #define	hd64465uartcnpollc	comcnpollc
76 cons_decl(hd64465uart);
77 
78 /* Builtin video console */
79 #if NBICONSDEV > 0
80 #define biconscnpollc	nullcnpollc
81 cons_decl(bicons);
82 #endif
83 
84 /* HD64461 video module */
85 #if NHD64461VIDEO > 0
86 cons_decl(hd64461video_);
87 #if NWSKBD > 0
88 #include <dev/wscons/wskbdvar.h>
89 #define hd64461video_cngetc	wskbd_cngetc
90 #else /* NWSKBD > 0 */
91 int
92 hd64461video_cngetc(dev_t dev)
93 {
94 	printf("no input method. reboot me.\n");
95 	while (1)
96 		;
97 	/* NOTREACHED */
98 }
99 #endif /* NWSKBD > 0 */
100 #define hd64461video_cnputc	wsdisplay_cnputc
101 #define	hd64461video_cnpollc	nullcnpollc
102 #endif /* NHD64461VIDEO > 0 */
103 
104 struct consdev constab[] = {
105 #if NBICONSDEV > 0
106 	cons_init(bicons),
107 #endif
108 #if NHD64461VIDEO > 0
109 	cons_init(hd64461video_),
110 #endif
111 #if NSCIF > 0
112 	cons_init(scif),
113 #endif
114 #if NHD64461UART > 0
115 	cons_init(hd64461uart),
116 #endif
117 #if NHD64465UART > 0
118 	cons_init(hd64465uart),
119 #endif
120 	{ 0 } /* terminator */
121 };
122 #define CN_ENABLE(x)	set_console(x ## cninit, x ## cnprobe)
123 
124 static int initialized;
125 static int attach_kbd  __attribute__((__unused__)) = 1;
126 static void set_console(void (*)(struct consdev *), void (*)(struct consdev *));
127 static void disable_console(void);
128 static void cn_nonprobe(struct consdev *);
129 #if NBICONSDEV > 0
130 static void enable_bicons(void);
131 #endif
132 
133 void
134 consinit()
135 {
136 	if (initialized)
137 		return;
138 
139 	/* select console */
140 	disable_console();
141 
142 	switch (bootinfo->bi_cnuse) {
143 	case BI_CNUSE_BUILTIN:
144 #if NBICONSDEV > 0
145 		enable_bicons();
146 #endif
147 		break;
148 	case BI_CNUSE_HD64461VIDEO:
149 #if NHD64461VIDEO > 0
150 		CN_ENABLE(hd64461video_);
151 		attach_kbd = 1;
152 #endif
153 		break;
154 	case BI_CNUSE_SCIF:
155 #if NSCIF > 0
156 		CN_ENABLE(scif);
157 #endif
158 		break;
159 	case BI_CNUSE_HD64461COM:
160 #if NHD64461UART > 0
161 		CN_ENABLE(hd64461uart);
162 #endif
163 		break;
164 	case BI_CNUSE_HD64465COM:
165 #if NHD64465UART > 0
166 		CN_ENABLE(hd64465uart);
167 #endif
168 		break;
169 	}
170 
171 #if NBICONSDEV > 0
172 	if (!initialized) { /* use builtin console instead */
173 		enable_bicons();
174 	}
175 #endif
176 
177 	if (initialized) {
178 		cninit();
179 	}
180 
181 #if NPFCKBD > 0
182 	if (attach_kbd)
183 		pfckbd_cnattach();
184 #endif
185 
186 #if NHPCFB > 0 && NBICONSDEV > 0
187 	if (cn_tab->cn_putc == biconscnputc)
188 		hpcfb_cnattach(0);
189 #endif
190 
191 #ifdef KGDB
192 #if NSCIF > 0
193 	scif_kgdb_init();
194 #endif
195 #if NHD64461UART > 0
196 	hd64461uart_kgdb_init();
197 #endif
198 #if NHD64465UART > 0
199 	hd64465uart_kgdb_init();
200 #endif
201 #endif /* KGDB */
202 }
203 
204 static void
205 set_console(void (*init_func)(struct consdev *),
206     void (*probe_func)(struct consdev *))
207 {
208 	struct consdev *cp;
209 
210 	for (cp = constab; cp->cn_probe; cp++) {
211 		if (cp->cn_init == init_func) {
212 			cp->cn_probe = probe_func;
213 			initialized = 1;
214 			break;
215 		}
216 	}
217 }
218 
219 static void
220 disable_console()
221 {
222 	struct consdev *cp;
223 
224 	for (cp = constab; cp->cn_probe; cp++)
225 		cp->cn_probe = cn_nonprobe;
226 }
227 
228 static void
229 cn_nonprobe(struct consdev *cp)
230 {
231 
232 	cp->cn_pri = CN_DEAD;
233 }
234 
235 #if NBICONSDEV > 0
236 static void
237 enable_bicons()
238 {
239 
240 	bootinfo->bi_cnuse = BI_CNUSE_BUILTIN;
241 	bicons_set_priority(CN_INTERNAL);
242 	CN_ENABLE(bicons);
243 	attach_kbd = 1;
244 }
245 #endif /* NBICONSDEV > 0 */
246