Home | History | Annotate | Line # | Download | only in vsa
dz_vsbus.c revision 1.3
      1 /*	$NetBSD: dz_vsbus.c,v 1.3 1998/05/23 12:49:31 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/../vax/gencons.h>
     52 
     53 #include <vax/uba/dzreg.h>
     54 #include <vax/uba/dzvar.h>
     55 
     56 #include "ioconf.h"
     57 
     58 static  int     dz_vsbus_match __P((struct device *, struct cfdata *, void *));
     59 static  void    dz_vsbus_attach __P((struct device *, struct device *, void *));
     60 static  void    txon __P((void));
     61 static  void    rxon __P((void));
     62 
     63 struct  cfattach dz_vsbus_ca = {
     64         sizeof(struct dz_softc), dz_vsbus_match, dz_vsbus_attach
     65 };
     66 
     67 static void
     68 rxon()
     69 {
     70         vsbus_intr_enable(INR_SR);
     71 }
     72 
     73 static void
     74 txon()
     75 {
     76         vsbus_intr_enable(INR_ST);
     77 }
     78 
     79 static int
     80 dz_vsbus_match(parent, cf, aux)
     81         struct device *parent;
     82         struct cfdata *cf;
     83         void *aux;
     84 {
     85         struct vsbus_attach_args *va = aux;
     86         if (va->va_type == INR_SR)
     87                 return 1;
     88         return 0;
     89 }
     90 
     91 static void
     92 dz_vsbus_attach(parent, self, aux)
     93         struct device *parent, *self;
     94         void *aux;
     95 {
     96         struct  dz_softc *sc = (void *)self;
     97 
     98         sc->sc_dr.dr_csr = (void *)(dz_regs + 0);
     99         sc->sc_dr.dr_rbuf = (void *)(dz_regs + 4);
    100         sc->sc_dr.dr_dtr = (void *)(dz_regs + 9);
    101         sc->sc_dr.dr_break = (void *)(dz_regs + 13);
    102         sc->sc_dr.dr_tbuf = (void *)(dz_regs + 12);
    103         sc->sc_dr.dr_tcr = (void *)(dz_regs + 8);
    104         sc->sc_dr.dr_dcd = (void *)(dz_regs + 13);
    105         sc->sc_dr.dr_ring = (void *)(dz_regs + 13);
    106 
    107         sc->sc_type = DZ_DZV;
    108 
    109         sc->sc_txon = txon;
    110         sc->sc_rxon = rxon;
    111 	sc->sc_dsr = 0x0f; /* XXX check if VS has modem ctrl bits */
    112         vsbus_intr_attach(INR_SR, dzrint, 0);
    113         vsbus_intr_attach(INR_ST, dzxint, 0);
    114         printf(": DC367");
    115 
    116         dzattach(sc);
    117 }
    118 
    119 /*----------------------------------------------------------------------*/
    120 
    121 #define REG(name)     short name; short X##name##X;
    122 static volatile struct {/* base address of DZ-controller: 0x200A0000 */
    123   REG(csr);           /* 00 Csr: control/status register */
    124   REG(rbuf);          /* 04 Rbuf/Lpr: receive buffer/line param reg. */
    125   REG(tcr);           /* 08 Tcr: transmit console register */
    126   REG(tdr);           /* 0C Msr/Tdr: modem status reg/transmit data reg */
    127   REG(lpr0);          /* 10 Lpr0: */
    128   REG(lpr1);          /* 14 Lpr0: */
    129   REG(lpr2);          /* 18 Lpr0: */
    130   REG(lpr3);          /* 1C Lpr0: */
    131 } *dz  = (void*)0x200A0000;
    132 #undef REG
    133 
    134 cons_decl(dz);
    135 
    136 int
    137 dzcngetc(dev)
    138 	dev_t dev;
    139 {
    140 	int c;
    141 	u_char mask;
    142 
    143 	mask = vs_cpu->vc_intmsk;	/* save old state */
    144 	vs_cpu->vc_intmsk = 0;		/* disable all interrupts */
    145 
    146 	do {
    147 		while ((dz->csr & 0x80) == 0)
    148 			; /* Wait for char */
    149 		c = dz->rbuf & 0x7f;
    150 	} while (c == 17 || c == 19);		/* ignore XON/XOFF */
    151 
    152 	if (c == 13)
    153 		c = 10;
    154 
    155 	vs_cpu->vc_intclr = 0x80;	/* clear te interrupt request */
    156 	vs_cpu->vc_intmsk = mask;	/* restore interrupt mask */
    157 
    158 	return (c);
    159 }
    160 
    161 #define	DZMAJOR	1
    162 
    163 void
    164 dzcnprobe(cndev)
    165 	struct	consdev *cndev;
    166 {
    167 
    168 	switch (vax_boardtype) {
    169 	case VAX_BTYP_410:
    170 	case VAX_BTYP_420:
    171 	case VAX_BTYP_43:
    172 		cndev->cn_dev = makedev(DZMAJOR, 3);
    173 		cndev->cn_pri = CN_NORMAL;
    174 		break;
    175 
    176 	default:
    177 		cndev->cn_pri = CN_DEAD;
    178 		break;
    179 	}
    180 
    181 	return;
    182 }
    183 
    184 void
    185 dzcninit(cndev)
    186 	struct	consdev *cndev;
    187 {
    188 	dz = (void*)dz_regs;
    189 
    190 	dz->csr = 0;    /* Disable scanning until initting is done */
    191 	dz->rbuf = 0;   /* Turn off line 0's receiver */
    192 	dz->rbuf = 1;   /* Turn off line 1's receiver */
    193 	dz->rbuf = 2;   /* Turn off line 2's receiver */
    194 	                /* Leave line 3 alone */
    195 	dz->tcr = 8;    /* Turn off all but line 3's xmitter */
    196 	dz->csr = 0x20; /* Turn scanning back on */
    197 }
    198 
    199 
    200 void
    201 dzcnputc(dev,ch)
    202 	dev_t	dev;
    203 	int	ch;
    204 {
    205 	int timeout = 1<<15;            /* don't hang the machine! */
    206 	u_short tcr;
    207 	u_char mask;
    208 
    209 	if (mfpr(PR_MAPEN) == 0)
    210 		return;
    211 
    212 	mask = vs_cpu->vc_intmsk;	/* save old state */
    213 	vs_cpu->vc_intmsk = 0;		/* disable all interrupts */
    214 	tcr = dz->tcr;	/* remember which lines to scan */
    215 	dz->tcr = 8; /* XXX */
    216 
    217 	while ((dz->csr & 0x8000) == 0) /* Wait until ready */
    218 		if (--timeout < 0)
    219 			break;
    220 	dz->tdr = ch;                    /* Put the  character */
    221 
    222 	dz->tcr = tcr;
    223 	vs_cpu->vc_intmsk = mask;	/* restore interrupt mask */
    224 }
    225 
    226 void
    227 dzcnpollc(dev, pollflag)
    228 	dev_t dev;
    229 	int pollflag;
    230 {
    231 }
    232