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