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