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