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