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