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