Home | History | Annotate | Line # | Download | only in vsa
dz_vsbus.c revision 1.8
      1 /*	$NetBSD: dz_vsbus.c,v 1.8 1999/03/09 12:57:58 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 
     53 #include <machine/../vax/gencons.h>
     54 
     55 #include <vax/uba/dzreg.h>
     56 #include <vax/uba/dzvar.h>
     57 
     58 #include "ioconf.h"
     59 #include "lkc.h"
     60 
     61 static  int     dz_vsbus_match __P((struct device *, struct cfdata *, void *));
     62 static  void    dz_vsbus_attach __P((struct device *, struct device *, void *));
     63 static	int	dz_print __P((void *, const char *));
     64 static  void    txon __P((void));
     65 static  void    rxon __P((void));
     66 
     67 static	vaddr_t dz_regs; /* Used for console */
     68 
     69 struct  cfattach dz_vsbus_ca = {
     70         sizeof(struct dz_softc), dz_vsbus_match, dz_vsbus_attach
     71 };
     72 
     73 static void
     74 rxon()
     75 {
     76         vsbus_intr_enable(inr_sr);
     77 }
     78 
     79 static void
     80 txon()
     81 {
     82         vsbus_intr_enable(inr_st);
     83 }
     84 
     85 int
     86 dz_print(aux, name)
     87 	void *aux;
     88 	const char *name;
     89 {
     90 	if (name)
     91 		printf ("lkc at %s", name);
     92 	return (UNCONF);
     93 }
     94 
     95 static int
     96 dz_vsbus_match(parent, cf, aux)
     97         struct device *parent;
     98         struct cfdata *cf;
     99         void *aux;
    100 {
    101         struct vsbus_attach_args *va = aux;
    102         if (va->va_type == inr_sr)
    103                 return 1;
    104         return 0;
    105 }
    106 
    107 static void
    108 dz_vsbus_attach(parent, self, aux)
    109         struct device *parent, *self;
    110         void *aux;
    111 {
    112         struct  dz_softc *sc = (void *)self;
    113 
    114         sc->sc_dr.dr_csr = (void *)(dz_regs + 0);
    115         sc->sc_dr.dr_rbuf = (void *)(dz_regs + 4);
    116         sc->sc_dr.dr_dtr = (void *)(dz_regs + 9);
    117         sc->sc_dr.dr_break = (void *)(dz_regs + 13);
    118         sc->sc_dr.dr_tbuf = (void *)(dz_regs + 12);
    119         sc->sc_dr.dr_tcr = (void *)(dz_regs + 8);
    120         sc->sc_dr.dr_dcd = (void *)(dz_regs + 13);
    121         sc->sc_dr.dr_ring = (void *)(dz_regs + 13);
    122 
    123         sc->sc_type = DZ_DZV;
    124 
    125         sc->sc_txon = txon;
    126         sc->sc_rxon = rxon;
    127 	sc->sc_dsr = 0x0f; /* XXX check if VS has modem ctrl bits */
    128         vsbus_intr_attach(inr_sr, dzrint, 0);
    129         vsbus_intr_attach(inr_st, dzxint, 0);
    130         printf(": DC367");
    131 
    132         dzattach(sc);
    133 
    134 	if (((vax_confdata & 0x80) == 0) ||/* workstation, have lkc */
    135 	    (vax_boardtype == VAX_BTYP_48))
    136 		config_found(self, 0, dz_print);
    137 }
    138 
    139 /*----------------------------------------------------------------------*/
    140 
    141 #define REG(name)     short name; short X##name##X;
    142 static volatile struct {/* base address of DZ-controller: 0x200A0000 */
    143   REG(csr);           /* 00 Csr: control/status register */
    144   REG(rbuf);          /* 04 Rbuf/Lpr: receive buffer/line param reg. */
    145   REG(tcr);           /* 08 Tcr: transmit console register */
    146   REG(tdr);           /* 0C Msr/Tdr: modem status reg/transmit data reg */
    147   REG(lpr0);          /* 10 Lpr0: */
    148   REG(lpr1);          /* 14 Lpr0: */
    149   REG(lpr2);          /* 18 Lpr0: */
    150   REG(lpr3);          /* 1C Lpr0: */
    151 } *dz  = (void*)0x200A0000;
    152 #undef REG
    153 
    154 cons_decl(dz);
    155 
    156 int
    157 dzcngetc(dev)
    158 	dev_t dev;
    159 {
    160 	int c = 0;
    161 	int mino = minor(dev);
    162 	u_short rbuf;
    163 #if 0
    164 	u_char mask;
    165 
    166 	mask = vs_cpu->vc_intmsk;	/* save old state */
    167 	vs_cpu->vc_intmsk = 0;		/* disable all interrupts */
    168 #endif
    169 
    170 	do {
    171 		while ((dz->csr & 0x80) == 0)
    172 			; /* Wait for char */
    173 		rbuf = dz->rbuf;
    174 		if (((rbuf >> 8) & 3) != mino)
    175 			continue;
    176 		c = rbuf & 0x7f;
    177 	} while (c == 17 || c == 19);		/* ignore XON/XOFF */
    178 
    179 	if (c == 13)
    180 		c = 10;
    181 
    182 #if 0
    183 	vs_cpu->vc_intclr = 0x80;	/* clear te interrupt request */
    184 	vs_cpu->vc_intmsk = mask;	/* restore interrupt mask */
    185 #endif
    186 
    187 	return (c);
    188 }
    189 
    190 #define	DZMAJOR	1
    191 
    192 void
    193 dzcnprobe(cndev)
    194 	struct	consdev *cndev;
    195 {
    196 	extern	vaddr_t iospace;
    197 
    198 	switch (vax_boardtype) {
    199 	case VAX_BTYP_410:
    200 	case VAX_BTYP_420:
    201 	case VAX_BTYP_43:
    202 	case VAX_BTYP_46:
    203 	case VAX_BTYP_48:
    204 		cndev->cn_dev = makedev(DZMAJOR, 3);
    205 		dz_regs = iospace;
    206 		ioaccess(iospace, 0x200A0000, 1);
    207 		cndev->cn_pri = CN_NORMAL;
    208 		break;
    209 
    210 	default:
    211 		cndev->cn_pri = CN_DEAD;
    212 		break;
    213 	}
    214 
    215 	return;
    216 }
    217 
    218 void
    219 dzcninit(cndev)
    220 	struct	consdev *cndev;
    221 {
    222 	dz = (void*)dz_regs;
    223 
    224 	dz->csr = 0;    /* Disable scanning until initting is done */
    225 	dz->tcr = 8;    /* Turn off all but line 3's xmitter */
    226 	dz->csr = 0x20; /* Turn scanning back on */
    227 }
    228 
    229 
    230 void
    231 dzcnputc(dev,ch)
    232 	dev_t	dev;
    233 	int	ch;
    234 {
    235 	int timeout = 1<<15;            /* don't hang the machine! */
    236 	int mino = minor(dev);
    237 	u_short tcr;
    238 #if 0
    239 	u_char mask;
    240 #endif
    241 
    242 	if (mfpr(PR_MAPEN) == 0)
    243 		return;
    244 
    245 #if 0
    246 	mask = vs_cpu->vc_intmsk;	/* save old state */
    247 	vs_cpu->vc_intmsk = 0;		/* disable all interrupts */
    248 #endif
    249 	tcr = dz->tcr;	/* remember which lines to scan */
    250 	dz->tcr = (1 << mino);
    251 
    252 	while ((dz->csr & 0x8000) == 0) /* Wait until ready */
    253 		if (--timeout < 0)
    254 			break;
    255 	dz->tdr = ch;                    /* Put the  character */
    256 
    257 	dz->tcr = tcr;
    258 #if 0
    259 	vs_cpu->vc_intmsk = mask;	/* restore interrupt mask */
    260 #endif
    261 }
    262 
    263 void
    264 dzcnpollc(dev, pollflag)
    265 	dev_t dev;
    266 	int pollflag;
    267 {
    268 }
    269 
    270 #if NLKC
    271 cons_decl(lkc);
    272 
    273 void
    274 lkccninit(cndev)
    275 	struct	consdev *cndev;
    276 {
    277 	dz = (void*)dz_regs;
    278 
    279 	dz->csr = 0;    /* Disable scanning until initting is done */
    280 	dz->tcr = 1;    /* Turn off all but line 0's xmitter */
    281 	dz->rbuf = 0x1c18; /* XXX */
    282 	dz->csr = 0x20; /* Turn scanning back on */
    283 }
    284 
    285 int
    286 lkccngetc(dev)
    287 	dev_t dev;
    288 {
    289 	int lkc_decode(int);
    290 	int c;
    291 #if 0
    292 	u_char mask;
    293 
    294 	mask = vs_cpu->vc_intmsk;	/* save old state */
    295 	vs_cpu->vc_intmsk = 0;		/* disable all interrupts */
    296 #endif
    297 
    298 loop:
    299 	while ((dz->csr & 0x80) == 0)
    300 		; /* Wait for char */
    301 
    302 	c = lkc_decode(dz->rbuf & 255);
    303 	if (c < 1)
    304 		goto loop;
    305 
    306 #if 0
    307 	vs_cpu->vc_intclr = 0x80;	/* clear te interrupt request */
    308 	vs_cpu->vc_intmsk = mask;	/* restore interrupt mask */
    309 #endif
    310 
    311 	return (c);
    312 }
    313 #endif
    314