Home | History | Annotate | Line # | Download | only in dev
      1  1.21   martin /*	$NetBSD: zs_pcc.c,v 1.21 2008/04/28 20:23:29 martin 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.1    chuck  *
     19   1.2  thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.2  thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.2  thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.5      jtc  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.5      jtc  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.2  thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.2  thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.2  thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.2  thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.2  thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.2  thorpej  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1    chuck  */
     31   1.1    chuck 
     32   1.1    chuck /*
     33   1.1    chuck  * Zilog Z8530 Dual UART driver (machine-dependent part)
     34   1.1    chuck  *
     35   1.1    chuck  * Runs two serial lines per chip using slave drivers.
     36   1.1    chuck  * Plain tty/async lines use the zs_async slave.
     37   1.1    chuck  *
     38  1.17   keihan  * Modified for NetBSD/mvme68k by Jason R. Thorpe <thorpej (at) NetBSD.org>
     39   1.1    chuck  */
     40  1.16    lukem 
     41  1.16    lukem #include <sys/cdefs.h>
     42  1.21   martin __KERNEL_RCSID(0, "$NetBSD: zs_pcc.c,v 1.21 2008/04/28 20:23:29 martin Exp $");
     43   1.1    chuck 
     44   1.1    chuck #include <sys/param.h>
     45   1.1    chuck #include <sys/systm.h>
     46   1.1    chuck #include <sys/proc.h>
     47   1.1    chuck #include <sys/device.h>
     48   1.1    chuck #include <sys/conf.h>
     49   1.1    chuck #include <sys/file.h>
     50   1.1    chuck #include <sys/ioctl.h>
     51   1.1    chuck #include <sys/tty.h>
     52   1.1    chuck #include <sys/time.h>
     53   1.1    chuck #include <sys/kernel.h>
     54   1.1    chuck #include <sys/syslog.h>
     55   1.1    chuck 
     56   1.1    chuck #include <dev/cons.h>
     57   1.1    chuck #include <dev/ic/z8530reg.h>
     58   1.1    chuck #include <machine/z8530var.h>
     59   1.1    chuck 
     60   1.1    chuck #include <machine/cpu.h>
     61   1.8      scw #include <machine/bus.h>
     62   1.1    chuck 
     63   1.8      scw #include <mvme68k/dev/mainbus.h>
     64   1.1    chuck #include <mvme68k/dev/pccreg.h>
     65   1.1    chuck #include <mvme68k/dev/pccvar.h>
     66   1.1    chuck #include <mvme68k/dev/zsvar.h>
     67   1.1    chuck 
     68  1.19  tsutsui #include "ioconf.h"
     69   1.1    chuck 
     70   1.1    chuck /* Definition of the driver for autoconfig. */
     71  1.20  tsutsui static int	zsc_pcc_match(device_t, cfdata_t, void *);
     72  1.20  tsutsui static void	zsc_pcc_attach(device_t, device_t, void *);
     73   1.1    chuck 
     74  1.20  tsutsui CFATTACH_DECL_NEW(zsc_pcc, sizeof(struct zsc_softc),
     75  1.15  thorpej     zsc_pcc_match, zsc_pcc_attach, NULL, NULL);
     76   1.1    chuck 
     77   1.8      scw cons_decl(zsc_pcc);
     78   1.8      scw 
     79   1.8      scw 
     80   1.1    chuck /*
     81   1.1    chuck  * Is the zs chip present?
     82   1.1    chuck  */
     83   1.1    chuck static int
     84  1.20  tsutsui zsc_pcc_match(device_t parent, cfdata_t cf, void *aux)
     85   1.1    chuck {
     86   1.1    chuck 	struct pcc_attach_args *pa = aux;
     87   1.1    chuck 
     88   1.1    chuck 	if (strcmp(pa->pa_name, zsc_cd.cd_name))
     89  1.19  tsutsui 		return 0;
     90   1.1    chuck 
     91   1.1    chuck 	pa->pa_ipl = cf->pcccf_ipl;
     92   1.1    chuck 	if (pa->pa_ipl == -1)
     93   1.1    chuck 		pa->pa_ipl = ZSHARD_PRI;
     94  1.19  tsutsui 	return 1;
     95   1.1    chuck }
     96   1.1    chuck 
     97   1.1    chuck /*
     98   1.1    chuck  * Attach a found zs.
     99   1.1    chuck  *
    100   1.1    chuck  * Match slave number to zs unit number, so that misconfiguration will
    101   1.1    chuck  * not set up the keyboard as ttya, etc.
    102   1.1    chuck  */
    103   1.1    chuck static void
    104  1.20  tsutsui zsc_pcc_attach(device_t parent, device_t self, void *aux)
    105   1.1    chuck {
    106  1.20  tsutsui 	struct zsc_softc *zsc = device_private(self);
    107   1.1    chuck 	struct pcc_attach_args *pa = aux;
    108  1.10      scw 	struct zsdevice zs;
    109   1.8      scw 	bus_space_handle_t bush;
    110   1.1    chuck 	int zs_level, ir;
    111   1.1    chuck 	static int didintr;
    112   1.1    chuck 
    113  1.20  tsutsui 	zsc->zsc_dev = self;
    114  1.20  tsutsui 
    115   1.8      scw 	/* Map the device's registers */
    116   1.8      scw 	bus_space_map(pa->pa_bust, pa->pa_offset, 4, 0, &bush);
    117   1.8      scw 
    118   1.1    chuck 	zs_level = pa->pa_ipl;
    119   1.1    chuck 
    120  1.10      scw 	/* XXX: This is a gross hack. I need to bus-space zs.c ... */
    121  1.20  tsutsui 	zs.zs_chan_b.zc_csr = (volatile uint8_t *)bush;
    122  1.20  tsutsui 	zs.zs_chan_b.zc_data = (volatile uint8_t *)bush + 1;
    123  1.20  tsutsui 	zs.zs_chan_a.zc_csr = (volatile uint8_t *)bush + 2;
    124  1.20  tsutsui 	zs.zs_chan_a.zc_data = (volatile uint8_t *)bush + 3;
    125  1.10      scw 
    126  1.10      scw 	/*
    127  1.10      scw 	 * Do common parts of SCC configuration.
    128  1.10      scw 	 * Note that the vector is not actually used by the ZS chip on
    129  1.10      scw 	 * MVME-147. We set up the PCC so that it provides the vector.
    130  1.10      scw 	 * This is just here so the real vector is printed at config time.
    131  1.10      scw 	 */
    132  1.10      scw 	zs_config(zsc, &zs, PCC_VECBASE + PCCV_ZS, PCLK_147);
    133   1.1    chuck 
    134  1.12      scw 	evcnt_attach_dynamic(&zsc->zsc_evcnt, EVCNT_TYPE_INTR,
    135  1.20  tsutsui 	    pccintr_evcnt(zs_level), "rs232", device_xname(zsc->zsc_dev));
    136  1.12      scw 
    137   1.1    chuck 	/*
    138   1.1    chuck 	 * Now safe to install interrupt handlers.  Note the arguments
    139   1.1    chuck 	 * to the interrupt handlers aren't used.  Note, we only do this
    140   1.1    chuck 	 * once since both SCCs interrupt at the same level and vector.
    141   1.1    chuck 	 */
    142   1.1    chuck 	if (didintr == 0) {
    143   1.1    chuck 		didintr = 1;
    144  1.12      scw 		pccintr_establish(PCCV_ZS, zshard_shared, zs_level, zsc, NULL);
    145   1.1    chuck 	}
    146   1.1    chuck 
    147   1.1    chuck 	/* Sanity check the interrupt levels. */
    148   1.8      scw 	ir = pcc_reg_read(sys_pcc, PCCREG_SERIAL_INTR_CTRL);
    149   1.1    chuck 	if (((ir & PCC_IMASK) != 0) &&
    150   1.1    chuck 	    ((ir & PCC_IMASK) != zs_level))
    151  1.19  tsutsui 		panic("%s: zs configured at different IPLs", __func__);
    152   1.1    chuck 
    153   1.1    chuck 	/*
    154  1.10      scw 	 * Set master interrupt enable. Vector is supplied by the PCC.
    155   1.1    chuck 	 */
    156   1.8      scw 	pcc_reg_write(sys_pcc, PCCREG_SERIAL_INTR_CTRL,
    157   1.8      scw 	    zs_level | PCC_IENABLE | PCC_ZSEXTERN);
    158  1.10      scw 	zs_write_reg(zsc->zsc_cs[0], 2, PCC_VECBASE + PCCV_ZS);
    159   1.3      gwr 	zs_write_reg(zsc->zsc_cs[0], 9, zs_init_reg[9]);
    160   1.1    chuck }
    161   1.1    chuck 
    162   1.1    chuck /****************************************************************
    163   1.1    chuck  * Console support functions (MVME PCC specific!)
    164   1.1    chuck  ****************************************************************/
    165   1.1    chuck 
    166   1.1    chuck /*
    167   1.1    chuck  * Check for SCC console.  The MVME-147 always uses unit 0 chan 0.
    168   1.1    chuck  */
    169   1.1    chuck void
    170  1.19  tsutsui zsc_pcccnprobe(struct consdev *cp)
    171   1.1    chuck {
    172  1.13  gehenna 	extern const struct cdevsw zstty_cdevsw;
    173  1.13  gehenna 
    174   1.7      scw 	if (machineid != MVME_147) {
    175   1.1    chuck 		cp->cn_pri = CN_DEAD;
    176   1.1    chuck 		return;
    177   1.1    chuck 	}
    178   1.1    chuck 
    179   1.1    chuck 	/* Initialize required fields. */
    180  1.13  gehenna 	cp->cn_dev = makedev(cdevsw_lookup_major(&zstty_cdevsw), 0);
    181   1.1    chuck 	cp->cn_pri = CN_NORMAL;
    182   1.1    chuck }
    183   1.1    chuck 
    184   1.1    chuck void
    185  1.19  tsutsui zsc_pcccninit(struct consdev *cp)
    186   1.1    chuck {
    187   1.8      scw 	bus_space_handle_t bush;
    188  1.10      scw 	struct zsdevice zs;
    189   1.1    chuck 
    190  1.11      scw 	bus_space_map(&_mainbus_space_tag,
    191  1.11      scw 	    intiobase_phys + MAINBUS_PCC_OFFSET + PCC_ZS0_OFF, 4, 0, &bush);
    192   1.1    chuck 
    193  1.10      scw 	/* XXX: This is a gross hack. I need to bus-space zs.c ... */
    194  1.20  tsutsui 	zs.zs_chan_b.zc_csr = (volatile uint8_t *)bush;
    195  1.20  tsutsui 	zs.zs_chan_b.zc_data = (volatile uint8_t *)bush + 1;
    196  1.20  tsutsui 	zs.zs_chan_a.zc_csr = (volatile uint8_t *)bush + 2;
    197  1.20  tsutsui 	zs.zs_chan_a.zc_data = (volatile uint8_t *)bush + 3;
    198  1.10      scw 
    199   1.1    chuck 	/* Do common parts of console init. */
    200  1.10      scw 	zs_cnconfig(0, 0, &zs, PCLK_147);
    201   1.1    chuck }
    202