Home | History | Annotate | Line # | Download | only in vsa
dz_vsbus.c revision 1.23
      1 /*	$NetBSD: dz_vsbus.c,v 1.23 2002/06/10 21:32:15 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 <arch/vax/vax/gencons.h>
     55 
     56 #include <dev/dec/dzreg.h>
     57 #include <dev/dec/dzvar.h>
     58 
     59 #include "ioconf.h"
     60 #include "dzkbd.h"
     61 #include "dzms.h"
     62 #include "opt_cputype.h"
     63 
     64 #if NDZKBD > 0 || NDZMS > 0
     65 #include <dev/dec/dzkbdvar.h>
     66 
     67 #if 0
     68 static	struct dz_linestate dz_conslinestate = { NULL, -1, NULL, NULL, NULL };
     69 #endif
     70 #endif
     71 
     72 static  int     dz_vsbus_match(struct device *, struct cfdata *, void *);
     73 static  void    dz_vsbus_attach(struct device *, struct device *, void *);
     74 
     75 static	vaddr_t dz_regs; /* Used for console */
     76 
     77 struct  cfattach dz_vsbus_ca = {
     78 	sizeof(struct dz_softc), dz_vsbus_match, dz_vsbus_attach
     79 };
     80 
     81 #define REG(name)     short name; short X##name##X;
     82 static volatile struct ss_dz {/* base address of DZ-controller: 0x200A0000 */
     83 	REG(csr);	/* 00 Csr: control/status register */
     84 	REG(rbuf);	/* 04 Rbuf/Lpr: receive buffer/line param reg. */
     85 	REG(tcr);	/* 08 Tcr: transmit console register */
     86 	REG(tdr);	/* 0C Msr/Tdr: modem status reg/transmit data reg */
     87 	REG(lpr0);	/* 10 Lpr0: */
     88 	REG(lpr1);	/* 14 Lpr0: */
     89 	REG(lpr2);	/* 18 Lpr0: */
     90 	REG(lpr3);	/* 1C Lpr0: */
     91 } *dz;
     92 #undef REG
     93 
     94 cons_decl(dz);
     95 cdev_decl(dz);
     96 
     97 #if NDZKBD > 0 || NDZMS > 0
     98 static int
     99 dz_print(void *aux, const char *name)
    100 {
    101 #if 0
    102 #if NDZKBD > 0 || NDZMS > 0
    103 	struct dz_attach_args *dz_args = aux;
    104 	if (name == NULL) {
    105 		printf (" line %d", dz_args->line);
    106 		if (dz_args->hwflags & DZ_HWFLAG_CONSOLE)
    107 			printf (" (console)");
    108 	}
    109 	return (QUIET);
    110 #else
    111 	if (name)
    112 		printf ("lkc at %s", name);
    113 	return (UNCONF);
    114 #endif
    115 #endif
    116 	return (UNCONF);
    117 }
    118 #endif
    119 
    120 static int
    121 dz_vsbus_match(struct device *parent, struct cfdata *cf, void *aux)
    122 {
    123 	struct vsbus_attach_args *va = aux;
    124 	struct ss_dz *dzP;
    125 	short i;
    126 
    127 #if VAX53 || VAX49 || VAXANY
    128 	if (vax_boardtype == VAX_BTYP_53 || vax_boardtype == VAX_BTYP_49)
    129 		if (cf->cf_loc[0] != 0x25000000)
    130 			return 0; /* Ugly */
    131 #endif
    132 
    133 	dzP = (struct ss_dz *)va->va_addr;
    134 	i = dzP->tcr;
    135 	dzP->csr = DZ_CSR_MSE|DZ_CSR_TXIE;
    136 	dzP->tcr = 0;
    137 	DELAY(1000);
    138 	dzP->tcr = 1;
    139 	DELAY(100000);
    140 	dzP->tcr = i;
    141 
    142 	/* If the device doesn't exist, no interrupt has been generated */
    143 	return 1;
    144 }
    145 
    146 static void
    147 dz_vsbus_attach(struct device *parent, struct device *self, void *aux)
    148 {
    149 	struct dz_softc *sc = (void *)self;
    150 	struct vsbus_attach_args *va = aux;
    151 #if NDZKBD > 0 || NDZMS > 0
    152 	struct dzkm_attach_args daa;
    153 #endif
    154 	int s;
    155 
    156 	/*
    157 	 * XXX - This is evil and ugly, but...
    158 	 * due to the nature of how bus_space_* works on VAX, this will
    159 	 * be perfectly good until everything is converted.
    160 	 */
    161 	if (dz_regs == 0) /* This isn't console */
    162 		dz_regs = vax_map_physmem(va->va_paddr, 1);
    163 	sc->sc_ioh = dz_regs;
    164 	sc->sc_dr.dr_csr = 0;
    165 	sc->sc_dr.dr_rbuf = 4;
    166 	sc->sc_dr.dr_dtr = 9;
    167 	sc->sc_dr.dr_break = 13;
    168 	sc->sc_dr.dr_tbuf = 12;
    169 	sc->sc_dr.dr_tcr = 8;
    170 	sc->sc_dr.dr_dcd = 13;
    171 	sc->sc_dr.dr_ring = 13;
    172 
    173 	sc->sc_type = DZ_DZV;
    174 
    175 	sc->sc_dsr = 0x0f; /* XXX check if VS has modem ctrl bits */
    176 
    177 	scb_vecalloc(va->va_cvec, dzxint, sc, SCB_ISTACK, &sc->sc_tintrcnt);
    178 	scb_vecalloc(va->va_cvec - 4, dzrint, sc, SCB_ISTACK, &sc->sc_rintrcnt);
    179 
    180 	printf("\n%s: 4 lines", self->dv_xname);
    181 
    182 	dzattach(sc, NULL);
    183 	DELAY(10000);
    184 
    185 #if NDZKBD > 0
    186 	/* Don't touch this port if this is the console */
    187 	if (cn_tab->cn_dev != makedev(getmajor(dzopen), 0)) {
    188 		dz->rbuf = DZ_LPR_RX_ENABLE | (DZ_LPR_B4800 << 8)
    189 		    | DZ_LPR_8_BIT_CHAR;
    190 		daa.daa_line = 0;
    191 		daa.daa_flags =
    192 		    (cn_tab->cn_pri == CN_INTERNAL ? DZKBD_CONSOLE : 0);
    193 		config_found(self, &daa, dz_print);
    194 	}
    195 #endif
    196 #if NDZMS > 0
    197 	dz->rbuf = DZ_LPR_RX_ENABLE | (DZ_LPR_B4800 << 8) | DZ_LPR_7_BIT_CHAR \
    198 	    | DZ_LPR_PARENB | DZ_LPR_OPAR | 1 /* line */;
    199 	daa.daa_line = 1;
    200 	daa.daa_flags = 0;
    201 	config_found(self, &daa, dz_print);
    202 #endif
    203 	s = spltty();
    204 	dzrint(sc);
    205 	dzxint(sc);
    206 	splx(s);
    207 }
    208 
    209 int
    210 dzcngetc(dev_t dev)
    211 {
    212 	int c = 0;
    213 	int mino = minor(dev);
    214 	u_short rbuf;
    215 
    216 	do {
    217 		while ((dz->csr & 0x80) == 0)
    218 			; /* Wait for char */
    219 		rbuf = dz->rbuf;
    220 		if (((rbuf >> 8) & 3) != mino)
    221 			continue;
    222 		c = rbuf & 0x7f;
    223 	} while (c == 17 || c == 19);		/* ignore XON/XOFF */
    224 
    225 	if (c == 13)
    226 		c = 10;
    227 
    228 	return (c);
    229 }
    230 
    231 void
    232 dzcnprobe(struct consdev *cndev)
    233 {
    234 	extern	vaddr_t iospace;
    235 	int diagcons;
    236 	paddr_t ioaddr = 0x200A0000;
    237 
    238 	switch (vax_boardtype) {
    239 	case VAX_BTYP_410:
    240 	case VAX_BTYP_420:
    241 	case VAX_BTYP_43:
    242 		diagcons = (vax_confdata & 0x20 ? 3 : 0);
    243 		break;
    244 
    245 	case VAX_BTYP_46:
    246 	case VAX_BTYP_48:
    247 		diagcons = (vax_confdata & 0x100 ? 3 : 0);
    248 		break;
    249 
    250 	case VAX_BTYP_49:
    251 	case VAX_BTYP_53:
    252 		ioaddr = 0x25000000;
    253 		diagcons = 3;
    254 		break;
    255 
    256 	default:
    257 		cndev->cn_pri = CN_DEAD;
    258 		return;
    259 	}
    260 	if (diagcons)
    261 		cndev->cn_pri = CN_REMOTE;
    262 	else
    263 		cndev->cn_pri = CN_NORMAL;
    264 	cndev->cn_dev = makedev(getmajor(dzopen), diagcons);
    265 	(vaddr_t)dz = dz_regs = iospace;
    266 	ioaccess(iospace, ioaddr, 1);
    267 }
    268 
    269 void
    270 dzcninit(struct consdev *cndev)
    271 {
    272 	dz = (void*)dz_regs;
    273 
    274 	dz->csr = 0;    /* Disable scanning until initting is done */
    275 	dz->tcr = (1 << minor(cndev->cn_dev));    /* Turn on xmitter */
    276 	dz->csr = 0x20; /* Turn scanning back on */
    277 }
    278 
    279 
    280 void
    281 dzcnputc(dev_t dev, int	ch)
    282 {
    283 	int timeout = 1<<15;            /* don't hang the machine! */
    284 	int mino = minor(dev);
    285 	u_short tcr;
    286 
    287 	if (mfpr(PR_MAPEN) == 0)
    288 		return;
    289 
    290 	tcr = dz->tcr;	/* remember which lines to scan */
    291 	dz->tcr = (1 << mino);
    292 
    293 	while ((dz->csr & 0x8000) == 0) /* Wait until ready */
    294 		if (--timeout < 0)
    295 			break;
    296 	dz->tdr = ch;                    /* Put the  character */
    297 	timeout = 1<<15;
    298 	while ((dz->csr & 0x8000) == 0) /* Wait until ready */
    299 		if (--timeout < 0)
    300 			break;
    301 
    302 	dz->tcr = tcr;
    303 }
    304 
    305 void
    306 dzcnpollc(dev_t dev, int pollflag)
    307 {
    308 	static	u_char mask;
    309 
    310 	if (pollflag)
    311 		mask = vsbus_setmask(0);
    312 	else
    313 		vsbus_setmask(mask);
    314 }
    315 
    316 #if NDZKBD > 0 || NDZMS > 0
    317 int
    318 dzgetc(struct dz_linestate *ls)
    319 {
    320 	int line = ls->dz_line;
    321 	u_short rbuf;
    322 
    323 	for (;;) {
    324 		for(; (dz->csr & DZ_CSR_RX_DONE) == 0;);
    325 		rbuf = dz->rbuf;
    326 		if (((rbuf >> 8) & 3) == line)
    327 			return (rbuf & 0xff);
    328 	}
    329 }
    330 
    331 void
    332 dzputc(struct dz_linestate *ls, int ch)
    333 {
    334 	int line = 0; /* = ls->dz_line; */
    335 	u_short tcr;
    336 	int s;
    337 
    338 	/* if the dz has already been attached, the MI
    339 	   driver will do the transmitting: */
    340 	if (ls && ls->dz_sc) {
    341 		s = spltty();
    342 		putc(ch, &ls->dz_sc->sc_dz[line].dz_tty->t_outq);
    343 		tcr = dz->tcr;
    344 		if (!(tcr & (1 << line)))
    345 			dz->tcr = tcr | (1 << line);
    346 		dzxint(ls->dz_sc);
    347 		splx(s);
    348 		return;
    349 	}
    350 
    351 	/* use dzcnputc to do the transmitting: */
    352 	dzcnputc(makedev(getmajor(dzopen), line), ch);
    353 }
    354 #endif /* NDZKBD > 0 || NDZMS > 0 */
    355