Home | History | Annotate | Line # | Download | only in tc
zs_ioasic.c revision 1.5.2.2
      1  1.5.2.2  bouyer /* $NetBSD: zs_ioasic.c,v 1.5.2.2 2000/11/20 11:43:18 bouyer Exp $ */
      2  1.5.2.2  bouyer 
      3  1.5.2.2  bouyer /*-
      4  1.5.2.2  bouyer  * Copyright (c) 1996, 1998 The NetBSD Foundation, Inc.
      5  1.5.2.2  bouyer  * All rights reserved.
      6  1.5.2.2  bouyer  *
      7  1.5.2.2  bouyer  * This code is derived from software contributed to The NetBSD Foundation
      8  1.5.2.2  bouyer  * by Gordon W. Ross, Ken Hornstein, and by Jason R. Thorpe of the
      9  1.5.2.2  bouyer  * Numerical Aerospace Simulation Facility, NASA Ames Research Center.
     10  1.5.2.2  bouyer  *
     11  1.5.2.2  bouyer  * Redistribution and use in source and binary forms, with or without
     12  1.5.2.2  bouyer  * modification, are permitted provided that the following conditions
     13  1.5.2.2  bouyer  * are met:
     14  1.5.2.2  bouyer  * 1. Redistributions of source code must retain the above copyright
     15  1.5.2.2  bouyer  *    notice, this list of conditions and the following disclaimer.
     16  1.5.2.2  bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.5.2.2  bouyer  *    notice, this list of conditions and the following disclaimer in the
     18  1.5.2.2  bouyer  *    documentation and/or other materials provided with the distribution.
     19  1.5.2.2  bouyer  * 3. All advertising materials mentioning features or use of this software
     20  1.5.2.2  bouyer  *    must display the following acknowledgement:
     21  1.5.2.2  bouyer  *        This product includes software developed by the NetBSD
     22  1.5.2.2  bouyer  *        Foundation, Inc. and its contributors.
     23  1.5.2.2  bouyer  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  1.5.2.2  bouyer  *    contributors may be used to endorse or promote products derived
     25  1.5.2.2  bouyer  *    from this software without specific prior written permission.
     26  1.5.2.2  bouyer  *
     27  1.5.2.2  bouyer  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  1.5.2.2  bouyer  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  1.5.2.2  bouyer  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  1.5.2.2  bouyer  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  1.5.2.2  bouyer  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  1.5.2.2  bouyer  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  1.5.2.2  bouyer  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  1.5.2.2  bouyer  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  1.5.2.2  bouyer  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  1.5.2.2  bouyer  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  1.5.2.2  bouyer  * POSSIBILITY OF SUCH DAMAGE.
     38  1.5.2.2  bouyer  */
     39  1.5.2.2  bouyer 
     40  1.5.2.2  bouyer #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     41  1.5.2.2  bouyer 
     42  1.5.2.2  bouyer __KERNEL_RCSID(0, "$NetBSD: zs_ioasic.c,v 1.5.2.2 2000/11/20 11:43:18 bouyer Exp $");
     43  1.5.2.2  bouyer 
     44  1.5.2.2  bouyer /*
     45  1.5.2.2  bouyer  * Zilog Z8530 Dual UART driver (machine-dependent part).  This driver
     46  1.5.2.2  bouyer  * handles Z8530 chips attached to the DECstation/Alpha IOASIC.  Modified
     47  1.5.2.2  bouyer  * for NetBSD/alpha by Ken Hornstein and Jason R. Thorpe.  NetBSD/pmax
     48  1.5.2.2  bouyer  * adaption by Mattias Drochner.  Merge work by Tohru Nishimura.
     49  1.5.2.2  bouyer  *
     50  1.5.2.2  bouyer  * Runs two serial lines per chip using slave drivers.
     51  1.5.2.2  bouyer  * Plain tty/async lines use the zstty slave.
     52  1.5.2.2  bouyer  */
     53  1.5.2.2  bouyer 
     54  1.5.2.2  bouyer #include "opt_ddb.h"
     55  1.5.2.2  bouyer #include "zskbd.h"
     56  1.5.2.2  bouyer 
     57  1.5.2.2  bouyer #include <sys/param.h>
     58  1.5.2.2  bouyer #include <sys/systm.h>
     59  1.5.2.2  bouyer #include <sys/conf.h>
     60  1.5.2.2  bouyer #include <sys/device.h>
     61  1.5.2.2  bouyer #include <sys/malloc.h>
     62  1.5.2.2  bouyer #include <sys/file.h>
     63  1.5.2.2  bouyer #include <sys/ioctl.h>
     64  1.5.2.2  bouyer #include <sys/kernel.h>
     65  1.5.2.2  bouyer #include <sys/proc.h>
     66  1.5.2.2  bouyer #include <sys/tty.h>
     67  1.5.2.2  bouyer #include <sys/time.h>
     68  1.5.2.2  bouyer #include <sys/syslog.h>
     69  1.5.2.2  bouyer 
     70  1.5.2.2  bouyer #include <machine/autoconf.h>
     71  1.5.2.2  bouyer #include <machine/intr.h>
     72  1.5.2.2  bouyer #include <machine/z8530var.h>
     73  1.5.2.2  bouyer 
     74  1.5.2.2  bouyer #include <dev/cons.h>
     75  1.5.2.2  bouyer #include <dev/ic/z8530reg.h>
     76  1.5.2.2  bouyer 
     77  1.5.2.2  bouyer #include <dev/tc/tcvar.h>
     78  1.5.2.2  bouyer #include <dev/tc/ioasicreg.h>
     79  1.5.2.2  bouyer #include <dev/tc/ioasicvar.h>
     80  1.5.2.2  bouyer 
     81  1.5.2.2  bouyer #include <dev/tc/zs_ioasicvar.h>
     82  1.5.2.2  bouyer 
     83  1.5.2.2  bouyer #if defined(__alpha__) || defined(alpha)
     84  1.5.2.2  bouyer #include <machine/rpb.h>
     85  1.5.2.2  bouyer #endif
     86  1.5.2.2  bouyer #if defined(pmax)
     87  1.5.2.2  bouyer #include <pmax/pmax/pmaxtype.h>
     88  1.5.2.2  bouyer #endif
     89  1.5.2.2  bouyer 
     90  1.5.2.2  bouyer /*
     91  1.5.2.2  bouyer  * Helpers for console support.
     92  1.5.2.2  bouyer  */
     93  1.5.2.2  bouyer void	zs_ioasic_cninit __P((tc_addr_t, tc_offset_t, int));
     94  1.5.2.2  bouyer int	zs_ioasic_cngetc __P((dev_t));
     95  1.5.2.2  bouyer void	zs_ioasic_cnputc __P((dev_t, int));
     96  1.5.2.2  bouyer void	zs_ioasic_cnpollc __P((dev_t, int));
     97  1.5.2.2  bouyer 
     98  1.5.2.2  bouyer struct consdev zs_ioasic_cons = {
     99  1.5.2.2  bouyer 	NULL, NULL, zs_ioasic_cngetc, zs_ioasic_cnputc,
    100  1.5.2.2  bouyer 	zs_ioasic_cnpollc, NULL, NODEV, CN_NORMAL,
    101  1.5.2.2  bouyer };
    102  1.5.2.2  bouyer 
    103  1.5.2.2  bouyer tc_offset_t zs_ioasic_console_offset;
    104  1.5.2.2  bouyer int zs_ioasic_console_channel;
    105  1.5.2.2  bouyer int zs_ioasic_console;
    106  1.5.2.2  bouyer struct zs_chanstate zs_ioasic_conschanstate_store;
    107  1.5.2.2  bouyer 
    108  1.5.2.2  bouyer int	zs_ioasic_isconsole __P((tc_offset_t, int));
    109  1.5.2.2  bouyer int	zs_getc __P((struct zs_chanstate *));
    110  1.5.2.2  bouyer void	zs_putc __P((struct zs_chanstate *, int));
    111  1.5.2.2  bouyer 
    112  1.5.2.2  bouyer /*
    113  1.5.2.2  bouyer  * Some warts needed by z8530tty.c
    114  1.5.2.2  bouyer  */
    115  1.5.2.2  bouyer int zs_def_cflag = (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8;
    116  1.5.2.2  bouyer #if defined(__alpha__) || defined(alpha)
    117  1.5.2.2  bouyer int zs_major = 15;
    118  1.5.2.2  bouyer #endif
    119  1.5.2.2  bouyer #if defined(pmax)
    120  1.5.2.2  bouyer int zs_major = 17;
    121  1.5.2.2  bouyer #endif
    122  1.5.2.2  bouyer 
    123  1.5.2.2  bouyer /*
    124  1.5.2.2  bouyer  * ZS chips are feeded a 7.372 MHz clock.
    125  1.5.2.2  bouyer  */
    126  1.5.2.2  bouyer #define	PCLK	(9600 * 768)	/* PCLK pin input clock rate */
    127  1.5.2.2  bouyer 
    128  1.5.2.2  bouyer /* The layout of this is hardware-dependent (padding, order). */
    129  1.5.2.2  bouyer struct zshan {
    130  1.5.2.2  bouyer #if defined(__alpha__) || defined(alpha)
    131  1.5.2.2  bouyer 	volatile u_int	zc_csr;		/* ctrl,status, and indirect access */
    132  1.5.2.2  bouyer 	u_int		zc_pad0;
    133  1.5.2.2  bouyer 	volatile u_int	zc_data;	/* data */
    134  1.5.2.2  bouyer 	u_int		sc_pad1;
    135  1.5.2.2  bouyer #endif
    136  1.5.2.2  bouyer #if defined(pmax)
    137  1.5.2.2  bouyer 	volatile u_int16_t zc_csr;	/* ctrl,status, and indirect access */
    138  1.5.2.2  bouyer 	unsigned : 16;
    139  1.5.2.2  bouyer 	volatile u_int16_t zc_data;	/* data */
    140  1.5.2.2  bouyer 	unsigned : 16;
    141  1.5.2.2  bouyer #endif
    142  1.5.2.2  bouyer };
    143  1.5.2.2  bouyer 
    144  1.5.2.2  bouyer struct zsdevice {
    145  1.5.2.2  bouyer 	/* Yes, they are backwards. */
    146  1.5.2.2  bouyer 	struct	zshan zs_chan_b;
    147  1.5.2.2  bouyer 	struct	zshan zs_chan_a;
    148  1.5.2.2  bouyer };
    149  1.5.2.2  bouyer 
    150  1.5.2.2  bouyer static u_char zs_ioasic_init_reg[16] = {
    151  1.5.2.2  bouyer 	0,	/* 0: CMD (reset, etc.) */
    152  1.5.2.2  bouyer 	0,	/* 1: No interrupts yet. */
    153  1.5.2.2  bouyer 	0xf0,	/* 2: IVECT */
    154  1.5.2.2  bouyer 	ZSWR3_RX_8 | ZSWR3_RX_ENABLE,
    155  1.5.2.2  bouyer 	ZSWR4_CLK_X16 | ZSWR4_ONESB,
    156  1.5.2.2  bouyer 	ZSWR5_TX_8 | ZSWR5_TX_ENABLE,
    157  1.5.2.2  bouyer 	0,	/* 6: TXSYNC/SYNCLO */
    158  1.5.2.2  bouyer 	0,	/* 7: RXSYNC/SYNCHI */
    159  1.5.2.2  bouyer 	0,	/* 8: alias for data port */
    160  1.5.2.2  bouyer 	ZSWR9_MASTER_IE | ZSWR9_VECTOR_INCL_STAT,
    161  1.5.2.2  bouyer 	0,	/*10: Misc. TX/RX control bits */
    162  1.5.2.2  bouyer 	ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD,
    163  1.5.2.2  bouyer 	22,	/*12: BAUDLO (default=9600) */
    164  1.5.2.2  bouyer 	0,	/*13: BAUDHI (default=9600) */
    165  1.5.2.2  bouyer 	ZSWR14_BAUD_ENA | ZSWR14_BAUD_FROM_PCLK,
    166  1.5.2.2  bouyer 	ZSWR15_BREAK_IE,
    167  1.5.2.2  bouyer };
    168  1.5.2.2  bouyer 
    169  1.5.2.2  bouyer struct zshan *zs_ioasic_get_chan_addr __P((tc_addr_t, int));
    170  1.5.2.2  bouyer 
    171  1.5.2.2  bouyer struct zshan *
    172  1.5.2.2  bouyer zs_ioasic_get_chan_addr(zsaddr, channel)
    173  1.5.2.2  bouyer 	tc_addr_t zsaddr;
    174  1.5.2.2  bouyer 	int channel;
    175  1.5.2.2  bouyer {
    176  1.5.2.2  bouyer 	struct zsdevice *addr;
    177  1.5.2.2  bouyer 	struct zshan *zc;
    178  1.5.2.2  bouyer 
    179  1.5.2.2  bouyer #if defined(__alpha__) || defined(alpha)
    180  1.5.2.2  bouyer 	addr = (struct zsdevice *)TC_DENSE_TO_SPARSE(zsaddr);
    181  1.5.2.2  bouyer #endif
    182  1.5.2.2  bouyer #if defined(pmax)
    183  1.5.2.2  bouyer 	addr = (struct zsdevice *)MIPS_PHYS_TO_KSEG1(zsaddr);
    184  1.5.2.2  bouyer #endif
    185  1.5.2.2  bouyer 
    186  1.5.2.2  bouyer 	if (channel == 0)
    187  1.5.2.2  bouyer 		zc = &addr->zs_chan_a;
    188  1.5.2.2  bouyer 	else
    189  1.5.2.2  bouyer 		zc = &addr->zs_chan_b;
    190  1.5.2.2  bouyer 
    191  1.5.2.2  bouyer 	return (zc);
    192  1.5.2.2  bouyer }
    193  1.5.2.2  bouyer 
    194  1.5.2.2  bouyer 
    195  1.5.2.2  bouyer /****************************************************************
    196  1.5.2.2  bouyer  * Autoconfig
    197  1.5.2.2  bouyer  ****************************************************************/
    198  1.5.2.2  bouyer 
    199  1.5.2.2  bouyer /* Definition of the driver for autoconfig. */
    200  1.5.2.2  bouyer int	zs_ioasic_match __P((struct device *, struct cfdata *, void *));
    201  1.5.2.2  bouyer void	zs_ioasic_attach __P((struct device *, struct device *, void *));
    202  1.5.2.2  bouyer int	zs_ioasic_print __P((void *, const char *name));
    203  1.5.2.2  bouyer int	zs_ioasic_submatch __P((struct device *, struct cfdata *, void *));
    204  1.5.2.2  bouyer 
    205  1.5.2.2  bouyer struct cfattach zsc_ioasic_ca = {
    206  1.5.2.2  bouyer 	sizeof(struct zsc_softc), zs_ioasic_match, zs_ioasic_attach
    207  1.5.2.2  bouyer };
    208  1.5.2.2  bouyer 
    209  1.5.2.2  bouyer /* Interrupt handlers. */
    210  1.5.2.2  bouyer int	zs_ioasic_hardintr __P((void *));
    211  1.5.2.2  bouyer void	zs_ioasic_softintr __P((void *));
    212  1.5.2.2  bouyer 
    213  1.5.2.2  bouyer extern struct cfdriver ioasic_cd;
    214  1.5.2.2  bouyer 
    215  1.5.2.2  bouyer /*
    216  1.5.2.2  bouyer  * Is the zs chip present?
    217  1.5.2.2  bouyer  */
    218  1.5.2.2  bouyer int
    219  1.5.2.2  bouyer zs_ioasic_match(parent, cf, aux)
    220  1.5.2.2  bouyer 	struct device *parent;
    221  1.5.2.2  bouyer 	struct cfdata *cf;
    222  1.5.2.2  bouyer 	void *aux;
    223  1.5.2.2  bouyer {
    224  1.5.2.2  bouyer 	struct ioasicdev_attach_args *d = aux;
    225  1.5.2.2  bouyer 	void *zs_addr;
    226  1.5.2.2  bouyer 
    227  1.5.2.2  bouyer 	if (parent->dv_cfdata->cf_driver != &ioasic_cd)
    228  1.5.2.2  bouyer 		return (0);
    229  1.5.2.2  bouyer 
    230  1.5.2.2  bouyer 	/*
    231  1.5.2.2  bouyer 	 * Make sure that we're looking for the right kind of device.
    232  1.5.2.2  bouyer 	 */
    233  1.5.2.2  bouyer 	if (strncmp(d->iada_modname, "z8530   ", TC_ROM_LLEN) != 0 &&
    234  1.5.2.2  bouyer 	    strncmp(d->iada_modname, "scc", TC_ROM_LLEN) != 0)
    235  1.5.2.2  bouyer 		return (0);
    236  1.5.2.2  bouyer 
    237  1.5.2.2  bouyer 	/*
    238  1.5.2.2  bouyer 	 * Check user-specified offset against the ioasic offset.
    239  1.5.2.2  bouyer 	 * Allow it to be wildcarded.
    240  1.5.2.2  bouyer 	 */
    241  1.5.2.2  bouyer 	if (cf->cf_loc[IOASICCF_OFFSET] != IOASICCF_OFFSET_DEFAULT &&
    242  1.5.2.2  bouyer 	    cf->cf_loc[IOASICCF_OFFSET] != d->iada_offset)
    243  1.5.2.2  bouyer 		return (0);
    244  1.5.2.2  bouyer 
    245  1.5.2.2  bouyer 	/*
    246  1.5.2.2  bouyer 	 * Find out the device address, and check it for validity.
    247  1.5.2.2  bouyer 	 */
    248  1.5.2.2  bouyer 	zs_addr = (void *) TC_DENSE_TO_SPARSE((tc_addr_t) zs_addr);
    249  1.5.2.2  bouyer 	if (tc_badaddr(zs_addr))
    250  1.5.2.2  bouyer 		return (0);
    251  1.5.2.2  bouyer 
    252  1.5.2.2  bouyer 	return (1);
    253  1.5.2.2  bouyer }
    254  1.5.2.2  bouyer 
    255  1.5.2.2  bouyer /*
    256  1.5.2.2  bouyer  * Attach a found zs.
    257  1.5.2.2  bouyer  */
    258  1.5.2.2  bouyer void
    259  1.5.2.2  bouyer zs_ioasic_attach(parent, self, aux)
    260  1.5.2.2  bouyer 	struct device *parent;
    261  1.5.2.2  bouyer 	struct device *self;
    262  1.5.2.2  bouyer 	void *aux;
    263  1.5.2.2  bouyer {
    264  1.5.2.2  bouyer 	struct zsc_softc *zs = (void *) self;
    265  1.5.2.2  bouyer 	struct zsc_attach_args zs_args;
    266  1.5.2.2  bouyer 	struct zs_chanstate *cs;
    267  1.5.2.2  bouyer 	struct ioasicdev_attach_args *d = aux;
    268  1.5.2.2  bouyer 	struct zshan *zc;
    269  1.5.2.2  bouyer 	int s, channel;
    270  1.5.2.2  bouyer 
    271  1.5.2.2  bouyer 	printf("\n");
    272  1.5.2.2  bouyer 
    273  1.5.2.2  bouyer 	/*
    274  1.5.2.2  bouyer 	 * Initialize software state for each channel.
    275  1.5.2.2  bouyer 	 */
    276  1.5.2.2  bouyer 	for (channel = 0; channel < 2; channel++) {
    277  1.5.2.2  bouyer 		zs_args.channel = channel;
    278  1.5.2.2  bouyer 		zs_args.hwflags = 0;
    279  1.5.2.2  bouyer 
    280  1.5.2.2  bouyer 		if (zs_ioasic_isconsole(d->iada_offset, channel)) {
    281  1.5.2.2  bouyer 			cs = &zs_ioasic_conschanstate_store;
    282  1.5.2.2  bouyer 			zs_args.hwflags |= ZS_HWFLAG_CONSOLE;
    283  1.5.2.2  bouyer 		} else {
    284  1.5.2.2  bouyer 			cs = malloc(sizeof(struct zs_chanstate),
    285  1.5.2.2  bouyer 					M_DEVBUF, M_NOWAIT);
    286  1.5.2.2  bouyer 			zc = zs_ioasic_get_chan_addr(d->iada_addr, channel);
    287  1.5.2.2  bouyer 			cs->cs_reg_csr = (void *)&zc->zc_csr;
    288  1.5.2.2  bouyer 
    289  1.5.2.2  bouyer 			bcopy(zs_ioasic_init_reg, cs->cs_creg, 16);
    290  1.5.2.2  bouyer 			bcopy(zs_ioasic_init_reg, cs->cs_preg, 16);
    291  1.5.2.2  bouyer 
    292  1.5.2.2  bouyer 			cs->cs_defcflag = zs_def_cflag;
    293  1.5.2.2  bouyer 			cs->cs_defspeed = 9600;		/* XXX */
    294  1.5.2.2  bouyer 			(void) zs_set_modes(cs, cs->cs_defcflag);
    295  1.5.2.2  bouyer 		}
    296  1.5.2.2  bouyer 
    297  1.5.2.2  bouyer 		zs->zsc_cs[channel] = cs;
    298  1.5.2.2  bouyer 		zs->zsc_addroffset = d->iada_offset; /* cookie only */
    299  1.5.2.2  bouyer 		cs->cs_channel = channel;
    300  1.5.2.2  bouyer 		cs->cs_ops = &zsops_null;
    301  1.5.2.2  bouyer 		cs->cs_brg_clk = PCLK / 16;
    302  1.5.2.2  bouyer 
    303  1.5.2.2  bouyer 		/*
    304  1.5.2.2  bouyer 		 * DCD and CTS interrupts are only meaningful on
    305  1.5.2.2  bouyer 		 * SCC 0/B.
    306  1.5.2.2  bouyer 		 *
    307  1.5.2.2  bouyer 		 * XXX This is sorta gross.
    308  1.5.2.2  bouyer 		 */
    309  1.5.2.2  bouyer 		if (d->iada_offset == 0x00100000 && channel == 1) {
    310  1.5.2.2  bouyer 			cs->cs_creg[15] |= ZSWR15_DCD_IE;
    311  1.5.2.2  bouyer 			cs->cs_preg[15] |= ZSWR15_DCD_IE;
    312  1.5.2.2  bouyer 			(u_long)cs->cs_private = ZIP_FLAGS_DCDCTS;
    313  1.5.2.2  bouyer 		}
    314  1.5.2.2  bouyer 		else
    315  1.5.2.2  bouyer 			cs->cs_private = NULL;
    316  1.5.2.2  bouyer 
    317  1.5.2.2  bouyer 		/*
    318  1.5.2.2  bouyer 		 * Clear the master interrupt enable.
    319  1.5.2.2  bouyer 		 * The INTENA is common to both channels,
    320  1.5.2.2  bouyer 		 * so just do it on the A channel.
    321  1.5.2.2  bouyer 		 */
    322  1.5.2.2  bouyer 		if (channel == 0) {
    323  1.5.2.2  bouyer 			zs_write_reg(cs, 9, 0);
    324  1.5.2.2  bouyer 		}
    325  1.5.2.2  bouyer 
    326  1.5.2.2  bouyer #ifdef notyet /* XXX thorpej */
    327  1.5.2.2  bouyer 		/*
    328  1.5.2.2  bouyer 		 * Set up the flow/modem control channel pointer to
    329  1.5.2.2  bouyer 		 * deal with the weird wiring on the TC Alpha and
    330  1.5.2.2  bouyer 		 * DECstation.
    331  1.5.2.2  bouyer 		 */
    332  1.5.2.2  bouyer 		if (channel == 1)
    333  1.5.2.2  bouyer 			cs->cs_ctl_chan = zs->zsc_cs[0];
    334  1.5.2.2  bouyer 		else
    335  1.5.2.2  bouyer 			cs->cs_ctl_chan = NULL;
    336  1.5.2.2  bouyer #endif
    337  1.5.2.2  bouyer 
    338  1.5.2.2  bouyer 		/*
    339  1.5.2.2  bouyer 		 * Look for a child driver for this channel.
    340  1.5.2.2  bouyer 		 * The child attach will setup the hardware.
    341  1.5.2.2  bouyer 		 */
    342  1.5.2.2  bouyer 		if (config_found_sm(self, (void *)&zs_args,
    343  1.5.2.2  bouyer 				zs_ioasic_print, zs_ioasic_submatch) == NULL) {
    344  1.5.2.2  bouyer 			/* No sub-driver.  Just reset it. */
    345  1.5.2.2  bouyer 			u_char reset = (channel == 0) ?
    346  1.5.2.2  bouyer 				ZSWR9_A_RESET : ZSWR9_B_RESET;
    347  1.5.2.2  bouyer 			s = splhigh();
    348  1.5.2.2  bouyer 			zs_write_reg(cs, 9, reset);
    349  1.5.2.2  bouyer 			splx(s);
    350  1.5.2.2  bouyer 		}
    351  1.5.2.2  bouyer 	}
    352  1.5.2.2  bouyer 
    353  1.5.2.2  bouyer 	/*
    354  1.5.2.2  bouyer 	 * Set up the ioasic interrupt handler.
    355  1.5.2.2  bouyer 	 */
    356  1.5.2.2  bouyer 	ioasic_intr_establish(parent, d->iada_cookie, TC_IPL_TTY,
    357  1.5.2.2  bouyer 	    zs_ioasic_hardintr, zs);
    358  1.5.2.2  bouyer 	zs->zsc_sih = softintr_establish(IPL_SOFTSERIAL,
    359  1.5.2.2  bouyer 	    zs_ioasic_softintr, zs);
    360  1.5.2.2  bouyer 	if (zs->zsc_sih == NULL)
    361  1.5.2.2  bouyer 		panic("zs_ioasic_attach: unable to register softintr");
    362  1.5.2.2  bouyer 
    363  1.5.2.2  bouyer 	/*
    364  1.5.2.2  bouyer 	 * Set the master interrupt enable and interrupt vector.  The
    365  1.5.2.2  bouyer 	 * Sun does this only on one channel.  The old Alpha SCC driver
    366  1.5.2.2  bouyer 	 * did it on both.  We'll do it on both.
    367  1.5.2.2  bouyer 	 */
    368  1.5.2.2  bouyer 	s = splhigh();
    369  1.5.2.2  bouyer 	/* interrupt vector */
    370  1.5.2.2  bouyer 	zs_write_reg(zs->zsc_cs[0], 2, zs_ioasic_init_reg[2]);
    371  1.5.2.2  bouyer 	zs_write_reg(zs->zsc_cs[1], 2, zs_ioasic_init_reg[2]);
    372  1.5.2.2  bouyer 
    373  1.5.2.2  bouyer 	/* master interrupt control (enable) */
    374  1.5.2.2  bouyer 	zs_write_reg(zs->zsc_cs[0], 9, zs_ioasic_init_reg[9]);
    375  1.5.2.2  bouyer 	zs_write_reg(zs->zsc_cs[1], 9, zs_ioasic_init_reg[9]);
    376  1.5.2.2  bouyer #if defined(__alpha__) || defined(alpha)
    377  1.5.2.2  bouyer 	/* ioasic interrupt enable */
    378  1.5.2.2  bouyer 	*(volatile u_int *)(ioasic_base + IOASIC_IMSK) |=
    379  1.5.2.2  bouyer 		    IOASIC_INTR_SCC_1 | IOASIC_INTR_SCC_0;
    380  1.5.2.2  bouyer 	tc_mb();
    381  1.5.2.2  bouyer #endif
    382  1.5.2.2  bouyer 	splx(s);
    383  1.5.2.2  bouyer }
    384  1.5.2.2  bouyer 
    385  1.5.2.2  bouyer int
    386  1.5.2.2  bouyer zs_ioasic_print(aux, name)
    387  1.5.2.2  bouyer 	void *aux;
    388  1.5.2.2  bouyer 	const char *name;
    389  1.5.2.2  bouyer {
    390  1.5.2.2  bouyer 	struct zsc_attach_args *args = aux;
    391  1.5.2.2  bouyer 
    392  1.5.2.2  bouyer 	if (name != NULL)
    393  1.5.2.2  bouyer 		printf("%s:", name);
    394  1.5.2.2  bouyer 
    395  1.5.2.2  bouyer 	if (args->channel != -1)
    396  1.5.2.2  bouyer 		printf(" channel %d", args->channel);
    397  1.5.2.2  bouyer 
    398  1.5.2.2  bouyer 	return (UNCONF);
    399  1.5.2.2  bouyer }
    400  1.5.2.2  bouyer 
    401  1.5.2.2  bouyer int
    402  1.5.2.2  bouyer zs_ioasic_submatch(parent, cf, aux)
    403  1.5.2.2  bouyer 	struct device *parent;
    404  1.5.2.2  bouyer 	struct cfdata *cf;
    405  1.5.2.2  bouyer 	void *aux;
    406  1.5.2.2  bouyer {
    407  1.5.2.2  bouyer 	struct zsc_softc *zs = (void *)parent;
    408  1.5.2.2  bouyer 	struct zsc_attach_args *pa = aux;
    409  1.5.2.2  bouyer 	char *defname = "";
    410  1.5.2.2  bouyer 
    411  1.5.2.2  bouyer 	if (cf->cf_loc[ZSCCF_CHANNEL] != ZSCCF_CHANNEL_DEFAULT &&
    412  1.5.2.2  bouyer 	    cf->cf_loc[ZSCCF_CHANNEL] != pa->channel)
    413  1.5.2.2  bouyer 		return (0);
    414  1.5.2.2  bouyer 	if (cf->cf_loc[ZSCCF_CHANNEL] == ZSCCF_CHANNEL_DEFAULT) {
    415  1.5.2.2  bouyer 		if (pa->channel == 0) {
    416  1.5.2.2  bouyer #if defined(pmax)
    417  1.5.2.2  bouyer 			if (systype == DS_MAXINE)
    418  1.5.2.2  bouyer 				return (0);
    419  1.5.2.2  bouyer #endif
    420  1.5.2.2  bouyer 			if (zs->zsc_addroffset == 0x100000)
    421  1.5.2.2  bouyer 				defname = "vsms";
    422  1.5.2.2  bouyer 			else
    423  1.5.2.2  bouyer 				defname = "lkkbd";
    424  1.5.2.2  bouyer 		}
    425  1.5.2.2  bouyer 		else if (zs->zsc_addroffset == 0x100000)
    426  1.5.2.2  bouyer 			defname = "zstty";
    427  1.5.2.2  bouyer #if defined(pmax)
    428  1.5.2.2  bouyer 		else if (systype == DS_MAXINE)
    429  1.5.2.2  bouyer 			return (0);
    430  1.5.2.2  bouyer #endif
    431  1.5.2.2  bouyer #if defined(__alpha__) || defined(alpha)
    432  1.5.2.2  bouyer 		else if (cputype == ST_DEC_3000_300)
    433  1.5.2.2  bouyer 			return (0);
    434  1.5.2.2  bouyer #endif
    435  1.5.2.2  bouyer 		else
    436  1.5.2.2  bouyer 			defname = "zstty"; /* 3min/3max+, DEC3000/500 */
    437  1.5.2.2  bouyer 
    438  1.5.2.2  bouyer 		if (strcmp(cf->cf_driver->cd_name, defname))
    439  1.5.2.2  bouyer 			return (0);
    440  1.5.2.2  bouyer 	}
    441  1.5.2.2  bouyer 	return ((*cf->cf_attach->ca_match)(parent, cf, aux));
    442  1.5.2.2  bouyer }
    443  1.5.2.2  bouyer 
    444  1.5.2.2  bouyer /*
    445  1.5.2.2  bouyer  * Hardware interrupt handler.
    446  1.5.2.2  bouyer  */
    447  1.5.2.2  bouyer int
    448  1.5.2.2  bouyer zs_ioasic_hardintr(arg)
    449  1.5.2.2  bouyer 	void *arg;
    450  1.5.2.2  bouyer {
    451  1.5.2.2  bouyer 	struct zsc_softc *zsc = arg;
    452  1.5.2.2  bouyer 
    453  1.5.2.2  bouyer 	/*
    454  1.5.2.2  bouyer 	 * Call the upper-level MI hardware interrupt handler.
    455  1.5.2.2  bouyer 	 */
    456  1.5.2.2  bouyer 	zsc_intr_hard(zsc);
    457  1.5.2.2  bouyer 
    458  1.5.2.2  bouyer 	/*
    459  1.5.2.2  bouyer 	 * Check to see if we need to schedule any software-level
    460  1.5.2.2  bouyer 	 * processing interrupts.
    461  1.5.2.2  bouyer 	 */
    462  1.5.2.2  bouyer 	if (zsc->zsc_cs[0]->cs_softreq | zsc->zsc_cs[1]->cs_softreq)
    463  1.5.2.2  bouyer 		softintr_schedule(zsc->zsc_sih);
    464  1.5.2.2  bouyer 
    465  1.5.2.2  bouyer 	return (1);
    466  1.5.2.2  bouyer }
    467  1.5.2.2  bouyer 
    468  1.5.2.2  bouyer /*
    469  1.5.2.2  bouyer  * Software-level interrupt (character processing, lower priority).
    470  1.5.2.2  bouyer  */
    471  1.5.2.2  bouyer void
    472  1.5.2.2  bouyer zs_ioasic_softintr(arg)
    473  1.5.2.2  bouyer 	void *arg;
    474  1.5.2.2  bouyer {
    475  1.5.2.2  bouyer 	struct zsc_softc *zsc = arg;
    476  1.5.2.2  bouyer 	int s;
    477  1.5.2.2  bouyer 
    478  1.5.2.2  bouyer 	s = spltty();
    479  1.5.2.2  bouyer 	(void) zsc_intr_soft(zsc);
    480  1.5.2.2  bouyer 	splx(s);
    481  1.5.2.2  bouyer }
    482  1.5.2.2  bouyer 
    483  1.5.2.2  bouyer /*
    484  1.5.2.2  bouyer  * MD functions for setting the baud rate and control modes.
    485  1.5.2.2  bouyer  */
    486  1.5.2.2  bouyer int
    487  1.5.2.2  bouyer zs_set_speed(cs, bps)
    488  1.5.2.2  bouyer 	struct zs_chanstate *cs;
    489  1.5.2.2  bouyer 	int bps;	/* bits per second */
    490  1.5.2.2  bouyer {
    491  1.5.2.2  bouyer 	int tconst, real_bps;
    492  1.5.2.2  bouyer 
    493  1.5.2.2  bouyer 	if (bps == 0)
    494  1.5.2.2  bouyer 		return (0);
    495  1.5.2.2  bouyer 
    496  1.5.2.2  bouyer #ifdef DIAGNOSTIC
    497  1.5.2.2  bouyer 	if (cs->cs_brg_clk == 0)
    498  1.5.2.2  bouyer 		panic("zs_set_speed");
    499  1.5.2.2  bouyer #endif
    500  1.5.2.2  bouyer 
    501  1.5.2.2  bouyer 	tconst = BPS_TO_TCONST(cs->cs_brg_clk, bps);
    502  1.5.2.2  bouyer 	if (tconst < 0)
    503  1.5.2.2  bouyer 		return (EINVAL);
    504  1.5.2.2  bouyer 
    505  1.5.2.2  bouyer 	/* Convert back to make sure we can do it. */
    506  1.5.2.2  bouyer 	real_bps = TCONST_TO_BPS(cs->cs_brg_clk, tconst);
    507  1.5.2.2  bouyer 
    508  1.5.2.2  bouyer 	/* XXX - Allow some tolerance here? */
    509  1.5.2.2  bouyer 	if (real_bps != bps)
    510  1.5.2.2  bouyer 		return (EINVAL);
    511  1.5.2.2  bouyer 
    512  1.5.2.2  bouyer 	cs->cs_preg[12] = tconst;
    513  1.5.2.2  bouyer 	cs->cs_preg[13] = tconst >> 8;
    514  1.5.2.2  bouyer 
    515  1.5.2.2  bouyer 	/* Caller will stuff the pending registers. */
    516  1.5.2.2  bouyer 	return (0);
    517  1.5.2.2  bouyer }
    518  1.5.2.2  bouyer 
    519  1.5.2.2  bouyer int
    520  1.5.2.2  bouyer zs_set_modes(cs, cflag)
    521  1.5.2.2  bouyer 	struct zs_chanstate *cs;
    522  1.5.2.2  bouyer 	int cflag;	/* bits per second */
    523  1.5.2.2  bouyer {
    524  1.5.2.2  bouyer 	u_long privflags = (u_long)cs->cs_private;
    525  1.5.2.2  bouyer 	int s;
    526  1.5.2.2  bouyer 
    527  1.5.2.2  bouyer 	/*
    528  1.5.2.2  bouyer 	 * Output hardware flow control on the chip is horrendous:
    529  1.5.2.2  bouyer 	 * if carrier detect drops, the receiver is disabled, and if
    530  1.5.2.2  bouyer 	 * CTS drops, the transmitter is stoped IN MID CHARACTER!
    531  1.5.2.2  bouyer 	 * Therefore, NEVER set the HFC bit, and instead use the
    532  1.5.2.2  bouyer 	 * status interrupt to detect CTS changes.
    533  1.5.2.2  bouyer 	 */
    534  1.5.2.2  bouyer 	s = splzs();
    535  1.5.2.2  bouyer 	if ((cflag & (CLOCAL | MDMBUF)) != 0)
    536  1.5.2.2  bouyer 		cs->cs_rr0_dcd = 0;
    537  1.5.2.2  bouyer 	else
    538  1.5.2.2  bouyer 		cs->cs_rr0_dcd = ZSRR0_DCD;
    539  1.5.2.2  bouyer 	if ((cflag & CRTSCTS) != 0) {
    540  1.5.2.2  bouyer 		cs->cs_wr5_dtr = ZSWR5_DTR;
    541  1.5.2.2  bouyer 		cs->cs_wr5_rts = ZSWR5_RTS;
    542  1.5.2.2  bouyer 		cs->cs_rr0_cts = ZSRR0_CTS;
    543  1.5.2.2  bouyer 	} else if ((cflag & CDTRCTS) != 0) {
    544  1.5.2.2  bouyer 		cs->cs_wr5_dtr = 0;
    545  1.5.2.2  bouyer 		cs->cs_wr5_rts = ZSWR5_DTR;
    546  1.5.2.2  bouyer 		cs->cs_rr0_cts = ZSRR0_CTS;
    547  1.5.2.2  bouyer 	} else if ((cflag & MDMBUF) != 0) {
    548  1.5.2.2  bouyer 		cs->cs_wr5_dtr = 0;
    549  1.5.2.2  bouyer 		cs->cs_wr5_rts = ZSWR5_DTR;
    550  1.5.2.2  bouyer 		cs->cs_rr0_cts = ZSRR0_DCD;
    551  1.5.2.2  bouyer 	} else {
    552  1.5.2.2  bouyer 		cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
    553  1.5.2.2  bouyer 		cs->cs_wr5_rts = 0;
    554  1.5.2.2  bouyer 		cs->cs_rr0_cts = 0;
    555  1.5.2.2  bouyer 	}
    556  1.5.2.2  bouyer 
    557  1.5.2.2  bouyer 	if ((privflags & ZIP_FLAGS_DCDCTS) == 0) {
    558  1.5.2.2  bouyer 		cs->cs_rr0_dcd &= ~(ZSRR0_CTS|ZSRR0_DCD);
    559  1.5.2.2  bouyer 		cs->cs_rr0_cts &= ~(ZSRR0_CTS|ZSRR0_DCD);
    560  1.5.2.2  bouyer 	}
    561  1.5.2.2  bouyer 	splx(s);
    562  1.5.2.2  bouyer 
    563  1.5.2.2  bouyer 	/* Caller will stuff the pending registers. */
    564  1.5.2.2  bouyer 	return (0);
    565  1.5.2.2  bouyer }
    566  1.5.2.2  bouyer 
    567  1.5.2.2  bouyer /*
    568  1.5.2.2  bouyer  * Functions to read and write individual registers in a channel.
    569  1.5.2.2  bouyer  * The ZS chip requires a 1.6 uSec. recovery time between accesses,
    570  1.5.2.2  bouyer  * and the Alpha TC hardware does NOT take care of this for you.
    571  1.5.2.2  bouyer  * The delay is now handled inside the chip access functions.
    572  1.5.2.2  bouyer  * These could be inlines, but with the delay, speed is moot.
    573  1.5.2.2  bouyer  */
    574  1.5.2.2  bouyer #if defined(pmax)
    575  1.5.2.2  bouyer #undef	DELAY
    576  1.5.2.2  bouyer #define	DELAY(x)
    577  1.5.2.2  bouyer #endif
    578  1.5.2.2  bouyer 
    579  1.5.2.2  bouyer u_int
    580  1.5.2.2  bouyer zs_read_reg(cs, reg)
    581  1.5.2.2  bouyer 	struct zs_chanstate *cs;
    582  1.5.2.2  bouyer 	u_int reg;
    583  1.5.2.2  bouyer {
    584  1.5.2.2  bouyer 	struct zshan *zc = (void *)cs->cs_reg_csr;
    585  1.5.2.2  bouyer 	unsigned val;
    586  1.5.2.2  bouyer 
    587  1.5.2.2  bouyer 	zc->zc_csr = reg << 8;
    588  1.5.2.2  bouyer 	tc_wmb();
    589  1.5.2.2  bouyer 	DELAY(5);
    590  1.5.2.2  bouyer 	val = (zc->zc_csr >> 8) & 0xff;
    591  1.5.2.2  bouyer 	/* tc_mb(); */
    592  1.5.2.2  bouyer 	DELAY(5);
    593  1.5.2.2  bouyer 	return (val);
    594  1.5.2.2  bouyer }
    595  1.5.2.2  bouyer 
    596  1.5.2.2  bouyer void
    597  1.5.2.2  bouyer zs_write_reg(cs, reg, val)
    598  1.5.2.2  bouyer 	struct zs_chanstate *cs;
    599  1.5.2.2  bouyer 	u_int reg, val;
    600  1.5.2.2  bouyer {
    601  1.5.2.2  bouyer 	struct zshan *zc = (void *)cs->cs_reg_csr;
    602  1.5.2.2  bouyer 
    603  1.5.2.2  bouyer 	zc->zc_csr = reg << 8;
    604  1.5.2.2  bouyer 	tc_wmb();
    605  1.5.2.2  bouyer 	DELAY(5);
    606  1.5.2.2  bouyer 	zc->zc_csr = val << 8;
    607  1.5.2.2  bouyer 	tc_wmb();
    608  1.5.2.2  bouyer 	DELAY(5);
    609  1.5.2.2  bouyer }
    610  1.5.2.2  bouyer 
    611  1.5.2.2  bouyer u_int
    612  1.5.2.2  bouyer zs_read_csr(cs)
    613  1.5.2.2  bouyer 	struct zs_chanstate *cs;
    614  1.5.2.2  bouyer {
    615  1.5.2.2  bouyer 	struct zshan *zc = (void *)cs->cs_reg_csr;
    616  1.5.2.2  bouyer 	unsigned val;
    617  1.5.2.2  bouyer 
    618  1.5.2.2  bouyer 	val = (zc->zc_csr >> 8) & 0xff;
    619  1.5.2.2  bouyer 	/* tc_mb(); */
    620  1.5.2.2  bouyer 	DELAY(5);
    621  1.5.2.2  bouyer 	return (val);
    622  1.5.2.2  bouyer }
    623  1.5.2.2  bouyer 
    624  1.5.2.2  bouyer void
    625  1.5.2.2  bouyer zs_write_csr(cs, val)
    626  1.5.2.2  bouyer 	struct zs_chanstate *cs;
    627  1.5.2.2  bouyer 	u_int val;
    628  1.5.2.2  bouyer {
    629  1.5.2.2  bouyer 	struct zshan *zc = (void *)cs->cs_reg_csr;
    630  1.5.2.2  bouyer 
    631  1.5.2.2  bouyer 	zc->zc_csr = val << 8;
    632  1.5.2.2  bouyer 	tc_wmb();
    633  1.5.2.2  bouyer 	DELAY(5);
    634  1.5.2.2  bouyer }
    635  1.5.2.2  bouyer 
    636  1.5.2.2  bouyer u_int
    637  1.5.2.2  bouyer zs_read_data(cs)
    638  1.5.2.2  bouyer 	struct zs_chanstate *cs;
    639  1.5.2.2  bouyer {
    640  1.5.2.2  bouyer 	struct zshan *zc = (void *)cs->cs_reg_csr;
    641  1.5.2.2  bouyer 	unsigned val;
    642  1.5.2.2  bouyer 
    643  1.5.2.2  bouyer 	val = (zc->zc_data) >> 8 & 0xff;
    644  1.5.2.2  bouyer 	/* tc_mb(); */
    645  1.5.2.2  bouyer 	DELAY(5);
    646  1.5.2.2  bouyer 	return (val);
    647  1.5.2.2  bouyer }
    648  1.5.2.2  bouyer 
    649  1.5.2.2  bouyer void
    650  1.5.2.2  bouyer zs_write_data(cs, val)
    651  1.5.2.2  bouyer 	struct zs_chanstate *cs;
    652  1.5.2.2  bouyer 	u_int val;
    653  1.5.2.2  bouyer {
    654  1.5.2.2  bouyer 	struct zshan *zc = (void *)cs->cs_reg_csr;
    655  1.5.2.2  bouyer 
    656  1.5.2.2  bouyer 	zc->zc_data = val << 8;
    657  1.5.2.2  bouyer 	tc_wmb();
    658  1.5.2.2  bouyer 	DELAY(5);
    659  1.5.2.2  bouyer }
    660  1.5.2.2  bouyer 
    661  1.5.2.2  bouyer /****************************************************************
    662  1.5.2.2  bouyer  * Console support functions
    663  1.5.2.2  bouyer  ****************************************************************/
    664  1.5.2.2  bouyer 
    665  1.5.2.2  bouyer /*
    666  1.5.2.2  bouyer  * Handle user request to enter kernel debugger.
    667  1.5.2.2  bouyer  */
    668  1.5.2.2  bouyer void
    669  1.5.2.2  bouyer zs_abort(cs)
    670  1.5.2.2  bouyer 	struct zs_chanstate *cs;
    671  1.5.2.2  bouyer {
    672  1.5.2.2  bouyer 	int rr0;
    673  1.5.2.2  bouyer 
    674  1.5.2.2  bouyer 	/* Wait for end of break. */
    675  1.5.2.2  bouyer 	/* XXX - Limit the wait? */
    676  1.5.2.2  bouyer 	do {
    677  1.5.2.2  bouyer 		rr0 = zs_read_csr(cs);
    678  1.5.2.2  bouyer 	} while (rr0 & ZSRR0_BREAK);
    679  1.5.2.2  bouyer 
    680  1.5.2.2  bouyer #if defined(KGDB)
    681  1.5.2.2  bouyer 	zskgdb(cs);
    682  1.5.2.2  bouyer #elif defined(DDB)
    683  1.5.2.2  bouyer 	Debugger();
    684  1.5.2.2  bouyer #else
    685  1.5.2.2  bouyer 	printf("zs_abort: ignoring break on console\n");
    686  1.5.2.2  bouyer #endif
    687  1.5.2.2  bouyer }
    688  1.5.2.2  bouyer 
    689  1.5.2.2  bouyer /*
    690  1.5.2.2  bouyer  * Polled input char.
    691  1.5.2.2  bouyer  */
    692  1.5.2.2  bouyer int
    693  1.5.2.2  bouyer zs_getc(cs)
    694  1.5.2.2  bouyer 	struct zs_chanstate *cs;
    695  1.5.2.2  bouyer {
    696  1.5.2.2  bouyer 	int s, c, rr0;
    697  1.5.2.2  bouyer 
    698  1.5.2.2  bouyer 	s = splhigh();
    699  1.5.2.2  bouyer 	/* Wait for a character to arrive. */
    700  1.5.2.2  bouyer 	do {
    701  1.5.2.2  bouyer 		rr0 = zs_read_csr(cs);
    702  1.5.2.2  bouyer 	} while ((rr0 & ZSRR0_RX_READY) == 0);
    703  1.5.2.2  bouyer 
    704  1.5.2.2  bouyer 	c = zs_read_data(cs);
    705  1.5.2.2  bouyer 	splx(s);
    706  1.5.2.2  bouyer 
    707  1.5.2.2  bouyer 	/*
    708  1.5.2.2  bouyer 	 * This is used by the kd driver to read scan codes,
    709  1.5.2.2  bouyer 	 * so don't translate '\r' ==> '\n' here...
    710  1.5.2.2  bouyer 	 */
    711  1.5.2.2  bouyer 	return (c);
    712  1.5.2.2  bouyer }
    713  1.5.2.2  bouyer 
    714  1.5.2.2  bouyer /*
    715  1.5.2.2  bouyer  * Polled output char.
    716  1.5.2.2  bouyer  */
    717  1.5.2.2  bouyer void
    718  1.5.2.2  bouyer zs_putc(cs, c)
    719  1.5.2.2  bouyer 	struct zs_chanstate *cs;
    720  1.5.2.2  bouyer 	int c;
    721  1.5.2.2  bouyer {
    722  1.5.2.2  bouyer 	register int s, rr0;
    723  1.5.2.2  bouyer 
    724  1.5.2.2  bouyer 	s = splhigh();
    725  1.5.2.2  bouyer 	/* Wait for transmitter to become ready. */
    726  1.5.2.2  bouyer 	do {
    727  1.5.2.2  bouyer 		rr0 = zs_read_csr(cs);
    728  1.5.2.2  bouyer 	} while ((rr0 & ZSRR0_TX_READY) == 0);
    729  1.5.2.2  bouyer 
    730  1.5.2.2  bouyer 	zs_write_data(cs, c);
    731  1.5.2.2  bouyer 
    732  1.5.2.2  bouyer 	/* Wait for the character to be transmitted. */
    733  1.5.2.2  bouyer 	do {
    734  1.5.2.2  bouyer 		rr0 = zs_read_csr(cs);
    735  1.5.2.2  bouyer 	} while ((rr0 & ZSRR0_TX_READY) == 0);
    736  1.5.2.2  bouyer 	splx(s);
    737  1.5.2.2  bouyer }
    738  1.5.2.2  bouyer 
    739  1.5.2.2  bouyer /*****************************************************************/
    740  1.5.2.2  bouyer 
    741  1.5.2.2  bouyer /*
    742  1.5.2.2  bouyer  * zs_ioasic_cninit --
    743  1.5.2.2  bouyer  *	Initialize the serial channel for console use--either the
    744  1.5.2.2  bouyer  * primary keyboard or the serial console.
    745  1.5.2.2  bouyer  */
    746  1.5.2.2  bouyer void
    747  1.5.2.2  bouyer zs_ioasic_cninit(ioasic_addr, zs_offset, channel)
    748  1.5.2.2  bouyer 	tc_addr_t ioasic_addr;
    749  1.5.2.2  bouyer 	tc_offset_t zs_offset;
    750  1.5.2.2  bouyer 	int channel;
    751  1.5.2.2  bouyer {
    752  1.5.2.2  bouyer 	struct zs_chanstate *cs;
    753  1.5.2.2  bouyer 	tc_addr_t zs_addr;
    754  1.5.2.2  bouyer 	struct zshan *zc;
    755  1.5.2.2  bouyer 
    756  1.5.2.2  bouyer 	/*
    757  1.5.2.2  bouyer 	 * Initialize the console finder helpers.
    758  1.5.2.2  bouyer 	 */
    759  1.5.2.2  bouyer 	zs_ioasic_console_offset = zs_offset;
    760  1.5.2.2  bouyer 	zs_ioasic_console_channel = channel;
    761  1.5.2.2  bouyer 	zs_ioasic_console = 1;
    762  1.5.2.2  bouyer 
    763  1.5.2.2  bouyer 	/*
    764  1.5.2.2  bouyer 	 * Pointer to channel state.
    765  1.5.2.2  bouyer 	 */
    766  1.5.2.2  bouyer 	cs = &zs_ioasic_conschanstate_store;
    767  1.5.2.2  bouyer 
    768  1.5.2.2  bouyer 	/*
    769  1.5.2.2  bouyer 	 * Compute the physical address of the chip, "map" it via
    770  1.5.2.2  bouyer 	 * K0SEG, and then get the address of the actual channel.
    771  1.5.2.2  bouyer 	 */
    772  1.5.2.2  bouyer #if defined(__alpha__) || defined(alpha)
    773  1.5.2.2  bouyer 	zs_addr = ALPHA_PHYS_TO_K0SEG(ioasic_addr + zs_offset);
    774  1.5.2.2  bouyer #endif
    775  1.5.2.2  bouyer #if defined(pmax)
    776  1.5.2.2  bouyer 	zs_addr = MIPS_PHYS_TO_KSEG1(ioasic_addr + zs_offset);
    777  1.5.2.2  bouyer #endif
    778  1.5.2.2  bouyer 	zc = zs_ioasic_get_chan_addr(zs_addr, channel);
    779  1.5.2.2  bouyer 
    780  1.5.2.2  bouyer 	/* Setup temporary chanstate. */
    781  1.5.2.2  bouyer 	cs->cs_reg_csr = (void *)&zc->zc_csr;
    782  1.5.2.2  bouyer 
    783  1.5.2.2  bouyer 	/* Initialize the pending registers. */
    784  1.5.2.2  bouyer 	bcopy(zs_ioasic_init_reg, cs->cs_preg, 16);
    785  1.5.2.2  bouyer 	cs->cs_preg[5] |= (ZSWR5_DTR | ZSWR5_RTS);
    786  1.5.2.2  bouyer 
    787  1.5.2.2  bouyer 	/*
    788  1.5.2.2  bouyer 	 * DCD and CTS interrupts are only meaningful on
    789  1.5.2.2  bouyer 	 * SCC 0/B.
    790  1.5.2.2  bouyer 	 *
    791  1.5.2.2  bouyer 	 * XXX This is sorta gross.
    792  1.5.2.2  bouyer 	 */
    793  1.5.2.2  bouyer 	if (zs_offset == 0x00100000 && channel == 1)
    794  1.5.2.2  bouyer 		(u_long)cs->cs_private = ZIP_FLAGS_DCDCTS;
    795  1.5.2.2  bouyer 	else
    796  1.5.2.2  bouyer 		cs->cs_private = NULL;
    797  1.5.2.2  bouyer 
    798  1.5.2.2  bouyer 	/* Clear the master interrupt enable. */
    799  1.5.2.2  bouyer 	zs_write_reg(cs, 9, 0);
    800  1.5.2.2  bouyer 
    801  1.5.2.2  bouyer 	/* Reset the whole SCC chip. */
    802  1.5.2.2  bouyer 	zs_write_reg(cs, 9, ZSWR9_HARD_RESET);
    803  1.5.2.2  bouyer 
    804  1.5.2.2  bouyer 	/* Copy "pending" to "current" and H/W. */
    805  1.5.2.2  bouyer 	zs_loadchannelregs(cs);
    806  1.5.2.2  bouyer }
    807  1.5.2.2  bouyer 
    808  1.5.2.2  bouyer /*
    809  1.5.2.2  bouyer  * zs_ioasic_cnattach --
    810  1.5.2.2  bouyer  *	Initialize and attach a serial console.
    811  1.5.2.2  bouyer  */
    812  1.5.2.2  bouyer void
    813  1.5.2.2  bouyer zs_ioasic_cnattach(ioasic_addr, zs_offset, channel)
    814  1.5.2.2  bouyer 	tc_addr_t ioasic_addr;
    815  1.5.2.2  bouyer 	tc_offset_t zs_offset;
    816  1.5.2.2  bouyer {
    817  1.5.2.2  bouyer 	struct zs_chanstate *cs = &zs_ioasic_conschanstate_store;
    818  1.5.2.2  bouyer 
    819  1.5.2.2  bouyer 	zs_ioasic_cninit(ioasic_addr, zs_offset, channel);
    820  1.5.2.2  bouyer 	cs->cs_defspeed = 9600;
    821  1.5.2.2  bouyer 	cs->cs_defcflag = (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8;
    822  1.5.2.2  bouyer 
    823  1.5.2.2  bouyer 	/* Point the console at the SCC. */
    824  1.5.2.2  bouyer 	cn_tab = &zs_ioasic_cons;
    825  1.5.2.2  bouyer 	cn_tab->cn_pri = CN_REMOTE;
    826  1.5.2.2  bouyer 	cn_tab->cn_dev = makedev(zs_major, (zs_offset == 0x100000) ? 0 : 1);
    827  1.5.2.2  bouyer }
    828  1.5.2.2  bouyer 
    829  1.5.2.2  bouyer /*
    830  1.5.2.2  bouyer  * zs_ioasic_lk201_cnattach --
    831  1.5.2.2  bouyer  *	Initialize and attach the primary keyboard.
    832  1.5.2.2  bouyer  */
    833  1.5.2.2  bouyer int
    834  1.5.2.2  bouyer zs_ioasic_lk201_cnattach(ioasic_addr, zs_offset, channel)
    835  1.5.2.2  bouyer 	tc_addr_t ioasic_addr;
    836  1.5.2.2  bouyer 	tc_offset_t zs_offset;
    837  1.5.2.2  bouyer 	int channel;
    838  1.5.2.2  bouyer {
    839  1.5.2.2  bouyer #if (NZSKBD > 0)
    840  1.5.2.2  bouyer 	struct zs_chanstate *cs = &zs_ioasic_conschanstate_store;
    841  1.5.2.2  bouyer 
    842  1.5.2.2  bouyer 	zs_ioasic_cninit(ioasic_addr, zs_offset, channel);
    843  1.5.2.2  bouyer 	cs->cs_defspeed = 4800;
    844  1.5.2.2  bouyer 	cs->cs_defcflag = (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8;
    845  1.5.2.2  bouyer 	cs->cs_brg_clk = PCLK / 16;
    846  1.5.2.2  bouyer 	return (zskbd_cnattach(cs));
    847  1.5.2.2  bouyer #else
    848  1.5.2.2  bouyer 	return (ENXIO);
    849  1.5.2.2  bouyer #endif
    850  1.5.2.2  bouyer }
    851  1.5.2.2  bouyer 
    852  1.5.2.2  bouyer int
    853  1.5.2.2  bouyer zs_ioasic_isconsole(offset, channel)
    854  1.5.2.2  bouyer 	tc_offset_t offset;
    855  1.5.2.2  bouyer 	int channel;
    856  1.5.2.2  bouyer {
    857  1.5.2.2  bouyer 
    858  1.5.2.2  bouyer 	if (zs_ioasic_console &&
    859  1.5.2.2  bouyer 	    offset == zs_ioasic_console_offset &&
    860  1.5.2.2  bouyer 	    channel == zs_ioasic_console_channel)
    861  1.5.2.2  bouyer 		return (1);
    862  1.5.2.2  bouyer 
    863  1.5.2.2  bouyer 	return (0);
    864  1.5.2.2  bouyer }
    865  1.5.2.2  bouyer 
    866  1.5.2.2  bouyer /*
    867  1.5.2.2  bouyer  * Polled console input putchar.
    868  1.5.2.2  bouyer  */
    869  1.5.2.2  bouyer int
    870  1.5.2.2  bouyer zs_ioasic_cngetc(dev)
    871  1.5.2.2  bouyer 	dev_t dev;
    872  1.5.2.2  bouyer {
    873  1.5.2.2  bouyer 
    874  1.5.2.2  bouyer 	return (zs_getc(&zs_ioasic_conschanstate_store));
    875  1.5.2.2  bouyer }
    876  1.5.2.2  bouyer 
    877  1.5.2.2  bouyer /*
    878  1.5.2.2  bouyer  * Polled console output putchar.
    879  1.5.2.2  bouyer  */
    880  1.5.2.2  bouyer void
    881  1.5.2.2  bouyer zs_ioasic_cnputc(dev, c)
    882  1.5.2.2  bouyer 	dev_t dev;
    883  1.5.2.2  bouyer 	int c;
    884  1.5.2.2  bouyer {
    885  1.5.2.2  bouyer 
    886  1.5.2.2  bouyer 	zs_putc(&zs_ioasic_conschanstate_store, c);
    887  1.5.2.2  bouyer }
    888  1.5.2.2  bouyer 
    889  1.5.2.2  bouyer /*
    890  1.5.2.2  bouyer  * Set polling/no polling on console.
    891  1.5.2.2  bouyer  */
    892  1.5.2.2  bouyer void
    893  1.5.2.2  bouyer zs_ioasic_cnpollc(dev, onoff)
    894  1.5.2.2  bouyer 	dev_t dev;
    895  1.5.2.2  bouyer 	int onoff;
    896  1.5.2.2  bouyer {
    897  1.5.2.2  bouyer 
    898  1.5.2.2  bouyer 	/* XXX ??? */
    899  1.5.2.2  bouyer }
    900