1 /* $NetBSD: sio.c,v 1.4 2014/01/03 02:03:12 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 91 void 92 _siointr(void) 93 { 94 int unit; 95 96 for (unit = 0; unit < NSIO; unit++) 97 siointr(unit); 98 } 99 100 void 101 siointr(int unit) 102 { 103 #if 0 104 struct siodevice *sio = sio_addr[unit]; 105 #endif 106 int rr0 = sioreg(REG(unit, RR0), 0); 107 int rr1 = sioreg(REG(unit, RR1), 0); 108 109 if (rr0 & RR0_RXAVAIL) { 110 if (rr1 & RR1_FRAMING) 111 return; 112 113 if (rr1 & (RR1_PARITY | RR1_OVERRUN)) { 114 /* Channel-A Error Reset */ 115 sioreg(REG(unit, WR0), WR0_ERRRST); 116 } 117 118 if (unit == 1) { 119 int c = kbd_decode(sio_addr[unit]->sio_data); 120 121 if ((c & KC_TYPE) == KC_CODE) 122 PUSH_RBUF(unit, c); 123 } else { 124 PUSH_RBUF(unit, sio_addr[unit]->sio_data); 125 } 126 } 127 } 128 129 /* 130 * Following are all routines needed for SIO to act as console 131 */ 132 #include <dev/cons.h> 133 #include <luna68k/stand/boot/romvec.h> 134 135 void 136 siocnprobe(struct consdev *cp) 137 { 138 sio_addr[0] = (struct siodevice *)0x51000000; 139 sio_addr[1] = (struct siodevice *)0x51000004; 140 141 /* make sure hardware exists */ 142 if (badaddr((short *)sio_addr[0])) { 143 cp->cn_pri = CN_DEAD; 144 return; 145 } 146 147 /* locate the major number */ 148 149 /* initialize required fields */ 150 cp->cn_dev = 0; 151 cp->cn_pri = CN_NORMAL; 152 } 153 154 void 155 siocninit(struct consdev *cp) 156 { 157 int unit = cp->cn_dev; 158 159 sioinit(); 160 sioconsole = unit; 161 } 162 163 int 164 siocngetc(dev_t dev) 165 { 166 int c, unit = dev; 167 168 if (RBUF_EMPTY(unit)) 169 return 0; 170 171 POP_RBUF(unit, c); 172 173 return c; 174 } 175 176 void 177 siocnputc(dev_t dev, int c) 178 { 179 int unit = dev; 180 int s; 181 182 if (sioconsole == -1) { 183 (void)sioinit(); 184 sioconsole = unit; 185 } 186 187 s = splsio(); 188 189 /* wait for any pending transmission to finish */ 190 while ((sioreg(REG(unit, RR0), 0) & RR0_TXEMPTY) == 0) 191 continue; 192 193 sio_addr[unit]->sio_data = (c & 0xFF); 194 195 /* wait for any pending transmission to finish */ 196 while ((sioreg(REG(unit, RR0), 0) & RR0_TXEMPTY) == 0) 197 continue; 198 199 splx(s); 200 } 201 202 /* SIO misc routines */ 203 204 void 205 sioinit(void) 206 { 207 int s; 208 209 RBUF_INIT(0); 210 RBUF_INIT(1); 211 212 s = splsio(); 213 214 /* Channel-A Reset */ 215 sioreg(REG(0, WR0), WR0_CHANRST); 216 217 /* Set CPU BUS Interface Mode */ 218 sioreg(WR2A, WR2_VEC86 | WR2_INTR_1); 219 /* Set Interrupt Vector */ 220 sioreg(WR2B, 0); 221 222 /* Reset E/S Interrupt */ 223 sioreg(REG(0, WR0), WR0_RSTINT); 224 /* Tx/Rx */ 225 sioreg(REG(0, WR4), WR4_BAUD96 | WR4_STOP1 | WR4_NPARITY); 226 /* Rx */ 227 sioreg(REG(0, WR3), WR3_RX8BIT | WR3_RXENBL); 228 /* Tx */ 229 sioreg(REG(0, WR5), WR5_TX8BIT | WR5_TXENBL | WR5_DTR | WR5_RTS); 230 /* Reset E/S Interrupt */ 231 sioreg(REG(0, WR0), WR0_RSTINT); 232 /* Interrupted All Char. */ 233 sioreg(REG(0, WR1), WR1_RXALLS); 234 235 /* Channel-A Reset */ 236 sioreg(REG(1, WR0), WR0_CHANRST); 237 238 /* Reset E/S Interrupt */ 239 sioreg(REG(1, WR0), WR0_RSTINT); 240 /* Tx/Rx */ 241 sioreg(REG(1, WR4), WR4_BAUD96 | WR4_STOP1 | WR4_NPARITY); 242 /* Rx */ 243 sioreg(REG(1, WR3), WR3_RX8BIT | WR3_RXENBL); 244 /* Tx */ 245 sioreg(REG(1, WR5), WR5_TX8BIT | WR5_TXENBL); 246 /* Reset E/S Interrupt */ 247 sioreg(REG(1, WR0), WR0_RSTINT); 248 /* Interrupted All Char. */ 249 sioreg(REG(1, WR1), WR1_RXALLS); 250 251 splx(s); 252 } 253 254 int 255 sioreg(int reg, int val) 256 { 257 int chan; 258 259 chan = CHANNEL(reg); 260 261 if (isStatusReg(reg)) { 262 if (REGNO(reg) != 0) 263 sio_addr[chan]->sio_cmd = REGNO(reg); 264 return sio_addr[chan]->sio_stat; 265 } else { 266 if (REGNO(reg) != 0) 267 sio_addr[chan]->sio_cmd = REGNO(reg); 268 sio_addr[chan]->sio_cmd = val; 269 return val; 270 } 271 } 272