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