Home | History | Annotate | Line # | Download | only in dev
zs_pcc.c revision 1.1
      1  1.1  chuck /*	$NetBSD: zs_pcc.c,v 1.1 1996/04/26 19:00:24 chuck Exp $	*/
      2  1.1  chuck 
      3  1.1  chuck /*
      4  1.1  chuck  * Copyright (c) 1996 Jason R. Thorpe
      5  1.1  chuck  * Copyright (c) 1995 Gordon W. Ross
      6  1.1  chuck  * All rights reserved.
      7  1.1  chuck  *
      8  1.1  chuck  * Redistribution and use in source and binary forms, with or without
      9  1.1  chuck  * modification, are permitted provided that the following conditions
     10  1.1  chuck  * are met:
     11  1.1  chuck  * 1. Redistributions of source code must retain the above copyright
     12  1.1  chuck  *    notice, this list of conditions and the following disclaimer.
     13  1.1  chuck  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1  chuck  *    notice, this list of conditions and the following disclaimer in the
     15  1.1  chuck  *    documentation and/or other materials provided with the distribution.
     16  1.1  chuck  * 3. The name of the author may not be used to endorse or promote products
     17  1.1  chuck  *    derived from this software without specific prior written permission.
     18  1.1  chuck  * 4. All advertising materials mentioning features or use of this software
     19  1.1  chuck  *    must display the following acknowledgement:
     20  1.1  chuck  *      This product includes software developed by Gordon Ross
     21  1.1  chuck  *
     22  1.1  chuck  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  1.1  chuck  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  1.1  chuck  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  1.1  chuck  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  1.1  chuck  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  1.1  chuck  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  1.1  chuck  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  1.1  chuck  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  1.1  chuck  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  1.1  chuck  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  1.1  chuck  */
     33  1.1  chuck 
     34  1.1  chuck /*
     35  1.1  chuck  * Zilog Z8530 Dual UART driver (machine-dependent part)
     36  1.1  chuck  *
     37  1.1  chuck  * Runs two serial lines per chip using slave drivers.
     38  1.1  chuck  * Plain tty/async lines use the zs_async slave.
     39  1.1  chuck  *
     40  1.1  chuck  * Modified for NetBSD/mvme68k by Jason R. Thorpe <thorpej (at) NetBSD.ORG>
     41  1.1  chuck  */
     42  1.1  chuck 
     43  1.1  chuck #include <sys/param.h>
     44  1.1  chuck #include <sys/systm.h>
     45  1.1  chuck #include <sys/proc.h>
     46  1.1  chuck #include <sys/device.h>
     47  1.1  chuck #include <sys/conf.h>
     48  1.1  chuck #include <sys/file.h>
     49  1.1  chuck #include <sys/ioctl.h>
     50  1.1  chuck #include <sys/tty.h>
     51  1.1  chuck #include <sys/time.h>
     52  1.1  chuck #include <sys/kernel.h>
     53  1.1  chuck #include <sys/syslog.h>
     54  1.1  chuck 
     55  1.1  chuck #include <dev/cons.h>
     56  1.1  chuck #include <dev/ic/z8530reg.h>
     57  1.1  chuck #include <machine/z8530var.h>
     58  1.1  chuck 
     59  1.1  chuck #include <machine/cpu.h>
     60  1.1  chuck 
     61  1.1  chuck #include <mvme68k/dev/pccreg.h>
     62  1.1  chuck #include <mvme68k/dev/pccvar.h>
     63  1.1  chuck #include <mvme68k/dev/zsvar.h>
     64  1.1  chuck 
     65  1.1  chuck /*
     66  1.1  chuck  * PCC offsets.
     67  1.1  chuck  */
     68  1.1  chuck static int zs_pcc_offsets[NZS] = { PCC_ZS0_OFF, PCC_ZS1_OFF };
     69  1.1  chuck 
     70  1.1  chuck struct zschan *
     71  1.1  chuck zs_pcc_get_chan_addr(zsc_unit, channel)
     72  1.1  chuck 	int zsc_unit, channel;
     73  1.1  chuck {
     74  1.1  chuck 	struct zsdevice *addr;
     75  1.1  chuck 	struct zschan *zc;
     76  1.1  chuck 
     77  1.1  chuck 	if (zsc_unit >= NZS)
     78  1.1  chuck 		return NULL;
     79  1.1  chuck 	addr = (struct zsdevice *)PCC_VADDR(zs_pcc_offsets[zsc_unit]);
     80  1.1  chuck 	if (addr == NULL)
     81  1.1  chuck 		return NULL;
     82  1.1  chuck 	if (channel == 0) {
     83  1.1  chuck 		zc = &addr->zs_chan_a;
     84  1.1  chuck 	} else {
     85  1.1  chuck 		zc = &addr->zs_chan_b;
     86  1.1  chuck 	}
     87  1.1  chuck 	return (zc);
     88  1.1  chuck }
     89  1.1  chuck 
     90  1.1  chuck /****************************************************************
     91  1.1  chuck  * Autoconfig
     92  1.1  chuck  ****************************************************************/
     93  1.1  chuck 
     94  1.1  chuck /* Definition of the driver for autoconfig. */
     95  1.1  chuck static int	zsc_pcc_match __P((struct device *, void *, void *));
     96  1.1  chuck static void	zsc_pcc_attach __P((struct device *, struct device *, void *));
     97  1.1  chuck 
     98  1.1  chuck struct cfattach zsc_pcc_ca = {
     99  1.1  chuck 	sizeof(struct zsc_softc), zsc_pcc_match, zsc_pcc_attach
    100  1.1  chuck };
    101  1.1  chuck 
    102  1.1  chuck 
    103  1.1  chuck /*
    104  1.1  chuck  * Is the zs chip present?
    105  1.1  chuck  */
    106  1.1  chuck static int
    107  1.1  chuck zsc_pcc_match(parent, vcf, aux)
    108  1.1  chuck 	struct device *parent;
    109  1.1  chuck 	void *vcf, *aux;
    110  1.1  chuck {
    111  1.1  chuck 	struct cfdata *cf = vcf;
    112  1.1  chuck 	struct pcc_attach_args *pa = aux;
    113  1.1  chuck 	int unit;
    114  1.1  chuck 
    115  1.1  chuck 	/* XXX This is bogus; should fix this. */
    116  1.1  chuck 	unit = cf->cf_unit;
    117  1.1  chuck 	if (unit < 0 || unit >= NZS)
    118  1.1  chuck 		return (0);
    119  1.1  chuck 
    120  1.1  chuck 	if (strcmp(pa->pa_name, zsc_cd.cd_name))
    121  1.1  chuck 		return (0);
    122  1.1  chuck 
    123  1.1  chuck 	pa->pa_ipl = cf->pcccf_ipl;
    124  1.1  chuck 	if (pa->pa_ipl == -1)
    125  1.1  chuck 		pa->pa_ipl = ZSHARD_PRI;
    126  1.1  chuck 	return (1);
    127  1.1  chuck }
    128  1.1  chuck 
    129  1.1  chuck /*
    130  1.1  chuck  * Attach a found zs.
    131  1.1  chuck  *
    132  1.1  chuck  * Match slave number to zs unit number, so that misconfiguration will
    133  1.1  chuck  * not set up the keyboard as ttya, etc.
    134  1.1  chuck  */
    135  1.1  chuck static void
    136  1.1  chuck zsc_pcc_attach(parent, self, aux)
    137  1.1  chuck 	struct device *parent;
    138  1.1  chuck 	struct device *self;
    139  1.1  chuck 	void *aux;
    140  1.1  chuck {
    141  1.1  chuck 	struct zsc_softc *zsc = (void *) self;
    142  1.1  chuck 	struct pcc_attach_args *pa = aux;
    143  1.1  chuck 	int zs_level, ir;
    144  1.1  chuck 	static int didintr;
    145  1.1  chuck 
    146  1.1  chuck 	zs_level = pa->pa_ipl;
    147  1.1  chuck 
    148  1.1  chuck 	/* Do common parts of SCC configuration. */
    149  1.1  chuck 	zs_config(zsc, zs_pcc_get_chan_addr);
    150  1.1  chuck 
    151  1.1  chuck 	/*
    152  1.1  chuck 	 * Now safe to install interrupt handlers.  Note the arguments
    153  1.1  chuck 	 * to the interrupt handlers aren't used.  Note, we only do this
    154  1.1  chuck 	 * once since both SCCs interrupt at the same level and vector.
    155  1.1  chuck 	 */
    156  1.1  chuck 	if (didintr == 0) {
    157  1.1  chuck 		didintr = 1;
    158  1.1  chuck 		pccintr_establish(PCCV_ZS, zshard, zs_level, zsc);
    159  1.1  chuck 	}
    160  1.1  chuck 
    161  1.1  chuck 	/* Sanity check the interrupt levels. */
    162  1.1  chuck 	ir = sys_pcc->zs_int;
    163  1.1  chuck 	if (((ir & PCC_IMASK) != 0) &&
    164  1.1  chuck 	    ((ir & PCC_IMASK) != zs_level))
    165  1.1  chuck 		panic("zs_pcc_attach: zs configured at different IPLs");
    166  1.1  chuck 
    167  1.1  chuck 	/*
    168  1.1  chuck 	 * Set master interrupt enable.  Vector is programmed into
    169  1.1  chuck 	 * the SCC by the PCC.
    170  1.1  chuck 	 */
    171  1.1  chuck 	sys_pcc->zs_int = zs_level | PCC_IENABLE | PCC_ZSEXTERN;
    172  1.1  chuck 	zs_write_reg(&zsc->zsc_cs[0], 9, zs_init_reg[9]);
    173  1.1  chuck }
    174  1.1  chuck 
    175  1.1  chuck /****************************************************************
    176  1.1  chuck  * Console support functions (MVME PCC specific!)
    177  1.1  chuck  ****************************************************************/
    178  1.1  chuck 
    179  1.1  chuck /*
    180  1.1  chuck  * Check for SCC console.  The MVME-147 always uses unit 0 chan 0.
    181  1.1  chuck  */
    182  1.1  chuck void
    183  1.1  chuck zsc_pcccnprobe(cp)
    184  1.1  chuck 	struct consdev *cp;
    185  1.1  chuck {
    186  1.1  chuck 
    187  1.1  chuck #ifdef notyet
    188  1.1  chuck 	if (cputyp != CPU_147) {
    189  1.1  chuck 		cp->cn_pri = CN_DEAD;
    190  1.1  chuck 		return;
    191  1.1  chuck 	}
    192  1.1  chuck #endif
    193  1.1  chuck 
    194  1.1  chuck 	/* XXX Shouldn't hardcode the minor number... */
    195  1.1  chuck 
    196  1.1  chuck 	/* Initialize required fields. */
    197  1.1  chuck 	cp->cn_dev = makedev(ZSTTY_MAJOR, 0);
    198  1.1  chuck 	cp->cn_pri = CN_NORMAL;
    199  1.1  chuck }
    200  1.1  chuck 
    201  1.1  chuck void
    202  1.1  chuck zsc_pcccninit(cp)
    203  1.1  chuck 	struct consdev *cp;
    204  1.1  chuck {
    205  1.1  chuck 	int unit, chan;
    206  1.1  chuck 	struct zschan *zc;
    207  1.1  chuck 
    208  1.1  chuck 	unit = 0;	/* XXX */
    209  1.1  chuck 	chan = 0;	/* XXX */
    210  1.1  chuck 	zc = zs_pcc_get_chan_addr(unit, chan);
    211  1.1  chuck 
    212  1.1  chuck 	/* Do common parts of console init. */
    213  1.1  chuck 	zs_cnconfig(unit, chan, zc);
    214  1.1  chuck }
    215