sio.c revision 1.3.6.2 1 1.3.6.2 tls /* $NetBSD: sio.c,v 1.3.6.2 2013/02/25 00:28:50 tls Exp $ */
2 1.3.6.2 tls
3 1.3.6.2 tls /*
4 1.3.6.2 tls * Copyright (c) 1992 OMRON Corporation.
5 1.3.6.2 tls *
6 1.3.6.2 tls * This code is derived from software contributed to Berkeley by
7 1.3.6.2 tls * OMRON Corporation.
8 1.3.6.2 tls *
9 1.3.6.2 tls * Redistribution and use in source and binary forms, with or without
10 1.3.6.2 tls * modification, are permitted provided that the following conditions
11 1.3.6.2 tls * are met:
12 1.3.6.2 tls * 1. Redistributions of source code must retain the above copyright
13 1.3.6.2 tls * notice, this list of conditions and the following disclaimer.
14 1.3.6.2 tls * 2. Redistributions in binary form must reproduce the above copyright
15 1.3.6.2 tls * notice, this list of conditions and the following disclaimer in the
16 1.3.6.2 tls * documentation and/or other materials provided with the distribution.
17 1.3.6.2 tls * 3. All advertising materials mentioning features or use of this software
18 1.3.6.2 tls * must display the following acknowledgement:
19 1.3.6.2 tls * This product includes software developed by the University of
20 1.3.6.2 tls * California, Berkeley and its contributors.
21 1.3.6.2 tls * 4. Neither the name of the University nor the names of its contributors
22 1.3.6.2 tls * may be used to endorse or promote products derived from this software
23 1.3.6.2 tls * without specific prior written permission.
24 1.3.6.2 tls *
25 1.3.6.2 tls * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 1.3.6.2 tls * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 1.3.6.2 tls * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 1.3.6.2 tls * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 1.3.6.2 tls * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 1.3.6.2 tls * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 1.3.6.2 tls * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 1.3.6.2 tls * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 1.3.6.2 tls * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 1.3.6.2 tls * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 1.3.6.2 tls * SUCH DAMAGE.
36 1.3.6.2 tls *
37 1.3.6.2 tls * @(#)sio.c 8.1 (Berkeley) 6/10/93
38 1.3.6.2 tls */
39 1.3.6.2 tls /*
40 1.3.6.2 tls * Copyright (c) 1992, 1993
41 1.3.6.2 tls * The Regents of the University of California. All rights reserved.
42 1.3.6.2 tls *
43 1.3.6.2 tls * This code is derived from software contributed to Berkeley by
44 1.3.6.2 tls * OMRON Corporation.
45 1.3.6.2 tls *
46 1.3.6.2 tls * Redistribution and use in source and binary forms, with or without
47 1.3.6.2 tls * modification, are permitted provided that the following conditions
48 1.3.6.2 tls * are met:
49 1.3.6.2 tls * 1. Redistributions of source code must retain the above copyright
50 1.3.6.2 tls * notice, this list of conditions and the following disclaimer.
51 1.3.6.2 tls * 2. Redistributions in binary form must reproduce the above copyright
52 1.3.6.2 tls * notice, this list of conditions and the following disclaimer in the
53 1.3.6.2 tls * documentation and/or other materials provided with the distribution.
54 1.3.6.2 tls * 3. Neither the name of the University nor the names of its contributors
55 1.3.6.2 tls * may be used to endorse or promote products derived from this software
56 1.3.6.2 tls * without specific prior written permission.
57 1.3.6.2 tls *
58 1.3.6.2 tls * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59 1.3.6.2 tls * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 1.3.6.2 tls * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 1.3.6.2 tls * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 1.3.6.2 tls * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 1.3.6.2 tls * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 1.3.6.2 tls * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 1.3.6.2 tls * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 1.3.6.2 tls * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 1.3.6.2 tls * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 1.3.6.2 tls * SUCH DAMAGE.
69 1.3.6.2 tls *
70 1.3.6.2 tls * @(#)sio.c 8.1 (Berkeley) 6/10/93
71 1.3.6.2 tls */
72 1.3.6.2 tls
73 1.3.6.2 tls /* sio.c NOV-25-1991 */
74 1.3.6.2 tls
75 1.3.6.2 tls #define NSIO 2
76 1.3.6.2 tls
77 1.3.6.2 tls #include <sys/param.h>
78 1.3.6.2 tls #include <luna68k/stand/boot/samachdep.h>
79 1.3.6.2 tls #include <luna68k/stand/boot/sioreg.h>
80 1.3.6.2 tls #include <luna68k/stand/boot/rcvbuf.h>
81 1.3.6.2 tls #include <luna68k/stand/boot/kbdreg.h>
82 1.3.6.2 tls
83 1.3.6.2 tls static void siointr(int);
84 1.3.6.2 tls static int sioreg(int, int);
85 1.3.6.2 tls
86 1.3.6.2 tls struct rcvbuf rcvbuf[NSIO];
87 1.3.6.2 tls
88 1.3.6.2 tls int sioconsole = -1;
89 1.3.6.2 tls struct siodevice *sio_addr[2];
90 1.3.6.2 tls int cur_unit;
91 1.3.6.2 tls
92 1.3.6.2 tls
93 1.3.6.2 tls #define siounit(x) ( x & 0xffff )
94 1.3.6.2 tls #define isprint(c) ((c >= 0x20) && (c < 0x7F) ? 1 : 0)
95 1.3.6.2 tls
96 1.3.6.2 tls
97 1.3.6.2 tls void
98 1.3.6.2 tls _siointr(void)
99 1.3.6.2 tls {
100 1.3.6.2 tls int unit;
101 1.3.6.2 tls
102 1.3.6.2 tls for (unit = 0; unit < NSIO; unit++)
103 1.3.6.2 tls siointr(unit);
104 1.3.6.2 tls }
105 1.3.6.2 tls
106 1.3.6.2 tls void
107 1.3.6.2 tls siointr(int unit)
108 1.3.6.2 tls {
109 1.3.6.2 tls /* struct siodevice *sio = sio_addr[unit]; */
110 1.3.6.2 tls int rr0 = sioreg(REG(unit, RR0), 0);
111 1.3.6.2 tls int rr1 = sioreg(REG(unit, RR1), 0);
112 1.3.6.2 tls
113 1.3.6.2 tls if (rr0 & RR0_RXAVAIL) {
114 1.3.6.2 tls if (rr1 & RR1_FRAMING)
115 1.3.6.2 tls return;
116 1.3.6.2 tls
117 1.3.6.2 tls if (rr1 & (RR1_PARITY | RR1_OVERRUN))
118 1.3.6.2 tls sioreg(REG(unit, WR0), WR0_ERRRST); /* Channel-A Error Reset */
119 1.3.6.2 tls
120 1.3.6.2 tls if (unit == 1) {
121 1.3.6.2 tls int c = kbd_decode(sio_addr[unit]->sio_data);
122 1.3.6.2 tls
123 1.3.6.2 tls if ((c & KC_TYPE) == KC_CODE)
124 1.3.6.2 tls PUSH_RBUF(unit, c);
125 1.3.6.2 tls } else {
126 1.3.6.2 tls PUSH_RBUF(unit, sio_addr[unit]->sio_data);
127 1.3.6.2 tls }
128 1.3.6.2 tls }
129 1.3.6.2 tls }
130 1.3.6.2 tls
131 1.3.6.2 tls /*
132 1.3.6.2 tls * Following are all routines needed for SIO to act as console
133 1.3.6.2 tls */
134 1.3.6.2 tls #include <dev/cons.h>
135 1.3.6.2 tls #include <luna68k/stand/boot/romvec.h>
136 1.3.6.2 tls
137 1.3.6.2 tls void
138 1.3.6.2 tls siocnprobe(struct consdev *cp)
139 1.3.6.2 tls {
140 1.3.6.2 tls sio_addr[0] = (struct siodevice *) 0x51000000;
141 1.3.6.2 tls sio_addr[1] = (struct siodevice *) 0x51000004;
142 1.3.6.2 tls
143 1.3.6.2 tls /* make sure hardware exists */
144 1.3.6.2 tls if (badaddr((short *)sio_addr[0])) {
145 1.3.6.2 tls cp->cn_pri = CN_DEAD;
146 1.3.6.2 tls return;
147 1.3.6.2 tls }
148 1.3.6.2 tls
149 1.3.6.2 tls /* locate the major number */
150 1.3.6.2 tls
151 1.3.6.2 tls /* initialize required fields */
152 1.3.6.2 tls cp->cn_dev = cur_unit = 0;
153 1.3.6.2 tls cp->cn_pri = CN_NORMAL;
154 1.3.6.2 tls }
155 1.3.6.2 tls
156 1.3.6.2 tls void
157 1.3.6.2 tls siocninit(struct consdev *cp)
158 1.3.6.2 tls {
159 1.3.6.2 tls int unit = siounit(cp->cn_dev);
160 1.3.6.2 tls
161 1.3.6.2 tls sioinit();
162 1.3.6.2 tls sioconsole = unit;
163 1.3.6.2 tls }
164 1.3.6.2 tls
165 1.3.6.2 tls int
166 1.3.6.2 tls siocngetc(dev_t dev)
167 1.3.6.2 tls {
168 1.3.6.2 tls int c, unit = siounit(dev);
169 1.3.6.2 tls
170 1.3.6.2 tls if (RBUF_EMPTY(unit))
171 1.3.6.2 tls return 0;
172 1.3.6.2 tls
173 1.3.6.2 tls POP_RBUF(unit, c);
174 1.3.6.2 tls
175 1.3.6.2 tls return(c);
176 1.3.6.2 tls }
177 1.3.6.2 tls
178 1.3.6.2 tls void
179 1.3.6.2 tls siocnputc(dev_t dev, int c)
180 1.3.6.2 tls {
181 1.3.6.2 tls int unit = siounit(dev);
182 1.3.6.2 tls int s;
183 1.3.6.2 tls
184 1.3.6.2 tls if (sioconsole == -1) {
185 1.3.6.2 tls (void) sioinit();
186 1.3.6.2 tls sioconsole = unit;
187 1.3.6.2 tls }
188 1.3.6.2 tls
189 1.3.6.2 tls s = splsio();
190 1.3.6.2 tls
191 1.3.6.2 tls /* wait for any pending transmission to finish */
192 1.3.6.2 tls while ((sioreg(REG(unit, RR0), 0) & RR0_TXEMPTY) == 0);
193 1.3.6.2 tls
194 1.3.6.2 tls sio_addr[unit]->sio_data = (c & 0xFF);
195 1.3.6.2 tls
196 1.3.6.2 tls /* wait for any pending transmission to finish */
197 1.3.6.2 tls while ((sioreg(REG(unit, RR0), 0) & RR0_TXEMPTY) == 0);
198 1.3.6.2 tls
199 1.3.6.2 tls splx(s);
200 1.3.6.2 tls }
201 1.3.6.2 tls
202 1.3.6.2 tls /* SIO misc routines */
203 1.3.6.2 tls
204 1.3.6.2 tls void
205 1.3.6.2 tls sioinit(void)
206 1.3.6.2 tls {
207 1.3.6.2 tls int s;
208 1.3.6.2 tls
209 1.3.6.2 tls RBUF_INIT(0);
210 1.3.6.2 tls RBUF_INIT(1);
211 1.3.6.2 tls
212 1.3.6.2 tls s = splsio();
213 1.3.6.2 tls
214 1.3.6.2 tls sioreg(REG(0, WR0), WR0_CHANRST); /* Channel-A Reset */
215 1.3.6.2 tls
216 1.3.6.2 tls sioreg(WR2A, WR2_VEC86 | WR2_INTR_1); /* Set CPU BUS Interface Mode */
217 1.3.6.2 tls sioreg(WR2B, 0); /* Set Interrupt Vector */
218 1.3.6.2 tls
219 1.3.6.2 tls sioreg(REG(0, WR0), WR0_RSTINT); /* Reset E/S Interrupt */
220 1.3.6.2 tls sioreg(REG(0, WR4), WR4_BAUD96 | WR4_STOP1 | WR4_NPARITY); /* Tx/Rx */
221 1.3.6.2 tls sioreg(REG(0, WR3), WR3_RX8BIT | WR3_RXENBL); /* Rx */
222 1.3.6.2 tls sioreg(REG(0, WR5), WR5_TX8BIT | WR5_TXENBL | WR5_DTR | WR5_RTS); /* Tx */
223 1.3.6.2 tls sioreg(REG(0, WR0), WR0_RSTINT); /* Reset E/S Interrupt */
224 1.3.6.2 tls sioreg(REG(0, WR1), WR1_RXALLS); /* Interrupted All Char. */
225 1.3.6.2 tls
226 1.3.6.2 tls sioreg(REG(1, WR0), WR0_CHANRST); /* Channel-A Reset */
227 1.3.6.2 tls
228 1.3.6.2 tls sioreg(REG(1, WR0), WR0_RSTINT); /* Reset E/S Interrupt */
229 1.3.6.2 tls sioreg(REG(1, WR4), WR4_BAUD96 | WR4_STOP1 | WR4_NPARITY); /* Tx/Rx */
230 1.3.6.2 tls sioreg(REG(1, WR3), WR3_RX8BIT | WR3_RXENBL); /* Rx */
231 1.3.6.2 tls sioreg(REG(1, WR5), WR5_TX8BIT | WR5_TXENBL); /* Tx */
232 1.3.6.2 tls sioreg(REG(1, WR0), WR0_RSTINT); /* Reset E/S Interrupt */
233 1.3.6.2 tls sioreg(REG(1, WR1), WR1_RXALLS); /* Interrupted All Char. */
234 1.3.6.2 tls
235 1.3.6.2 tls splx(s);
236 1.3.6.2 tls }
237 1.3.6.2 tls
238 1.3.6.2 tls int
239 1.3.6.2 tls sioreg(int reg, int val)
240 1.3.6.2 tls {
241 1.3.6.2 tls int chan;
242 1.3.6.2 tls
243 1.3.6.2 tls chan = CHANNEL(reg);
244 1.3.6.2 tls
245 1.3.6.2 tls if (isStatusReg(reg)) {
246 1.3.6.2 tls if (REGNO(reg) != 0)
247 1.3.6.2 tls sio_addr[chan]->sio_cmd = REGNO(reg);
248 1.3.6.2 tls return(sio_addr[chan]->sio_stat);
249 1.3.6.2 tls } else {
250 1.3.6.2 tls if (REGNO(reg) != 0)
251 1.3.6.2 tls sio_addr[chan]->sio_cmd = REGNO(reg);
252 1.3.6.2 tls sio_addr[chan]->sio_cmd = val;
253 1.3.6.2 tls return(val);
254 1.3.6.2 tls }
255 1.3.6.2 tls }
256