Home | History | Annotate | Line # | Download | only in vsa
dz_vsbus.c revision 1.2
      1  1.2  ragge /*	$NetBSD: dz_vsbus.c,v 1.2 1998/05/21 13:02:21 ragge Exp $ */
      2  1.1  ragge /*
      3  1.1  ragge  * Copyright (c) 1998 Ludd, University of Lule}, Sweden.
      4  1.1  ragge  * All rights reserved.
      5  1.1  ragge  *
      6  1.1  ragge  * Redistribution and use in source and binary forms, with or without
      7  1.1  ragge  * modification, are permitted provided that the following conditions
      8  1.1  ragge  * are met:
      9  1.1  ragge  * 1. Redistributions of source code must retain the above copyright
     10  1.1  ragge  *    notice, this list of conditions and the following disclaimer.
     11  1.1  ragge  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.1  ragge  *    notice, this list of conditions and the following disclaimer in the
     13  1.1  ragge  *    documentation and/or other materials provided with the distribution.
     14  1.1  ragge  * 3. All advertising materials mentioning features or use of this software
     15  1.1  ragge  *    must display the following acknowledgement:
     16  1.1  ragge  *      This product includes software developed at Ludd, University of
     17  1.1  ragge  *      Lule}, Sweden and its contributors.
     18  1.1  ragge  * 4. The name of the author may not be used to endorse or promote products
     19  1.1  ragge  *    derived from this software without specific prior written permission
     20  1.1  ragge  *
     21  1.1  ragge  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  1.1  ragge  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  1.1  ragge  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  1.1  ragge  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  1.1  ragge  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  1.1  ragge  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  1.1  ragge  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  1.1  ragge  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  1.1  ragge  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  1.1  ragge  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  1.1  ragge  */
     32  1.1  ragge 
     33  1.1  ragge 
     34  1.1  ragge 
     35  1.1  ragge #include <sys/param.h>
     36  1.1  ragge #include <sys/proc.h>
     37  1.1  ragge #include <sys/systm.h>
     38  1.1  ragge #include <sys/ioctl.h>
     39  1.1  ragge #include <sys/tty.h>
     40  1.1  ragge #include <sys/file.h>
     41  1.1  ragge #include <sys/conf.h>
     42  1.1  ragge #include <sys/device.h>
     43  1.1  ragge #include <sys/reboot.h>
     44  1.1  ragge 
     45  1.1  ragge #include <dev/cons.h>
     46  1.1  ragge 
     47  1.1  ragge #include <machine/mtpr.h>
     48  1.1  ragge #include <machine/sid.h>
     49  1.1  ragge #include <machine/uvax.h>
     50  1.1  ragge #include <machine/vsbus.h>
     51  1.1  ragge #include <machine/../vax/gencons.h>
     52  1.1  ragge 
     53  1.1  ragge #include <vax/uba/dzreg.h>
     54  1.1  ragge #include <vax/uba/dzvar.h>
     55  1.1  ragge 
     56  1.1  ragge #include "ioconf.h"
     57  1.1  ragge 
     58  1.1  ragge static  int     dz_vsbus_match __P((struct device *, struct cfdata *, void *));
     59  1.1  ragge static  void    dz_vsbus_attach __P((struct device *, struct device *, void *));
     60  1.1  ragge static  void    txon __P((void));
     61  1.1  ragge static  void    rxon __P((void));
     62  1.1  ragge 
     63  1.1  ragge struct  cfattach dz_vsbus_ca = {
     64  1.1  ragge         sizeof(struct dz_softc), dz_vsbus_match, dz_vsbus_attach
     65  1.1  ragge };
     66  1.1  ragge 
     67  1.1  ragge static void
     68  1.1  ragge rxon()
     69  1.1  ragge {
     70  1.1  ragge         vsbus_intr_enable(INR_SR);
     71  1.1  ragge }
     72  1.1  ragge 
     73  1.1  ragge static void
     74  1.1  ragge txon()
     75  1.1  ragge {
     76  1.1  ragge         vsbus_intr_enable(INR_ST);
     77  1.1  ragge }
     78  1.1  ragge 
     79  1.1  ragge static int
     80  1.1  ragge dz_vsbus_match(parent, cf, aux)
     81  1.1  ragge         struct device *parent;
     82  1.1  ragge         struct cfdata *cf;
     83  1.1  ragge         void *aux;
     84  1.1  ragge {
     85  1.1  ragge         struct vsbus_attach_args *va = aux;
     86  1.1  ragge         if (va->va_type == INR_SR)
     87  1.1  ragge                 return 1;
     88  1.1  ragge         return 0;
     89  1.1  ragge }
     90  1.1  ragge 
     91  1.1  ragge static void
     92  1.1  ragge dz_vsbus_attach(parent, self, aux)
     93  1.1  ragge         struct device *parent, *self;
     94  1.1  ragge         void *aux;
     95  1.1  ragge {
     96  1.1  ragge         struct  dz_softc *sc = (void *)self;
     97  1.1  ragge 
     98  1.1  ragge         sc->sc_dr.dr_csr = (void *)(dz_regs + 0);
     99  1.1  ragge         sc->sc_dr.dr_rbuf = (void *)(dz_regs + 4);
    100  1.1  ragge         sc->sc_dr.dr_dtr = (void *)(dz_regs + 9);
    101  1.1  ragge         sc->sc_dr.dr_break = (void *)(dz_regs + 13);
    102  1.1  ragge         sc->sc_dr.dr_tbuf = (void *)(dz_regs + 12);
    103  1.1  ragge         sc->sc_dr.dr_tcr = (void *)(dz_regs + 8);
    104  1.1  ragge         sc->sc_dr.dr_dcd = (void *)(dz_regs + 13);
    105  1.1  ragge         sc->sc_dr.dr_ring = (void *)(dz_regs + 13);
    106  1.1  ragge 
    107  1.1  ragge         sc->sc_type = DZ_DZV;
    108  1.1  ragge 
    109  1.1  ragge         sc->sc_txon = txon;
    110  1.1  ragge         sc->sc_rxon = rxon;
    111  1.2  ragge 	sc->sc_dsr = 0x0f; /* XXX check if VS has modem ctrl bits */
    112  1.1  ragge         vsbus_intr_attach(INR_SR, dzrint, 0);
    113  1.1  ragge         vsbus_intr_attach(INR_ST, dzxint, 0);
    114  1.1  ragge         printf(": DC367");
    115  1.1  ragge 
    116  1.1  ragge         dzattach(sc);
    117  1.1  ragge }
    118  1.1  ragge 
    119  1.1  ragge /*----------------------------------------------------------------------*/
    120  1.1  ragge 
    121  1.1  ragge #define REG(name)     short name; short X##name##X;
    122  1.1  ragge static volatile struct {/* base address of DZ-controller: 0x200A0000 */
    123  1.1  ragge   REG(csr);           /* 00 Csr: control/status register */
    124  1.1  ragge   REG(rbuf);          /* 04 Rbuf/Lpr: receive buffer/line param reg. */
    125  1.1  ragge   REG(tcr);           /* 08 Tcr: transmit console register */
    126  1.1  ragge   REG(tdr);           /* 0C Msr/Tdr: modem status reg/transmit data reg */
    127  1.1  ragge   REG(lpr0);          /* 10 Lpr0: */
    128  1.1  ragge   REG(lpr1);          /* 14 Lpr0: */
    129  1.1  ragge   REG(lpr2);          /* 18 Lpr0: */
    130  1.1  ragge   REG(lpr3);          /* 1C Lpr0: */
    131  1.1  ragge } *dz  = (void*)0x200A0000;
    132  1.1  ragge #undef REG
    133  1.1  ragge 
    134  1.1  ragge cons_decl(dz);
    135  1.1  ragge 
    136  1.1  ragge int
    137  1.1  ragge dzcngetc(dev)
    138  1.1  ragge 	dev_t dev;
    139  1.1  ragge {
    140  1.1  ragge 	int c;
    141  1.1  ragge 
    142  1.1  ragge 	do {
    143  1.1  ragge 		while ((dz->csr & 0x80) == 0)
    144  1.1  ragge 			; /* Wait for char */
    145  1.1  ragge 		c = dz->rbuf & 0x7f;
    146  1.1  ragge 	} while (c == 17 || c == 19);		/* ignore XON/XOFF */
    147  1.1  ragge 
    148  1.1  ragge 	if (c == 13)
    149  1.1  ragge 		c = 10;
    150  1.1  ragge 	return (c);
    151  1.1  ragge }
    152  1.1  ragge 
    153  1.1  ragge #define	DZMAJOR	1
    154  1.1  ragge 
    155  1.1  ragge void
    156  1.1  ragge dzcnprobe(cndev)
    157  1.1  ragge 	struct	consdev *cndev;
    158  1.1  ragge {
    159  1.1  ragge 
    160  1.1  ragge 	switch (vax_boardtype) {
    161  1.1  ragge 	case VAX_BTYP_410:
    162  1.1  ragge 	case VAX_BTYP_420:
    163  1.1  ragge 	case VAX_BTYP_43:
    164  1.1  ragge 		cndev->cn_dev = makedev(DZMAJOR, 3);
    165  1.1  ragge 		cndev->cn_pri = CN_NORMAL;
    166  1.1  ragge 		break;
    167  1.1  ragge 
    168  1.1  ragge 	default:
    169  1.1  ragge 		cndev->cn_pri = CN_DEAD;
    170  1.1  ragge 		break;
    171  1.1  ragge 	}
    172  1.1  ragge 
    173  1.1  ragge 	return;
    174  1.1  ragge }
    175  1.1  ragge 
    176  1.1  ragge void
    177  1.1  ragge dzcninit(cndev)
    178  1.1  ragge 	struct	consdev *cndev;
    179  1.1  ragge {
    180  1.1  ragge 	dz = (void*)dz_regs;
    181  1.1  ragge 
    182  1.1  ragge 	dz->csr = 0;    /* Disable scanning until initting is done */
    183  1.1  ragge 	dz->rbuf = 0;   /* Turn off line 0's receiver */
    184  1.1  ragge 	dz->rbuf = 1;   /* Turn off line 1's receiver */
    185  1.1  ragge 	dz->rbuf = 2;   /* Turn off line 2's receiver */
    186  1.1  ragge 	                /* Leave line 3 alone */
    187  1.1  ragge 	dz->tcr = 8;    /* Turn off all but line 3's xmitter */
    188  1.1  ragge 	dz->csr = 0x20; /* Turn scanning back on */
    189  1.1  ragge }
    190  1.1  ragge 
    191  1.1  ragge 
    192  1.1  ragge void
    193  1.1  ragge dzcnputc(dev,ch)
    194  1.1  ragge 	dev_t	dev;
    195  1.1  ragge 	int	ch;
    196  1.1  ragge {
    197  1.1  ragge 	int timeout = 1<<15;            /* don't hang the machine! */
    198  1.1  ragge 
    199  1.1  ragge 	if (mfpr(PR_MAPEN) == 0)
    200  1.1  ragge 		return;
    201  1.1  ragge 
    202  1.1  ragge 	while ((dz->csr & 0x8000) == 0) /* Wait until ready */
    203  1.1  ragge 		if (--timeout < 0)
    204  1.1  ragge 			break;
    205  1.1  ragge 	dz->tdr = ch;                    /* Put the  character */
    206  1.2  ragge }
    207  1.2  ragge 
    208  1.2  ragge void
    209  1.2  ragge dzcnpollc(dev, pollflag)
    210  1.2  ragge 	dev_t dev;
    211  1.2  ragge 	int pollflag;
    212  1.2  ragge {
    213  1.2  ragge 	if (pollflag)  {
    214  1.2  ragge 		vsbus_intr_disable(INR_SR);
    215  1.2  ragge 		vsbus_intr_disable(INR_ST);
    216  1.2  ragge 	} else {
    217  1.2  ragge 		vsbus_intr_enable(INR_SR);
    218  1.2  ragge 		vsbus_intr_enable(INR_ST);
    219  1.2  ragge 	}
    220  1.1  ragge }
    221