Home | History | Annotate | Line # | Download | only in vsa
dz_vsbus.c revision 1.42
      1 /*	$NetBSD: dz_vsbus.c,v 1.42 2010/12/14 23:31:16 matt 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 #include <sys/cdefs.h>
     34 __KERNEL_RCSID(0, "$NetBSD: dz_vsbus.c,v 1.42 2010/12/14 23:31:16 matt Exp $");
     35 
     36 #include <sys/param.h>
     37 #include <sys/systm.h>
     38 #include <sys/conf.h>
     39 #include <sys/cpu.h>
     40 #include <sys/device.h>
     41 #include <sys/file.h>
     42 #include <sys/ioctl.h>
     43 #include <sys/proc.h>
     44 #include <sys/tty.h>
     45 
     46 #include <dev/cons.h>
     47 
     48 #include <machine/sid.h>
     49 #include <machine/vsbus.h>
     50 #include <machine/scb.h>
     51 
     52 #include <arch/vax/vax/gencons.h>
     53 
     54 #include <dev/dec/dzreg.h>
     55 #include <dev/dec/dzvar.h>
     56 
     57 #include "ioconf.h"
     58 #include "locators.h"
     59 #include "dzkbd.h"
     60 #include "dzms.h"
     61 #include "opt_cputype.h"
     62 
     63 #if NDZKBD > 0 || NDZMS > 0
     64 #include <dev/dec/dzkbdvar.h>
     65 
     66 #if 0
     67 static	struct dz_linestate dz_conslinestate = { NULL, -1, NULL, NULL, NULL };
     68 #endif
     69 #endif
     70 
     71 static  int     dz_vsbus_match(device_t, cfdata_t, void *);
     72 static  void    dz_vsbus_attach(device_t, device_t, void *);
     73 
     74 static	vaddr_t dz_regs; /* Used for console */
     75 
     76 CFATTACH_DECL_NEW(dz_vsbus, sizeof(struct dz_softc),
     77     dz_vsbus_match, dz_vsbus_attach, NULL, NULL);
     78 
     79 #define REG(name)     short name; short X##name##X;
     80 static volatile struct ss_dz {/* base address of DZ-controller: 0x200A0000 */
     81 	REG(csr);	/* 00 Csr: control/status register */
     82 	REG(rbuf);	/* 04 Rbuf/Lpr: receive buffer/line param reg. */
     83 	REG(tcr);	/* 08 Tcr: transmit console register */
     84 	REG(tdr);	/* 0C Msr/Tdr: modem status reg/transmit data reg */
     85 	REG(lpr0);	/* 10 Lpr0: */
     86 	REG(lpr1);	/* 14 Lpr0: */
     87 	REG(lpr2);	/* 18 Lpr0: */
     88 	REG(lpr3);	/* 1C Lpr0: */
     89 } *dz;
     90 #undef REG
     91 
     92 cons_decl(dz);
     93 
     94 #if NDZKBD > 0 || NDZMS > 0
     95 static int
     96 dz_print(void *aux, const char *name)
     97 {
     98 #if 0
     99 #if NDZKBD > 0 || NDZMS > 0
    100 	struct dz_attach_args *dz_args = aux;
    101 	if (name == NULL) {
    102 		aprint_normal (" line %d", dz_args->line);
    103 		if (dz_args->hwflags & DZ_HWFLAG_CONSOLE)
    104 			aprint_normal (" (console)");
    105 	}
    106 	return (QUIET);
    107 #else
    108 	if (name)
    109 		aprint_normal ("lkc at %s", name);
    110 	return (UNCONF);
    111 #endif
    112 #endif
    113 	return (UNCONF);
    114 }
    115 #endif
    116 
    117 static int
    118 dz_vsbus_match(device_t parent, cfdata_t cf, void *aux)
    119 {
    120 	struct vsbus_attach_args * const va = aux;
    121 	struct ss_dz *dzP;
    122 	short i;
    123 
    124 #if VAX53 || VAX49 || VAXANY
    125 	if (vax_boardtype == VAX_BTYP_53 || vax_boardtype == VAX_BTYP_49)
    126 		if (cf->cf_loc[VSBUSCF_CSR] != 0x25000000)
    127 			return 0; /* Ugly */
    128 #endif
    129 
    130 	dzP = (struct ss_dz *)va->va_addr;
    131 	i = dzP->tcr;
    132 	dzP->csr = DZ_CSR_MSE|DZ_CSR_TXIE;
    133 	dzP->tcr = 0;
    134 	DELAY(1000);
    135 	dzP->tcr = 1;
    136 	DELAY(100000);
    137 	dzP->tcr = i;
    138 
    139 	/* If the device doesn't exist, no interrupt has been generated */
    140 	return 1;
    141 }
    142 
    143 static void
    144 dz_vsbus_attach(device_t parent, device_t self, void *aux)
    145 {
    146 	struct dz_softc * const sc = device_private(self);
    147 	struct vsbus_attach_args * const va = aux;
    148 #if NDZKBD > 0
    149 	extern const struct cdevsw dz_cdevsw;
    150 #endif
    151 #if NDZKBD > 0 || NDZMS > 0
    152 	struct dzkm_attach_args daa;
    153 #endif
    154 	int s, consline;
    155 
    156 	sc->sc_dev = self;
    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 (cn_tab->cn_dev != makedev(cdevsw_lookup_major(&dz_cdevsw), 0)) {
    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_dr.dr_firstreg = 0;
    178 	sc->sc_dr.dr_winsize = 14;
    179 
    180 	sc->sc_type = DZ_DZV;
    181 
    182 	sc->sc_dsr = 0x0f; /* XXX check if VS has modem ctrl bits */
    183 
    184 	scb_vecalloc(va->va_cvec, dzxint, sc, SCB_ISTACK, &sc->sc_tintrcnt);
    185 	scb_vecalloc(va->va_cvec - 4, dzrint, sc, SCB_ISTACK, &sc->sc_rintrcnt);
    186 
    187 	aprint_normal("\n");
    188 	aprint_normal_dev(self, "4 lines");
    189 
    190 	dzattach(sc, NULL, consline);
    191 	DELAY(10000);
    192 
    193 	if (consline != -1)
    194 		cn_set_magic("\033D"); /* set VAX DDB escape sequence */
    195 
    196 #if NDZKBD > 0
    197 	/* Don't touch this port if this is the console */
    198 	if (cn_tab->cn_dev != makedev(cdevsw_lookup_major(&dz_cdevsw), 0)) {
    199 		dz->rbuf = DZ_LPR_RX_ENABLE | (DZ_LPR_B4800 << 8)
    200 		    | DZ_LPR_8_BIT_CHAR;
    201 		daa.daa_line = 0;
    202 		daa.daa_flags =
    203 		    (cn_tab->cn_pri == CN_INTERNAL ? DZKBD_CONSOLE : 0);
    204 		config_found(self, &daa, dz_print);
    205 	}
    206 #endif
    207 #if NDZMS > 0
    208 	dz->rbuf = DZ_LPR_RX_ENABLE | (DZ_LPR_B4800 << 8) | DZ_LPR_8_BIT_CHAR \
    209 	    | DZ_LPR_PARENB | DZ_LPR_OPAR | 1 /* line */;
    210 	daa.daa_line = 1;
    211 	daa.daa_flags = 0;
    212 	config_found(self, &daa, dz_print);
    213 #endif
    214 	s = spltty();
    215 	dzrint(sc);
    216 	dzxint(sc);
    217 	splx(s);
    218 }
    219 
    220 int
    221 dzcngetc(dev_t dev)
    222 {
    223 	int c = 0, s;
    224 	int mino = minor(dev);
    225 	u_short rbuf;
    226 
    227 	s = spltty();
    228 	do {
    229 		while ((dz->csr & 0x80) == 0)
    230 			; /* Wait for char */
    231 		rbuf = dz->rbuf;
    232 		if (((rbuf >> 8) & 3) != mino)
    233 			continue;
    234 		c = rbuf & 0x7f;
    235 	} while (c == 17 || c == 19);		/* ignore XON/XOFF */
    236 	splx(s);
    237 
    238 	if (c == 13)
    239 		c = 10;
    240 
    241 	return (c);
    242 }
    243 
    244 void
    245 dzcnprobe(struct consdev *cndev)
    246 {
    247 	extern	vaddr_t iospace;
    248 	int diagcons;
    249 	paddr_t ioaddr = 0x200A0000;
    250 	extern const struct cdevsw dz_cdevsw;
    251 
    252 	switch (vax_boardtype) {
    253 	case VAX_BTYP_410:
    254 	case VAX_BTYP_420:
    255 	case VAX_BTYP_43:
    256 		diagcons = (vax_confdata & 0x20 ? 3 : 0);
    257 		break;
    258 
    259 	case VAX_BTYP_46:
    260 	case VAX_BTYP_48:
    261 		diagcons = (vax_confdata & 0x100 ? 3 : 0);
    262 		break;
    263 
    264 	case VAX_BTYP_49:
    265 		ioaddr = 0x25000000;
    266 		diagcons = (vax_confdata & 8 ? 3 : 0);
    267 		break;
    268 
    269 	case VAX_BTYP_53:
    270 		ioaddr = 0x25000000;
    271 		diagcons = 3;
    272 		break;
    273 
    274 	default:
    275 		cndev->cn_pri = CN_DEAD;
    276 		return;
    277 	}
    278 	if (diagcons)
    279 		cndev->cn_pri = CN_REMOTE;
    280 	else
    281 		cndev->cn_pri = CN_NORMAL;
    282 	cndev->cn_dev = makedev(cdevsw_lookup_major(&dz_cdevsw), diagcons);
    283 	dz_regs = iospace;
    284 	dz = (void *)dz_regs;
    285 	ioaccess(iospace, ioaddr, 1);
    286 	dz->csr = 0;    /* Disable scanning until initting is done */
    287 	dz->tcr = (1 << minor(cndev->cn_dev));    /* Turn on xmitter */
    288 	dz->csr = 0x20; /* Turn scanning back on */
    289 }
    290 
    291 void
    292 dzcninit(struct consdev *cndev)
    293 {
    294 	dz = (void*)dz_regs;
    295 
    296 	dz->csr = 0;    /* Disable scanning until initting is done */
    297 	dz->tcr = (1 << minor(cndev->cn_dev));    /* Turn on xmitter */
    298 	dz->csr = 0x20; /* Turn scanning back on */
    299 }
    300 
    301 
    302 void
    303 dzcnputc(dev_t dev, int	ch)
    304 {
    305 	int timeout = 1<<15;            /* don't hang the machine! */
    306 	int mino = minor(dev);
    307 	int s;
    308 	u_short tcr;
    309 
    310 	if (mfpr(PR_MAPEN) == 0)
    311 		return;
    312 
    313 	s = spltty();
    314 	tcr = dz->tcr;	/* remember which lines to scan */
    315 	dz->tcr = (1 << mino);
    316 
    317 	while ((dz->csr & 0x8000) == 0) /* Wait until ready */
    318 		if (--timeout < 0)
    319 			break;
    320 	dz->tdr = ch;                    /* Put the  character */
    321 	timeout = 1<<15;
    322 	while ((dz->csr & 0x8000) == 0) /* Wait until ready */
    323 		if (--timeout < 0)
    324 			break;
    325 
    326 	dz->tcr = tcr;
    327 	splx(s);
    328 }
    329 
    330 void
    331 dzcnpollc(dev_t dev, int pollflag)
    332 {
    333 	static	u_char mask;
    334 
    335 	if (pollflag)
    336 		mask = vsbus_setmask(0);
    337 	else
    338 		vsbus_setmask(mask);
    339 }
    340 
    341 #if NDZKBD > 0 || NDZMS > 0
    342 int
    343 dzgetc(struct dz_linestate *ls)
    344 {
    345 	int line = ls->dz_line;
    346 	int s;
    347 	u_short rbuf;
    348 
    349 	s = spltty();
    350 	for (;;) {
    351 		for(; (dz->csr & DZ_CSR_RX_DONE) == 0;);
    352 		rbuf = dz->rbuf;
    353 		if (((rbuf >> 8) & 3) == line) {
    354 			splx(s);
    355 			return (rbuf & 0xff);
    356 		}
    357 	}
    358 }
    359 
    360 void
    361 dzputc(struct dz_linestate *ls, int ch)
    362 {
    363 	int line;
    364 	u_short tcr;
    365 	int s;
    366 	extern const struct cdevsw dz_cdevsw;
    367 
    368 	/* if the dz has already been attached, the MI
    369 	   driver will do the transmitting: */
    370 	if (ls && ls->dz_sc) {
    371 		s = spltty();
    372 		line = ls->dz_line;
    373 		putc(ch, &ls->dz_tty->t_outq);
    374 		tcr = dz->tcr;
    375 		if (!(tcr & (1 << line)))
    376 			dz->tcr = tcr | (1 << line);
    377 		dzxint(ls->dz_sc);
    378 		splx(s);
    379 		return;
    380 	}
    381 
    382 	/* use dzcnputc to do the transmitting: */
    383 	dzcnputc(makedev(cdevsw_lookup_major(&dz_cdevsw), 0), ch);
    384 }
    385 #endif /* NDZKBD > 0 || NDZMS > 0 */
    386