Home | History | Annotate | Line # | Download | only in vsa
dz_vsbus.c revision 1.11
      1 /*	$NetBSD: dz_vsbus.c,v 1.11 1999/03/27 15:33:46 ragge Exp $ */
      2 /*
      3  * Copyright (c) 1998 Ludd, University of Lule}, Sweden.
      4  * All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *      This product includes software developed at Ludd, University of
     17  *      Lule}, Sweden and its contributors.
     18  * 4. The name of the author may not be used to endorse or promote products
     19  *    derived from this software without specific prior written permission
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 
     34 
     35 #include <sys/param.h>
     36 #include <sys/proc.h>
     37 #include <sys/systm.h>
     38 #include <sys/ioctl.h>
     39 #include <sys/tty.h>
     40 #include <sys/file.h>
     41 #include <sys/conf.h>
     42 #include <sys/device.h>
     43 #include <sys/reboot.h>
     44 
     45 #include <dev/cons.h>
     46 
     47 #include <machine/mtpr.h>
     48 #include <machine/sid.h>
     49 #include <machine/uvax.h>
     50 #include <machine/vsbus.h>
     51 #include <machine/cpu.h>
     52 #include <machine/scb.h>
     53 
     54 #include <machine/../vax/gencons.h>
     55 
     56 #include <vax/uba/dzreg.h>
     57 #include <vax/uba/dzvar.h>
     58 
     59 #include "ioconf.h"
     60 #include "lkc.h"
     61 
     62 static  int     dz_vsbus_match __P((struct device *, struct cfdata *, void *));
     63 static  void    dz_vsbus_attach __P((struct device *, struct device *, void *));
     64 static	int	dz_print __P((void *, const char *));
     65 
     66 static	vaddr_t dz_regs; /* Used for console */
     67 
     68 struct  cfattach dz_vsbus_ca = {
     69 	sizeof(struct dz_softc), dz_vsbus_match, dz_vsbus_attach
     70 };
     71 
     72 #define REG(name)     short name; short X##name##X;
     73 static volatile struct ss_dz {/* base address of DZ-controller: 0x200A0000 */
     74 	REG(csr);	/* 00 Csr: control/status register */
     75 	REG(rbuf);	/* 04 Rbuf/Lpr: receive buffer/line param reg. */
     76 	REG(tcr);	/* 08 Tcr: transmit console register */
     77 	REG(tdr);	/* 0C Msr/Tdr: modem status reg/transmit data reg */
     78 	REG(lpr0);	/* 10 Lpr0: */
     79 	REG(lpr1);	/* 14 Lpr0: */
     80 	REG(lpr2);	/* 18 Lpr0: */
     81 	REG(lpr3);	/* 1C Lpr0: */
     82 } *dz;
     83 #undef REG
     84 
     85 cons_decl(dz);
     86 
     87 int
     88 dz_print(aux, name)
     89 	void *aux;
     90 	const char *name;
     91 {
     92 	if (name)
     93 		printf ("lkc at %s", name);
     94 	return (UNCONF);
     95 }
     96 
     97 static int
     98 dz_vsbus_match(parent, cf, aux)
     99 	struct device *parent;
    100 	struct cfdata *cf;
    101 	void *aux;
    102 {
    103 	struct vsbus_attach_args *va = aux;
    104 	struct ss_dz *dzP;
    105 	short i;
    106 
    107 	dzP = (struct ss_dz *)va->va_addr;
    108 	i = dzP->tcr;
    109 	dzP->csr = DZ_CSR_MSE;
    110 	dzP->tcr = 0;
    111 	DELAY(1000);
    112 	dzP->tcr = 1;
    113 	DELAY(100000);
    114 	dzP->tcr = i;
    115 	va->va_ivec = dzxint;
    116 
    117 	/* If the device doesn't exist, no interrupt has been generated */
    118 	return 1;
    119 }
    120 
    121 static void
    122 dz_vsbus_attach(parent, self, aux)
    123 	struct device *parent, *self;
    124 	void *aux;
    125 {
    126 	struct  dz_softc *sc = (void *)self;
    127 	struct vsbus_attach_args *va = aux;
    128 
    129 	sc->sc_dr.dr_csr = (void *)(dz_regs + 0);
    130 	sc->sc_dr.dr_rbuf = (void *)(dz_regs + 4);
    131 	sc->sc_dr.dr_dtr = (void *)(dz_regs + 9);
    132 	sc->sc_dr.dr_break = (void *)(dz_regs + 13);
    133 	sc->sc_dr.dr_tbuf = (void *)(dz_regs + 12);
    134 	sc->sc_dr.dr_tcr = (void *)(dz_regs + 8);
    135 	sc->sc_dr.dr_dcd = (void *)(dz_regs + 13);
    136 	sc->sc_dr.dr_ring = (void *)(dz_regs + 13);
    137 
    138 	sc->sc_type = DZ_DZV;
    139 
    140 	sc->sc_dsr = 0x0f; /* XXX check if VS has modem ctrl bits */
    141 	scb_vecalloc(va->va_cvec - 4, dzrint, self->dv_unit, SCB_ISTACK);
    142 	printf("\n%s: 4 lines", self->dv_xname);
    143 
    144 	dzattach(sc);
    145 
    146 	if (((vax_confdata & 0x80) == 0) ||/* workstation, have lkc */
    147 	    (vax_boardtype == VAX_BTYP_48))
    148 		config_found(self, 0, dz_print);
    149 }
    150 
    151 int
    152 dzcngetc(dev)
    153 	dev_t dev;
    154 {
    155 	int c = 0;
    156 	int mino = minor(dev);
    157 	u_short rbuf;
    158 
    159 	do {
    160 		while ((dz->csr & 0x80) == 0)
    161 			; /* Wait for char */
    162 		rbuf = dz->rbuf;
    163 		if (((rbuf >> 8) & 3) != mino)
    164 			continue;
    165 		c = rbuf & 0x7f;
    166 	} while (c == 17 || c == 19);		/* ignore XON/XOFF */
    167 
    168 	if (c == 13)
    169 		c = 10;
    170 
    171 	return (c);
    172 }
    173 
    174 #define	DZMAJOR	1
    175 
    176 void
    177 dzcnprobe(cndev)
    178 	struct	consdev *cndev;
    179 {
    180 	extern	vaddr_t iospace;
    181 	int diagcons;
    182 
    183 	switch (vax_boardtype) {
    184 	case VAX_BTYP_410:
    185 	case VAX_BTYP_420:
    186 	case VAX_BTYP_43:
    187 		diagcons = (vax_confdata & 0x20 ? 3 : 0);
    188 		break;
    189 
    190 	case VAX_BTYP_46:
    191 	case VAX_BTYP_48:
    192 		diagcons = (vax_confdata & 0x100 ? 3 : 0);
    193 		break;
    194 
    195 	case VAX_BTYP_49:
    196 		diagcons = 3;
    197 		break;
    198 
    199 	default:
    200 		cndev->cn_pri = CN_DEAD;
    201 		return;
    202 	}
    203 	if (diagcons)
    204 		cndev->cn_pri = CN_REMOTE;
    205 	else
    206 		cndev->cn_pri = CN_NORMAL;
    207 	cndev->cn_dev = makedev(DZMAJOR, diagcons);
    208 	dz_regs = iospace;
    209 	ioaccess(iospace, 0x200A0000, 1);
    210 }
    211 
    212 void
    213 dzcninit(cndev)
    214 	struct	consdev *cndev;
    215 {
    216 	dz = (void*)dz_regs;
    217 
    218 	dz->csr = 0;    /* Disable scanning until initting is done */
    219 	dz->tcr = (1 << minor(cndev->cn_dev));    /* Turn on xmitter */
    220 	dz->csr = 0x20; /* Turn scanning back on */
    221 }
    222 
    223 
    224 void
    225 dzcnputc(dev,ch)
    226 	dev_t	dev;
    227 	int	ch;
    228 {
    229 	int timeout = 1<<15;            /* don't hang the machine! */
    230 	int mino = minor(dev);
    231 	u_short tcr;
    232 
    233 	if (mfpr(PR_MAPEN) == 0)
    234 		return;
    235 
    236 	tcr = dz->tcr;	/* remember which lines to scan */
    237 	dz->tcr = (1 << mino);
    238 
    239 	while ((dz->csr & 0x8000) == 0) /* Wait until ready */
    240 		if (--timeout < 0)
    241 			break;
    242 	dz->tdr = ch;                    /* Put the  character */
    243 	timeout = 1<<15;
    244 	while ((dz->csr & 0x8000) == 0) /* Wait until ready */
    245 		if (--timeout < 0)
    246 			break;
    247 
    248 	dz->tcr = tcr;
    249 }
    250 
    251 void
    252 dzcnpollc(dev, pollflag)
    253 	dev_t dev;
    254 	int pollflag;
    255 {
    256 	static	u_char mask;
    257 
    258 	if (pollflag)
    259 		mask = vsbus_setmask(0);
    260 	else
    261 		vsbus_setmask(mask);
    262 }
    263 
    264 #if NLKC
    265 cons_decl(lkc);
    266 
    267 void
    268 lkccninit(cndev)
    269 	struct	consdev *cndev;
    270 {
    271 	dz = (void*)dz_regs;
    272 
    273 	dz->csr = 0;    /* Disable scanning until initting is done */
    274 	dz->tcr = 1;    /* Turn off all but line 0's xmitter */
    275 	dz->rbuf = 0x1c18; /* XXX */
    276 	dz->csr = 0x20; /* Turn scanning back on */
    277 }
    278 
    279 int
    280 lkccngetc(dev)
    281 	dev_t dev;
    282 {
    283 	int lkc_decode(int);
    284 	int c;
    285 //	u_char mask;
    286 
    287 
    288 //	mask = vsbus_setmask(0);	/* save old state */
    289 
    290 loop:
    291 	while ((dz->csr & 0x80) == 0)
    292 		; /* Wait for char */
    293 
    294 	c = lkc_decode(dz->rbuf & 255);
    295 	if (c < 1)
    296 		goto loop;
    297 
    298 //	vsbus_clrintr(0x80); /* XXX */
    299 //	vsbus_setmask(mask);
    300 
    301 	return (c);
    302 }
    303 #endif
    304