Home | History | Annotate | Line # | Download | only in dev
zs_pcctwo.c revision 1.10
      1  1.10   keihan /*	$NetBSD: zs_pcctwo.c,v 1.10 2003/12/04 12:42:54 keihan Exp $	*/
      2   1.1      scw 
      3   1.1      scw /*-
      4   1.1      scw  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5   1.1      scw  * All rights reserved.
      6   1.1      scw  *
      7   1.1      scw  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1      scw  * by Gordon W. Ross, Jason R. Thorpe and Steve C. Woodford.
      9   1.1      scw  *
     10   1.1      scw  * Redistribution and use in source and binary forms, with or without
     11   1.1      scw  * modification, are permitted provided that the following conditions
     12   1.1      scw  * are met:
     13   1.1      scw  * 1. Redistributions of source code must retain the above copyright
     14   1.1      scw  *    notice, this list of conditions and the following disclaimer.
     15   1.1      scw  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1      scw  *    notice, this list of conditions and the following disclaimer in the
     17   1.1      scw  *    documentation and/or other materials provided with the distribution.
     18   1.1      scw  * 3. All advertising materials mentioning features or use of this software
     19   1.1      scw  *    must display the following acknowledgement:
     20   1.1      scw  *        This product includes software developed by the NetBSD
     21   1.1      scw  *        Foundation, Inc. and its contributors.
     22   1.1      scw  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23   1.1      scw  *    contributors may be used to endorse or promote products derived
     24   1.1      scw  *    from this software without specific prior written permission.
     25   1.1      scw  *
     26   1.1      scw  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27   1.1      scw  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.1      scw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29   1.1      scw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30   1.1      scw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.1      scw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.1      scw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.1      scw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.1      scw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.1      scw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.1      scw  * POSSIBILITY OF SUCH DAMAGE.
     37   1.1      scw  */
     38   1.1      scw 
     39   1.1      scw /*
     40   1.1      scw  * Zilog Z8530 Dual UART driver (machine-dependent part)
     41   1.1      scw  *
     42   1.1      scw  * Runs two serial lines per chip using slave drivers.
     43   1.1      scw  * Plain tty/async lines use the zs_async slave.
     44   1.1      scw  *
     45  1.10   keihan  * Modified for NetBSD/mvme68k by Jason R. Thorpe <thorpej (at) NetBSD.org>
     46   1.1      scw  *
     47   1.1      scw  * Modified to attach to the PCCchip2/MCchip backend by Steve Woodford.
     48   1.1      scw  */
     49   1.9    lukem 
     50   1.9    lukem #include <sys/cdefs.h>
     51  1.10   keihan __KERNEL_RCSID(0, "$NetBSD: zs_pcctwo.c,v 1.10 2003/12/04 12:42:54 keihan Exp $");
     52   1.1      scw 
     53   1.1      scw #include <sys/param.h>
     54   1.1      scw #include <sys/systm.h>
     55   1.1      scw #include <sys/proc.h>
     56   1.1      scw #include <sys/device.h>
     57   1.1      scw #include <sys/conf.h>
     58   1.1      scw #include <sys/file.h>
     59   1.1      scw #include <sys/ioctl.h>
     60   1.1      scw #include <sys/tty.h>
     61   1.1      scw #include <sys/time.h>
     62   1.1      scw #include <sys/kernel.h>
     63   1.1      scw #include <sys/syslog.h>
     64   1.1      scw 
     65   1.1      scw #include <dev/cons.h>
     66   1.1      scw #include <dev/ic/z8530reg.h>
     67   1.1      scw #include <machine/z8530var.h>
     68   1.1      scw 
     69   1.1      scw #include <machine/cpu.h>
     70   1.1      scw #include <machine/bus.h>
     71   1.1      scw 
     72   1.5      scw #include <dev/mvme/pcctworeg.h>
     73   1.5      scw #include <dev/mvme/pcctwovar.h>
     74   1.5      scw 
     75   1.1      scw #include <mvme68k/dev/mainbus.h>
     76   1.1      scw #include <mvme68k/dev/zsvar.h>
     77   1.1      scw 
     78   1.1      scw 
     79   1.1      scw /* Definition of the driver for autoconfig. */
     80   1.1      scw static int	zsc_pcctwo_match(struct device *, struct cfdata *, void *);
     81   1.1      scw static void	zsc_pcctwo_attach(struct device *, struct device *, void *);
     82   1.1      scw 
     83   1.8  thorpej CFATTACH_DECL(zsc_pcctwo, sizeof(struct zsc_softc),
     84   1.8  thorpej     zsc_pcctwo_match, zsc_pcctwo_attach, NULL, NULL);
     85   1.1      scw 
     86   1.1      scw extern struct cfdriver zsc_cd;
     87   1.1      scw 
     88   1.1      scw cons_decl(zsc_pcctwo);
     89   1.1      scw 
     90   1.1      scw 
     91   1.1      scw /*
     92   1.1      scw  * Is the zs chip present?
     93   1.1      scw  */
     94   1.1      scw static int
     95   1.1      scw zsc_pcctwo_match(parent, cf, aux)
     96   1.1      scw 	struct device *parent;
     97   1.1      scw 	struct cfdata *cf;
     98   1.1      scw 	void *aux;
     99   1.1      scw {
    100   1.1      scw 	struct pcctwo_attach_args *pa = aux;
    101   1.1      scw 
    102   1.2      scw 	if (strcmp(pa->pa_name, zsc_cd.cd_name) ||
    103   1.2      scw 	    (machineid != MVME_162 && machineid != MVME_172))
    104   1.1      scw 		return (0);
    105   1.1      scw 
    106   1.1      scw 	pa->pa_ipl = cf->pcctwocf_ipl;
    107   1.1      scw 	if (pa->pa_ipl == -1)
    108   1.1      scw 		pa->pa_ipl = ZSHARD_PRI;
    109   1.1      scw 	return (1);
    110   1.1      scw }
    111   1.1      scw 
    112   1.1      scw /*
    113   1.1      scw  * Attach a found zs.
    114   1.1      scw  */
    115   1.1      scw static void
    116   1.1      scw zsc_pcctwo_attach(parent, self, aux)
    117   1.1      scw 	struct device *parent;
    118   1.1      scw 	struct device *self;
    119   1.1      scw 	void *aux;
    120   1.1      scw {
    121   1.1      scw 	struct zsc_softc *zsc = (void *) self;
    122   1.1      scw 	struct pcctwo_attach_args *pa = aux;
    123   1.1      scw 	struct zsdevice zs;
    124   1.1      scw 	bus_space_handle_t bush;
    125   1.1      scw 	int zs_level;
    126   1.1      scw 	static int vector = MCCHIPV_ZS0;
    127   1.1      scw 
    128   1.1      scw 	/* Map the device's registers */
    129   1.1      scw 	bus_space_map(pa->pa_bust, pa->pa_offset, 8, 0, &bush);
    130   1.1      scw 
    131   1.1      scw 	zs_level = pa->pa_ipl;
    132   1.1      scw 
    133   1.1      scw 	/* XXX: This is a gross hack. I need to bus-space zs.c ... */
    134   1.1      scw 	zs.zs_chan_b.zc_csr = (volatile u_char *) bush + 1;
    135   1.1      scw 	zs.zs_chan_b.zc_data = (volatile u_char *) bush + 3;
    136   1.1      scw 	zs.zs_chan_a.zc_csr = (volatile u_char *) bush + 5;
    137   1.1      scw 	zs.zs_chan_a.zc_data = (volatile u_char *) bush + 7;
    138   1.1      scw 
    139   1.1      scw 	/* Do common parts of SCC configuration. */
    140   1.1      scw 	zs_config(zsc, &zs, vector + PCCTWO_VECBASE, PCLK_162);
    141   1.1      scw 
    142   1.4      scw 	evcnt_attach_dynamic(&zsc->zsc_evcnt, EVCNT_TYPE_INTR,
    143   1.4      scw 	    pcctwointr_evcnt(zs_level), "rs232", zsc->zsc_dev.dv_xname);
    144   1.4      scw 
    145   1.1      scw 	/*
    146   1.1      scw 	 * Now safe to install interrupt handlers.
    147   1.1      scw 	 */
    148   1.4      scw 	pcctwointr_establish(vector++, zshard_unshared, zs_level, zsc, NULL);
    149   1.1      scw 
    150   1.1      scw 	/*
    151   1.1      scw 	 * Set master interrupt enable.
    152   1.1      scw 	 */
    153   1.1      scw 	zs_write_reg(zsc->zsc_cs[0], 9, zs_init_reg[9]);
    154   1.1      scw }
    155   1.1      scw 
    156   1.1      scw /****************************************************************
    157   1.1      scw  * Console support functions (MVME PCC specific!)
    158   1.1      scw  ****************************************************************/
    159   1.1      scw 
    160   1.1      scw /*
    161   1.2      scw  * Check for SCC console.  The MVME-1x2 always uses unit 0 chan 0.
    162   1.1      scw  */
    163   1.1      scw void
    164   1.1      scw zsc_pcctwocnprobe(cp)
    165   1.1      scw 	struct consdev *cp;
    166   1.1      scw {
    167   1.6  gehenna 	extern const struct cdevsw zstty_cdevsw;
    168   1.6  gehenna 
    169   1.2      scw 	if (machineid != MVME_162 && machineid != MVME_172) {
    170   1.1      scw 		cp->cn_pri = CN_DEAD;
    171   1.1      scw 		return;
    172   1.1      scw 	}
    173   1.1      scw 
    174   1.1      scw 	/* Initialize required fields. */
    175   1.6  gehenna 	cp->cn_dev = makedev(cdevsw_lookup_major(&zstty_cdevsw), 0);
    176   1.1      scw 	cp->cn_pri = CN_NORMAL;
    177   1.1      scw }
    178   1.1      scw 
    179   1.1      scw void
    180   1.1      scw zsc_pcctwocninit(cp)
    181   1.1      scw 	struct consdev *cp;
    182   1.1      scw {
    183   1.1      scw 	bus_space_handle_t bush;
    184   1.1      scw 	struct zsdevice zs;
    185   1.1      scw 
    186   1.3      scw 	bus_space_map(&_mainbus_space_tag,
    187   1.3      scw 	    intiobase_phys + MAINBUS_PCCTWO_OFFSET + MCCHIP_ZS0_OFF, 8, 0,&bush);
    188   1.1      scw 
    189   1.1      scw 	/* XXX: This is a gross hack. I need to bus-space zs.c ... */
    190   1.1      scw 	zs.zs_chan_b.zc_csr = (volatile u_char *) bush + 1;
    191   1.1      scw 	zs.zs_chan_b.zc_data = (volatile u_char *) bush + 3;
    192   1.1      scw 	zs.zs_chan_a.zc_csr = (volatile u_char *) bush + 5;
    193   1.1      scw 	zs.zs_chan_a.zc_data = (volatile u_char *) bush + 7;
    194   1.1      scw 
    195   1.1      scw 	/* Do common parts of console init. */
    196   1.1      scw 	zs_cnconfig(0, 0, &zs, PCLK_162);
    197   1.1      scw }
    198