1*5b509902Stsutsui /* $NetBSD: cons.c,v 1.3 2015/02/14 05:58:02 tsutsui Exp $ */
2df6945b8Stsutsui
3df6945b8Stsutsui /*
4df6945b8Stsutsui * Copyright (c) 1992 OMRON Corporation.
5df6945b8Stsutsui *
6df6945b8Stsutsui * This code is derived from software contributed to Berkeley by
7df6945b8Stsutsui * OMRON Corporation.
8df6945b8Stsutsui *
9df6945b8Stsutsui * Redistribution and use in source and binary forms, with or without
10df6945b8Stsutsui * modification, are permitted provided that the following conditions
11df6945b8Stsutsui * are met:
12df6945b8Stsutsui * 1. Redistributions of source code must retain the above copyright
13df6945b8Stsutsui * notice, this list of conditions and the following disclaimer.
14df6945b8Stsutsui * 2. Redistributions in binary form must reproduce the above copyright
15df6945b8Stsutsui * notice, this list of conditions and the following disclaimer in the
16df6945b8Stsutsui * documentation and/or other materials provided with the distribution.
17df6945b8Stsutsui * 3. All advertising materials mentioning features or use of this software
18df6945b8Stsutsui * must display the following acknowledgement:
19df6945b8Stsutsui * This product includes software developed by the University of
20df6945b8Stsutsui * California, Berkeley and its contributors.
21df6945b8Stsutsui * 4. Neither the name of the University nor the names of its contributors
22df6945b8Stsutsui * may be used to endorse or promote products derived from this software
23df6945b8Stsutsui * without specific prior written permission.
24df6945b8Stsutsui *
25df6945b8Stsutsui * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26df6945b8Stsutsui * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27df6945b8Stsutsui * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28df6945b8Stsutsui * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29df6945b8Stsutsui * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30df6945b8Stsutsui * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31df6945b8Stsutsui * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32df6945b8Stsutsui * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33df6945b8Stsutsui * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34df6945b8Stsutsui * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35df6945b8Stsutsui * SUCH DAMAGE.
36df6945b8Stsutsui *
37df6945b8Stsutsui * @(#)cons.c 8.1 (Berkeley) 6/10/93
38df6945b8Stsutsui */
39df6945b8Stsutsui /*
40df6945b8Stsutsui * Copyright (c) 1992, 1993
41df6945b8Stsutsui * The Regents of the University of California. All rights reserved.
42df6945b8Stsutsui *
43df6945b8Stsutsui * This code is derived from software contributed to Berkeley by
44df6945b8Stsutsui * OMRON Corporation.
45df6945b8Stsutsui *
46df6945b8Stsutsui * Redistribution and use in source and binary forms, with or without
47df6945b8Stsutsui * modification, are permitted provided that the following conditions
48df6945b8Stsutsui * are met:
49df6945b8Stsutsui * 1. Redistributions of source code must retain the above copyright
50df6945b8Stsutsui * notice, this list of conditions and the following disclaimer.
51df6945b8Stsutsui * 2. Redistributions in binary form must reproduce the above copyright
52df6945b8Stsutsui * notice, this list of conditions and the following disclaimer in the
53df6945b8Stsutsui * documentation and/or other materials provided with the distribution.
54df6945b8Stsutsui * 3. Neither the name of the University nor the names of its contributors
55df6945b8Stsutsui * may be used to endorse or promote products derived from this software
56df6945b8Stsutsui * without specific prior written permission.
57df6945b8Stsutsui *
58df6945b8Stsutsui * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59df6945b8Stsutsui * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60df6945b8Stsutsui * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61df6945b8Stsutsui * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62df6945b8Stsutsui * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63df6945b8Stsutsui * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64df6945b8Stsutsui * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65df6945b8Stsutsui * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66df6945b8Stsutsui * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67df6945b8Stsutsui * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68df6945b8Stsutsui * SUCH DAMAGE.
69df6945b8Stsutsui *
70df6945b8Stsutsui * @(#)cons.c 8.1 (Berkeley) 6/10/93
71df6945b8Stsutsui */
72df6945b8Stsutsui
73df6945b8Stsutsui #include <sys/param.h>
74df6945b8Stsutsui #include <dev/cons.h>
75df6945b8Stsutsui #include <luna68k/stand/boot/samachdep.h>
76df6945b8Stsutsui
77df6945b8Stsutsui #define NBMC 1
78df6945b8Stsutsui #define NSIO 1
79df6945b8Stsutsui #define NROM 0 /* XXX doesn't work with framebuffer/keyboard? */
80df6945b8Stsutsui
81df6945b8Stsutsui /* XXX - all this could be autoconfig()ed */
82df6945b8Stsutsui
83df6945b8Stsutsui struct consdev constab[] = {
84df6945b8Stsutsui #if NBMC > 0
85df6945b8Stsutsui { bmccnprobe, bmccninit, bmccngetc, bmccnputc },
86df6945b8Stsutsui #endif
87df6945b8Stsutsui #if NSIO > 0
88df6945b8Stsutsui { siocnprobe, siocninit, siocngetc, siocnputc },
89df6945b8Stsutsui #endif
90df6945b8Stsutsui #if NROM > 0
91df6945b8Stsutsui { romcnprobe, romcninit, romcngetc, romcnputc },
92df6945b8Stsutsui #endif
93df6945b8Stsutsui { 0 },
94df6945b8Stsutsui };
95df6945b8Stsutsui /* end XXX */
96df6945b8Stsutsui
97df6945b8Stsutsui struct tty *constty = 0; /* virtual console output device */
98df6945b8Stsutsui struct consdev *cn_tab; /* physical console device info */
99df6945b8Stsutsui
100df6945b8Stsutsui void
cninit(void)101df6945b8Stsutsui cninit(void)
102df6945b8Stsutsui {
103df6945b8Stsutsui struct consdev *cp;
104df6945b8Stsutsui
105df6945b8Stsutsui /*
106df6945b8Stsutsui * Collect information about all possible consoles
107df6945b8Stsutsui * and find the one with highest priority
108df6945b8Stsutsui */
109df6945b8Stsutsui for (cp = constab; cp->cn_probe; cp++) {
110df6945b8Stsutsui (*cp->cn_probe)(cp);
111df6945b8Stsutsui if (cp->cn_pri > CN_DEAD &&
112df6945b8Stsutsui (cn_tab == NULL || cp->cn_pri > cn_tab->cn_pri))
113df6945b8Stsutsui cn_tab = cp;
114df6945b8Stsutsui }
115df6945b8Stsutsui /*
116df6945b8Stsutsui * No console, we can handle it
117df6945b8Stsutsui */
118df6945b8Stsutsui if ((cp = cn_tab) == NULL)
119df6945b8Stsutsui return;
120df6945b8Stsutsui /*
121df6945b8Stsutsui * Turn on console
122df6945b8Stsutsui */
123df6945b8Stsutsui (*cp->cn_init)(cp);
124df6945b8Stsutsui }
125df6945b8Stsutsui
126df6945b8Stsutsui int
cngetc(void)127df6945b8Stsutsui cngetc(void)
128df6945b8Stsutsui {
129*5b509902Stsutsui
130df6945b8Stsutsui if (cn_tab == NULL)
1310dfe4134Stsutsui return 0;
1320dfe4134Stsutsui return (*cn_tab->cn_getc)(cn_tab->cn_dev);
133df6945b8Stsutsui }
134df6945b8Stsutsui
135df6945b8Stsutsui void
cnputc(int c)136df6945b8Stsutsui cnputc(int c)
137df6945b8Stsutsui {
138*5b509902Stsutsui
139df6945b8Stsutsui if (cn_tab == NULL)
140df6945b8Stsutsui return;
141*5b509902Stsutsui if (c != 0) {
142df6945b8Stsutsui (*cn_tab->cn_putc)(cn_tab->cn_dev, c);
143df6945b8Stsutsui if (c == '\n')
144df6945b8Stsutsui (*cn_tab->cn_putc)(cn_tab->cn_dev, '\r');
145df6945b8Stsutsui }
146df6945b8Stsutsui }
147