Home | History | Annotate | Line # | Download | only in dev
zs.c revision 1.34.8.3
      1  1.34.8.3  nathanw /*	$NetBSD: zs.c,v 1.34.8.3 2002/09/17 21:15:26 nathanw Exp $	*/
      2  1.34.8.2  nathanw 
      3  1.34.8.2  nathanw /*
      4  1.34.8.2  nathanw  * Copyright (c) 1996-1998 Bill Studenmund
      5  1.34.8.2  nathanw  * Copyright (c) 1995 Gordon W. Ross
      6  1.34.8.2  nathanw  * All rights reserved.
      7  1.34.8.2  nathanw  *
      8  1.34.8.2  nathanw  * Redistribution and use in source and binary forms, with or without
      9  1.34.8.2  nathanw  * modification, are permitted provided that the following conditions
     10  1.34.8.2  nathanw  * are met:
     11  1.34.8.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     12  1.34.8.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     13  1.34.8.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.34.8.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     15  1.34.8.2  nathanw  *    documentation and/or other materials provided with the distribution.
     16  1.34.8.2  nathanw  * 3. The name of the author may not be used to endorse or promote products
     17  1.34.8.2  nathanw  *    derived from this software without specific prior written permission.
     18  1.34.8.2  nathanw  * 4. All advertising materials mentioning features or use of this software
     19  1.34.8.2  nathanw  *    must display the following acknowledgement:
     20  1.34.8.2  nathanw  *      This product includes software developed by Gordon Ross
     21  1.34.8.2  nathanw  *
     22  1.34.8.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  1.34.8.2  nathanw  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  1.34.8.2  nathanw  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  1.34.8.2  nathanw  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  1.34.8.2  nathanw  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  1.34.8.2  nathanw  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  1.34.8.2  nathanw  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  1.34.8.2  nathanw  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  1.34.8.2  nathanw  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  1.34.8.2  nathanw  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  1.34.8.2  nathanw  */
     33  1.34.8.2  nathanw 
     34  1.34.8.2  nathanw /*
     35  1.34.8.2  nathanw  * Zilog Z8530 Dual UART driver (machine-dependent part)
     36  1.34.8.2  nathanw  *
     37  1.34.8.2  nathanw  * Runs two serial lines per chip using slave drivers.
     38  1.34.8.2  nathanw  * Plain tty/async lines use the zs_async slave.
     39  1.34.8.2  nathanw  * Sun keyboard/mouse uses the zs_kbd/zs_ms slaves.
     40  1.34.8.2  nathanw  * Other ports use their own mice & keyboard slaves.
     41  1.34.8.2  nathanw  *
     42  1.34.8.2  nathanw  * Credits & history:
     43  1.34.8.2  nathanw  *
     44  1.34.8.2  nathanw  * With NetBSD 1.1, port-mac68k started using a port of the port-sparc
     45  1.34.8.2  nathanw  * (port-sun3?) zs.c driver (which was in turn based on code in the
     46  1.34.8.2  nathanw  * Berkeley 4.4 Lite release). Bill Studenmund did the port, with
     47  1.34.8.2  nathanw  * help from Allen Briggs and Gordon Ross <gwr (at) netbsd.org>. Noud de
     48  1.34.8.2  nathanw  * Brouwer field-tested the driver at a local ISP.
     49  1.34.8.2  nathanw  *
     50  1.34.8.2  nathanw  * Bill Studenmund and Gordon Ross then ported the machine-independant
     51  1.34.8.2  nathanw  * z8530 driver to work with port-mac68k. NetBSD 1.2 contained an
     52  1.34.8.2  nathanw  * intermediate version (mac68k using a local, patched version of
     53  1.34.8.2  nathanw  * the m.i. drivers), with NetBSD 1.3 containing a full version.
     54  1.34.8.2  nathanw  */
     55  1.34.8.2  nathanw 
     56  1.34.8.2  nathanw #include "opt_ddb.h"
     57  1.34.8.2  nathanw #include "opt_mac68k.h"
     58  1.34.8.2  nathanw 
     59  1.34.8.2  nathanw #include <sys/param.h>
     60  1.34.8.2  nathanw #include <sys/systm.h>
     61  1.34.8.2  nathanw #include <sys/proc.h>
     62  1.34.8.2  nathanw #include <sys/device.h>
     63  1.34.8.2  nathanw #include <sys/conf.h>
     64  1.34.8.2  nathanw #include <sys/file.h>
     65  1.34.8.2  nathanw #include <sys/ioctl.h>
     66  1.34.8.2  nathanw #include <sys/tty.h>
     67  1.34.8.2  nathanw #include <sys/time.h>
     68  1.34.8.2  nathanw #include <sys/kernel.h>
     69  1.34.8.2  nathanw #include <sys/syslog.h>
     70  1.34.8.2  nathanw 
     71  1.34.8.2  nathanw #include <machine/autoconf.h>
     72  1.34.8.2  nathanw #include <machine/cpu.h>
     73  1.34.8.2  nathanw #include <machine/psc.h>
     74  1.34.8.2  nathanw #include <machine/viareg.h>
     75  1.34.8.2  nathanw 
     76  1.34.8.2  nathanw #include <dev/cons.h>
     77  1.34.8.2  nathanw #include <dev/ic/z8530reg.h>
     78  1.34.8.2  nathanw #include <machine/z8530var.h>
     79  1.34.8.2  nathanw #include <mac68k/dev/zs_cons.h>
     80  1.34.8.2  nathanw 
     81  1.34.8.2  nathanw /* Are these in a header file anywhere? */
     82  1.34.8.2  nathanw /* Booter flags interface */
     83  1.34.8.2  nathanw #define ZSMAC_RAW	0x01
     84  1.34.8.2  nathanw #define ZSMAC_LOCALTALK	0x02
     85  1.34.8.2  nathanw 
     86  1.34.8.2  nathanw #define	PCLK	(9600 * 384)
     87  1.34.8.2  nathanw 
     88  1.34.8.2  nathanw #include "zsc.h"	/* get the # of zs chips defined */
     89  1.34.8.2  nathanw 
     90  1.34.8.2  nathanw /*
     91  1.34.8.2  nathanw  * Some warts needed by z8530tty.c -
     92  1.34.8.2  nathanw  */
     93  1.34.8.2  nathanw int zs_def_cflag = (CREAD | CS8 | HUPCL);
     94  1.34.8.2  nathanw 
     95  1.34.8.2  nathanw /*
     96  1.34.8.2  nathanw  * abort detection on console will now timeout after iterating on a loop
     97  1.34.8.2  nathanw  * the following # of times. Cheep hack. Also, abort detection is turned
     98  1.34.8.2  nathanw  * off after a timeout (i.e. maybe there's not a terminal hooked up).
     99  1.34.8.2  nathanw  */
    100  1.34.8.2  nathanw #define ZSABORT_DELAY 3000000
    101  1.34.8.2  nathanw 
    102  1.34.8.2  nathanw /*
    103  1.34.8.2  nathanw  * Define interrupt levels.
    104  1.34.8.2  nathanw  */
    105  1.34.8.2  nathanw #define ZSHARD_PRI	4	/* Wired on the CPU board... */
    106  1.34.8.2  nathanw /*
    107  1.34.8.2  nathanw  * Serial port cards with zs chips on them are actually at the
    108  1.34.8.2  nathanw  * NuBus interrupt level, which is lower than 4. But blocking
    109  1.34.8.2  nathanw  * level 4 interrupts will block those interrupts too, so level
    110  1.34.8.2  nathanw  * 4 is fine.
    111  1.34.8.2  nathanw  */
    112  1.34.8.2  nathanw 
    113  1.34.8.2  nathanw /* The layout of this is hardware-dependent (padding, order). */
    114  1.34.8.2  nathanw struct zschan {
    115  1.34.8.2  nathanw 	volatile u_char	zc_csr;		/* ctrl,status, and indirect access */
    116  1.34.8.2  nathanw 	u_char		zc_xxx0;
    117  1.34.8.2  nathanw 	u_char		zc_xxx1;	/* part of the other channel lives here! */
    118  1.34.8.2  nathanw 	u_char		zc_xxx2;	/* Yea Apple! */
    119  1.34.8.2  nathanw 	volatile u_char	zc_data;	/* data */
    120  1.34.8.2  nathanw 	u_char		zc_xxx3;
    121  1.34.8.2  nathanw 	u_char		zc_xxx4;
    122  1.34.8.2  nathanw 	u_char		zc_xxx5;
    123  1.34.8.2  nathanw };
    124  1.34.8.2  nathanw 
    125  1.34.8.2  nathanw /* Saved PROM mappings */
    126  1.34.8.2  nathanw static char *zsaddr[NZSC];	/* See zs_init() */
    127  1.34.8.2  nathanw /* Flags from cninit() */
    128  1.34.8.2  nathanw static int zs_hwflags[NZSC][2];
    129  1.34.8.2  nathanw /* Default speed for each channel */
    130  1.34.8.2  nathanw static int zs_defspeed[NZSC][2] = {
    131  1.34.8.2  nathanw 	{ 9600, 	/* tty00 */
    132  1.34.8.2  nathanw 	  9600 },	/* tty01 */
    133  1.34.8.2  nathanw };
    134  1.34.8.2  nathanw /* console stuff */
    135  1.34.8.2  nathanw void	*zs_conschan = 0;
    136  1.34.8.2  nathanw int	zs_consunit;
    137  1.34.8.2  nathanw #ifdef	ZS_CONSOLE_ABORT
    138  1.34.8.2  nathanw int	zs_cons_canabort = 1;
    139  1.34.8.2  nathanw #else
    140  1.34.8.2  nathanw int	zs_cons_canabort = 0;
    141  1.34.8.2  nathanw #endif /* ZS_CONSOLE_ABORT*/
    142  1.34.8.2  nathanw /* device to which the console is attached--if serial. */
    143  1.34.8.2  nathanw dev_t	mac68k_zsdev;
    144  1.34.8.2  nathanw /* Mac stuff */
    145  1.34.8.2  nathanw volatile unsigned char *sccA = 0;
    146  1.34.8.2  nathanw 
    147  1.34.8.2  nathanw int	zs_cn_check_speed __P((int bps));
    148  1.34.8.2  nathanw 
    149  1.34.8.2  nathanw /*
    150  1.34.8.2  nathanw  * Even though zsparam will set up the clock multiples, etc., we
    151  1.34.8.2  nathanw  * still set them here as: 1) mice & keyboards don't use zsparam,
    152  1.34.8.2  nathanw  * and 2) the console stuff uses these defaults before device
    153  1.34.8.2  nathanw  * attach.
    154  1.34.8.2  nathanw  */
    155  1.34.8.2  nathanw 
    156  1.34.8.2  nathanw static u_char zs_init_reg[16] = {
    157  1.34.8.2  nathanw 	0,	/* 0: CMD (reset, etc.) */
    158  1.34.8.2  nathanw 	0,	/* 1: No interrupts yet. */
    159  1.34.8.2  nathanw 	0x18 + ZSHARD_PRI,	/* IVECT */
    160  1.34.8.2  nathanw 	ZSWR3_RX_8 | ZSWR3_RX_ENABLE,
    161  1.34.8.2  nathanw 	ZSWR4_CLK_X16 | ZSWR4_ONESB | ZSWR4_EVENP,
    162  1.34.8.2  nathanw 	ZSWR5_TX_8 | ZSWR5_TX_ENABLE,
    163  1.34.8.2  nathanw 	0,	/* 6: TXSYNC/SYNCLO */
    164  1.34.8.2  nathanw 	0,	/* 7: RXSYNC/SYNCHI */
    165  1.34.8.2  nathanw 	0,	/* 8: alias for data port */
    166  1.34.8.2  nathanw 	ZSWR9_MASTER_IE,
    167  1.34.8.2  nathanw 	0,	/*10: Misc. TX/RX control bits */
    168  1.34.8.2  nathanw 	ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD,
    169  1.34.8.2  nathanw 	((PCLK/32)/9600)-2,	/*12: BAUDLO (default=9600) */
    170  1.34.8.2  nathanw 	0,			/*13: BAUDHI (default=9600) */
    171  1.34.8.2  nathanw 	ZSWR14_BAUD_ENA,
    172  1.34.8.2  nathanw 	ZSWR15_BREAK_IE,
    173  1.34.8.2  nathanw };
    174  1.34.8.2  nathanw 
    175  1.34.8.2  nathanw struct zschan *
    176  1.34.8.2  nathanw zs_get_chan_addr(zsc_unit, channel)
    177  1.34.8.2  nathanw 	int zsc_unit, channel;
    178  1.34.8.2  nathanw {
    179  1.34.8.2  nathanw 	char *addr;
    180  1.34.8.2  nathanw 	struct zschan *zc;
    181  1.34.8.2  nathanw 
    182  1.34.8.2  nathanw 	if (zsc_unit >= NZSC)
    183  1.34.8.2  nathanw 		return NULL;
    184  1.34.8.2  nathanw 	addr = zsaddr[zsc_unit];
    185  1.34.8.2  nathanw 	if (addr == NULL)
    186  1.34.8.2  nathanw 		return NULL;
    187  1.34.8.2  nathanw 	if (channel == 0) {
    188  1.34.8.2  nathanw 		zc = (struct zschan *)(addr + 2);
    189  1.34.8.2  nathanw 		/* handle the fact the ports are intertwined. */
    190  1.34.8.2  nathanw 	} else {
    191  1.34.8.2  nathanw 		zc = (struct zschan *)(addr);
    192  1.34.8.2  nathanw 	}
    193  1.34.8.2  nathanw 	return (zc);
    194  1.34.8.2  nathanw }
    195  1.34.8.2  nathanw 
    196  1.34.8.2  nathanw 
    197  1.34.8.2  nathanw /* Find PROM mappings (for console support). */
    198  1.34.8.2  nathanw int zsinited = 0; /* 0 = not, 1 = inited, not attached, 2= attached */
    199  1.34.8.2  nathanw 
    200  1.34.8.2  nathanw void
    201  1.34.8.2  nathanw zs_init()
    202  1.34.8.2  nathanw {
    203  1.34.8.2  nathanw 	if ((zsinited == 2)&&(zsaddr[0] != (char *) sccA))
    204  1.34.8.2  nathanw 		panic("Moved zs0 address after attached!");
    205  1.34.8.2  nathanw 	zsaddr[0] = (char *) sccA;
    206  1.34.8.2  nathanw 	zsinited = 1;
    207  1.34.8.2  nathanw 	if (zs_conschan != 0){ /* we might have moved io under the console */
    208  1.34.8.2  nathanw 		zs_conschan = zs_get_chan_addr(0, zs_consunit);
    209  1.34.8.2  nathanw 		/* so recalc the console port */
    210  1.34.8.2  nathanw 	}
    211  1.34.8.2  nathanw }
    212  1.34.8.2  nathanw 
    213  1.34.8.2  nathanw 
    214  1.34.8.2  nathanw /****************************************************************
    215  1.34.8.2  nathanw  * Autoconfig
    216  1.34.8.2  nathanw  ****************************************************************/
    217  1.34.8.2  nathanw 
    218  1.34.8.2  nathanw /* Definition of the driver for autoconfig. */
    219  1.34.8.2  nathanw static int	zsc_match __P((struct device *, struct cfdata *, void *));
    220  1.34.8.2  nathanw static void	zsc_attach __P((struct device *, struct device *, void *));
    221  1.34.8.2  nathanw static int  zsc_print __P((void *, const char *name));
    222  1.34.8.2  nathanw 
    223  1.34.8.2  nathanw struct cfattach zsc_ca = {
    224  1.34.8.2  nathanw 	sizeof(struct zsc_softc), zsc_match, zsc_attach
    225  1.34.8.2  nathanw };
    226  1.34.8.2  nathanw 
    227  1.34.8.2  nathanw extern struct cfdriver zsc_cd;
    228  1.34.8.2  nathanw 
    229  1.34.8.2  nathanw int zshard __P((void *));
    230  1.34.8.2  nathanw int zssoft __P((void *));
    231  1.34.8.2  nathanw 
    232  1.34.8.2  nathanw 
    233  1.34.8.2  nathanw /*
    234  1.34.8.2  nathanw  * Is the zs chip present?
    235  1.34.8.2  nathanw  */
    236  1.34.8.2  nathanw static int
    237  1.34.8.2  nathanw zsc_match(parent, cf, aux)
    238  1.34.8.2  nathanw 	struct device *parent;
    239  1.34.8.2  nathanw 	struct cfdata *cf;
    240  1.34.8.2  nathanw 	void *aux;
    241  1.34.8.2  nathanw {
    242  1.34.8.2  nathanw 	return 1;
    243  1.34.8.2  nathanw }
    244  1.34.8.2  nathanw 
    245  1.34.8.2  nathanw /*
    246  1.34.8.2  nathanw  * Attach a found zs.
    247  1.34.8.2  nathanw  *
    248  1.34.8.2  nathanw  * Match slave number to zs unit number, so that misconfiguration will
    249  1.34.8.2  nathanw  * not set up the keyboard as ttya, etc.
    250  1.34.8.2  nathanw  */
    251  1.34.8.2  nathanw static void
    252  1.34.8.2  nathanw zsc_attach(parent, self, aux)
    253  1.34.8.2  nathanw 	struct device *parent;
    254  1.34.8.2  nathanw 	struct device *self;
    255  1.34.8.2  nathanw 	void *aux;
    256  1.34.8.2  nathanw {
    257  1.34.8.2  nathanw 	struct zsc_softc *zsc = (void *) self;
    258  1.34.8.2  nathanw 	struct zsc_attach_args zsc_args;
    259  1.34.8.2  nathanw 	volatile struct zschan *zc;
    260  1.34.8.2  nathanw 	struct xzs_chanstate *xcs;
    261  1.34.8.2  nathanw 	struct zs_chanstate *cs;
    262  1.34.8.2  nathanw 	int zsc_unit, channel;
    263  1.34.8.2  nathanw 	int s, chip, theflags;
    264  1.34.8.2  nathanw 
    265  1.34.8.2  nathanw 	if (!zsinited)
    266  1.34.8.2  nathanw 		zs_init();
    267  1.34.8.2  nathanw 	zsinited = 2;
    268  1.34.8.2  nathanw 
    269  1.34.8.2  nathanw 	zsc_unit = zsc->zsc_dev.dv_unit;
    270  1.34.8.2  nathanw 
    271  1.34.8.2  nathanw 	/* Make sure everything's inited ok. */
    272  1.34.8.2  nathanw 	if (zsaddr[zsc_unit] == NULL)
    273  1.34.8.2  nathanw 		panic("zs_attach: zs%d not mapped\n", zsc_unit);
    274  1.34.8.2  nathanw 
    275  1.34.8.2  nathanw 	chip = 0; /* We'll deal with chip types post 1.2 */
    276  1.34.8.2  nathanw 	printf(" chip type %d \n",chip);
    277  1.34.8.2  nathanw 
    278  1.34.8.2  nathanw 	/*
    279  1.34.8.2  nathanw 	 * Initialize software state for each channel.
    280  1.34.8.2  nathanw 	 */
    281  1.34.8.2  nathanw 	for (channel = 0; channel < 2; channel++) {
    282  1.34.8.2  nathanw 		zsc_args.channel = channel;
    283  1.34.8.2  nathanw 		zsc_args.hwflags = zs_hwflags[zsc_unit][channel];
    284  1.34.8.2  nathanw 		xcs = &zsc->xzsc_xcs_store[channel];
    285  1.34.8.2  nathanw 		cs  = &xcs->xzs_cs;
    286  1.34.8.2  nathanw 		zsc->zsc_cs[channel] = cs;
    287  1.34.8.2  nathanw 
    288  1.34.8.2  nathanw 		cs->cs_channel = channel;
    289  1.34.8.2  nathanw 		cs->cs_private = NULL;
    290  1.34.8.2  nathanw 		cs->cs_ops = &zsops_null;
    291  1.34.8.2  nathanw 
    292  1.34.8.2  nathanw 		zc = zs_get_chan_addr(zsc_unit, channel);
    293  1.34.8.2  nathanw 		cs->cs_reg_csr  = &zc->zc_csr;
    294  1.34.8.2  nathanw 		cs->cs_reg_data = &zc->zc_data;
    295  1.34.8.2  nathanw 
    296  1.34.8.2  nathanw 		bcopy(zs_init_reg, cs->cs_creg, 16);
    297  1.34.8.2  nathanw 		bcopy(zs_init_reg, cs->cs_preg, 16);
    298  1.34.8.2  nathanw 
    299  1.34.8.2  nathanw 		/* Current BAUD rate generator clock. */
    300  1.34.8.2  nathanw 		cs->cs_brg_clk = PCLK / 16;	/* RTxC is 230400*16, so use 230400 */
    301  1.34.8.2  nathanw 		cs->cs_defspeed = zs_defspeed[zsc_unit][channel];
    302  1.34.8.2  nathanw 		cs->cs_defcflag = zs_def_cflag;
    303  1.34.8.2  nathanw 
    304  1.34.8.2  nathanw 		/* Make these correspond to cs_defcflag (-crtscts) */
    305  1.34.8.2  nathanw 		cs->cs_rr0_dcd = ZSRR0_DCD;
    306  1.34.8.2  nathanw 		cs->cs_rr0_cts = 0;
    307  1.34.8.2  nathanw 		cs->cs_wr5_dtr = ZSWR5_DTR;
    308  1.34.8.2  nathanw 		cs->cs_wr5_rts = 0;
    309  1.34.8.2  nathanw 
    310  1.34.8.2  nathanw #ifdef __notyet__
    311  1.34.8.2  nathanw 		cs->cs_slave_type = ZS_SLAVE_NONE;
    312  1.34.8.2  nathanw #endif
    313  1.34.8.2  nathanw 
    314  1.34.8.2  nathanw 		/* Define BAUD rate stuff. */
    315  1.34.8.2  nathanw 		xcs->cs_clocks[0].clk = PCLK;
    316  1.34.8.2  nathanw 		xcs->cs_clocks[0].flags = ZSC_RTXBRG | ZSC_RTXDIV;
    317  1.34.8.2  nathanw 		xcs->cs_clocks[1].flags =
    318  1.34.8.2  nathanw 			ZSC_RTXBRG | ZSC_RTXDIV | ZSC_VARIABLE | ZSC_EXTERN;
    319  1.34.8.2  nathanw 		xcs->cs_clocks[2].flags = ZSC_TRXDIV | ZSC_VARIABLE;
    320  1.34.8.2  nathanw 		xcs->cs_clock_count = 3;
    321  1.34.8.2  nathanw 		if (channel == 0) {
    322  1.34.8.2  nathanw 			theflags = mac68k_machine.modem_flags;
    323  1.34.8.2  nathanw 			xcs->cs_clocks[1].clk = mac68k_machine.modem_dcd_clk;
    324  1.34.8.2  nathanw 			xcs->cs_clocks[2].clk = mac68k_machine.modem_cts_clk;
    325  1.34.8.2  nathanw 		} else {
    326  1.34.8.2  nathanw 			theflags = mac68k_machine.print_flags;
    327  1.34.8.2  nathanw 			xcs->cs_clocks[1].flags = ZSC_VARIABLE;
    328  1.34.8.2  nathanw 			/*
    329  1.34.8.2  nathanw 			 * Yes, we aren't defining ANY clock source enables for the
    330  1.34.8.2  nathanw 			 * printer's DCD clock in. The hardware won't let us
    331  1.34.8.2  nathanw 			 * use it. But a clock will freak out the chip, so we
    332  1.34.8.2  nathanw 			 * let you set it, telling us to bar interrupts on the line.
    333  1.34.8.2  nathanw 			 */
    334  1.34.8.2  nathanw 			xcs->cs_clocks[1].clk = mac68k_machine.print_dcd_clk;
    335  1.34.8.2  nathanw 			xcs->cs_clocks[2].clk = mac68k_machine.print_cts_clk;
    336  1.34.8.2  nathanw 		}
    337  1.34.8.2  nathanw 		if (xcs->cs_clocks[1].clk)
    338  1.34.8.2  nathanw 			zsc_args.hwflags |= ZS_HWFLAG_NO_DCD;
    339  1.34.8.2  nathanw 		if (xcs->cs_clocks[2].clk)
    340  1.34.8.2  nathanw 			zsc_args.hwflags |= ZS_HWFLAG_NO_CTS;
    341  1.34.8.2  nathanw 
    342  1.34.8.2  nathanw 		printf("zsc%d channel %d: d_speed %6d DCD clk %ld CTS clk %ld",
    343  1.34.8.2  nathanw 				zsc_unit, channel, cs->cs_defspeed,
    344  1.34.8.2  nathanw 				xcs->cs_clocks[1].clk, xcs->cs_clocks[2].clk);
    345  1.34.8.2  nathanw 
    346  1.34.8.2  nathanw 		/* Set defaults in our "extended" chanstate. */
    347  1.34.8.2  nathanw 		xcs->cs_csource = 0;
    348  1.34.8.2  nathanw 		xcs->cs_psource = 0;
    349  1.34.8.2  nathanw 		xcs->cs_cclk_flag = 0;  /* Nothing fancy by default */
    350  1.34.8.2  nathanw 		xcs->cs_pclk_flag = 0;
    351  1.34.8.2  nathanw 
    352  1.34.8.2  nathanw 		if (theflags & ZSMAC_RAW) {
    353  1.34.8.2  nathanw 			zsc_args.hwflags |= ZS_HWFLAG_RAW;
    354  1.34.8.2  nathanw 			printf(" (raw defaults)");
    355  1.34.8.2  nathanw 		}
    356  1.34.8.2  nathanw 
    357  1.34.8.2  nathanw 		/*
    358  1.34.8.2  nathanw 		 * XXX - This might be better done with a "stub" driver
    359  1.34.8.2  nathanw 		 * (to replace zstty) that ignores LocalTalk for now.
    360  1.34.8.2  nathanw 		 */
    361  1.34.8.2  nathanw 		if (theflags & ZSMAC_LOCALTALK) {
    362  1.34.8.2  nathanw 			printf(" shielding from LocalTalk");
    363  1.34.8.2  nathanw 			cs->cs_defspeed = 1;
    364  1.34.8.2  nathanw 			cs->cs_creg[ZSRR_BAUDLO] = cs->cs_preg[ZSRR_BAUDLO] = 0xff;
    365  1.34.8.2  nathanw 			cs->cs_creg[ZSRR_BAUDHI] = cs->cs_preg[ZSRR_BAUDHI] = 0xff;
    366  1.34.8.2  nathanw 			zs_write_reg(cs, ZSRR_BAUDLO, 0xff);
    367  1.34.8.2  nathanw 			zs_write_reg(cs, ZSRR_BAUDHI, 0xff);
    368  1.34.8.2  nathanw 			/*
    369  1.34.8.2  nathanw 			 * If we might have LocalTalk, then make sure we have the
    370  1.34.8.2  nathanw 			 * Baud rate low-enough to not do any damage.
    371  1.34.8.2  nathanw 			 */
    372  1.34.8.2  nathanw 		}
    373  1.34.8.2  nathanw 
    374  1.34.8.2  nathanw 		/*
    375  1.34.8.2  nathanw 		 * We used to disable chip interrupts here, but we now
    376  1.34.8.2  nathanw 		 * do that in zscnprobe, just in case MacOS left the chip on.
    377  1.34.8.2  nathanw 		 */
    378  1.34.8.2  nathanw 
    379  1.34.8.2  nathanw 		xcs->cs_chip = chip;
    380  1.34.8.2  nathanw 
    381  1.34.8.2  nathanw 		/* Stash away a copy of the final H/W flags. */
    382  1.34.8.2  nathanw 		xcs->cs_hwflags = zsc_args.hwflags;
    383  1.34.8.2  nathanw 
    384  1.34.8.2  nathanw 		printf("\n");
    385  1.34.8.2  nathanw 
    386  1.34.8.2  nathanw 		/*
    387  1.34.8.2  nathanw 		 * Look for a child driver for this channel.
    388  1.34.8.2  nathanw 		 * The child attach will setup the hardware.
    389  1.34.8.2  nathanw 		 */
    390  1.34.8.2  nathanw 		if (!config_found(self, (void *)&zsc_args, zsc_print)) {
    391  1.34.8.2  nathanw 			/* No sub-driver.  Just reset it. */
    392  1.34.8.2  nathanw 			u_char reset = (channel == 0) ?
    393  1.34.8.2  nathanw 				ZSWR9_A_RESET : ZSWR9_B_RESET;
    394  1.34.8.2  nathanw 			s = splzs();
    395  1.34.8.2  nathanw 			zs_write_reg(cs,  9, reset);
    396  1.34.8.2  nathanw 			splx(s);
    397  1.34.8.2  nathanw 		}
    398  1.34.8.2  nathanw 	}
    399  1.34.8.2  nathanw 
    400  1.34.8.2  nathanw 	if (current_mac_model->class == MACH_CLASSAV) {
    401  1.34.8.2  nathanw 		add_psc_lev4_intr(PSCINTR_SCCA, zshard, zsc);
    402  1.34.8.2  nathanw 		add_psc_lev4_intr(PSCINTR_SCCB, zshard, zsc);
    403  1.34.8.2  nathanw 	} else {
    404  1.34.8.2  nathanw 		intr_establish(zshard, zsc, ZSHARD_PRI);
    405  1.34.8.2  nathanw 	}
    406  1.34.8.2  nathanw 
    407  1.34.8.2  nathanw 	/* Now safe to enable interrupts. */
    408  1.34.8.2  nathanw 
    409  1.34.8.2  nathanw 	/*
    410  1.34.8.2  nathanw 	 * Set the master interrupt enable and interrupt vector.
    411  1.34.8.2  nathanw 	 * (common to both channels, do it on A)
    412  1.34.8.2  nathanw 	 */
    413  1.34.8.2  nathanw 	cs = zsc->zsc_cs[0];
    414  1.34.8.2  nathanw 	s = splzs();
    415  1.34.8.2  nathanw 	/* interrupt vector */
    416  1.34.8.2  nathanw 	zs_write_reg(cs, 2, zs_init_reg[2]);
    417  1.34.8.2  nathanw 	/* master interrupt control (enable) */
    418  1.34.8.2  nathanw 	zs_write_reg(cs, 9, zs_init_reg[9]);
    419  1.34.8.2  nathanw 	splx(s);
    420  1.34.8.2  nathanw }
    421  1.34.8.2  nathanw 
    422  1.34.8.2  nathanw static int
    423  1.34.8.2  nathanw zsc_print(aux, name)
    424  1.34.8.2  nathanw 	void *aux;
    425  1.34.8.2  nathanw 	const char *name;
    426  1.34.8.2  nathanw {
    427  1.34.8.2  nathanw 	struct zsc_attach_args *args = aux;
    428  1.34.8.2  nathanw 
    429  1.34.8.2  nathanw 	if (name != NULL)
    430  1.34.8.2  nathanw 		printf("%s: ", name);
    431  1.34.8.2  nathanw 
    432  1.34.8.2  nathanw 	if (args->channel != -1)
    433  1.34.8.2  nathanw 		printf(" channel %d", args->channel);
    434  1.34.8.2  nathanw 
    435  1.34.8.2  nathanw 	return UNCONF;
    436  1.34.8.2  nathanw }
    437  1.34.8.2  nathanw 
    438  1.34.8.2  nathanw int
    439  1.34.8.2  nathanw zsmdioctl(cs, cmd, data)
    440  1.34.8.2  nathanw 	struct zs_chanstate *cs;
    441  1.34.8.2  nathanw 	u_long cmd;
    442  1.34.8.2  nathanw 	caddr_t data;
    443  1.34.8.2  nathanw {
    444  1.34.8.2  nathanw 	switch (cmd) {
    445  1.34.8.2  nathanw 	default:
    446  1.34.8.2  nathanw 		return (EPASSTHROUGH);
    447  1.34.8.2  nathanw 	}
    448  1.34.8.2  nathanw 	return (0);
    449  1.34.8.2  nathanw }
    450  1.34.8.2  nathanw 
    451  1.34.8.2  nathanw void
    452  1.34.8.2  nathanw zsmd_setclock(cs)
    453  1.34.8.2  nathanw 	struct zs_chanstate *cs;
    454  1.34.8.2  nathanw {
    455  1.34.8.2  nathanw 	struct xzs_chanstate *xcs = (void *)cs;
    456  1.34.8.2  nathanw 
    457  1.34.8.2  nathanw 	if (cs->cs_channel != 0)
    458  1.34.8.2  nathanw 		return;
    459  1.34.8.2  nathanw 
    460  1.34.8.2  nathanw 	/*
    461  1.34.8.2  nathanw 	 * If the new clock has the external bit set, then select the
    462  1.34.8.2  nathanw 	 * external source.
    463  1.34.8.2  nathanw 	 */
    464  1.34.8.2  nathanw 	via_set_modem((xcs->cs_pclk_flag & ZSC_EXTERN) ? 1 : 0);
    465  1.34.8.2  nathanw }
    466  1.34.8.2  nathanw 
    467  1.34.8.2  nathanw static int zssoftpending;
    468  1.34.8.2  nathanw 
    469  1.34.8.2  nathanw /*
    470  1.34.8.2  nathanw  * Do the minimum work to pull data off of the chip and queue it up
    471  1.34.8.2  nathanw  * for later processing.
    472  1.34.8.2  nathanw  */
    473  1.34.8.2  nathanw int
    474  1.34.8.2  nathanw zshard(arg)
    475  1.34.8.2  nathanw 	void *arg;
    476  1.34.8.2  nathanw {
    477  1.34.8.2  nathanw 	struct zsc_softc *zsc = (struct zsc_softc *)arg;
    478  1.34.8.2  nathanw 	int rval;
    479  1.34.8.2  nathanw 
    480  1.34.8.2  nathanw 	if (zsc == NULL)
    481  1.34.8.2  nathanw 		return 0;
    482  1.34.8.2  nathanw 
    483  1.34.8.2  nathanw 	rval = zsc_intr_hard(zsc);
    484  1.34.8.2  nathanw 	if ((zsc->zsc_cs[0]->cs_softreq) || (zsc->zsc_cs[1]->cs_softreq)) {
    485  1.34.8.2  nathanw 		/* zsc_req_softint(zsc); */
    486  1.34.8.2  nathanw 		/* We are at splzs here, so no need to lock. */
    487  1.34.8.2  nathanw 		if (zssoftpending == 0) {
    488  1.34.8.2  nathanw 			zssoftpending = 1;
    489  1.34.8.2  nathanw 			setsoftserial();
    490  1.34.8.2  nathanw 		}
    491  1.34.8.2  nathanw 	}
    492  1.34.8.2  nathanw 	return (rval);
    493  1.34.8.2  nathanw }
    494  1.34.8.2  nathanw 
    495  1.34.8.2  nathanw /*
    496  1.34.8.2  nathanw  * Look at all of the zsc softint queues.
    497  1.34.8.2  nathanw  */
    498  1.34.8.2  nathanw int
    499  1.34.8.2  nathanw zssoft(arg)
    500  1.34.8.2  nathanw 	void *arg;
    501  1.34.8.2  nathanw {
    502  1.34.8.2  nathanw 	struct zsc_softc *zsc;
    503  1.34.8.2  nathanw 	int unit;
    504  1.34.8.2  nathanw 
    505  1.34.8.2  nathanw 	/* This is not the only ISR on this IPL. */
    506  1.34.8.2  nathanw 	if (zssoftpending == 0)
    507  1.34.8.2  nathanw 		return (0);
    508  1.34.8.2  nathanw 
    509  1.34.8.2  nathanw 	/*
    510  1.34.8.2  nathanw 	 * The soft intr. bit will be set by zshard only if
    511  1.34.8.2  nathanw 	 * the variable zssoftpending is zero.
    512  1.34.8.2  nathanw 	 */
    513  1.34.8.2  nathanw 	zssoftpending = 0;
    514  1.34.8.2  nathanw 
    515  1.34.8.2  nathanw 	for (unit = 0; unit < zsc_cd.cd_ndevs; ++unit) {
    516  1.34.8.2  nathanw 		zsc = zsc_cd.cd_devs[unit];
    517  1.34.8.2  nathanw 		if (zsc == NULL)
    518  1.34.8.2  nathanw 			continue;
    519  1.34.8.2  nathanw 		(void) zsc_intr_soft(zsc);
    520  1.34.8.2  nathanw 	}
    521  1.34.8.2  nathanw 	return (1);
    522  1.34.8.2  nathanw }
    523  1.34.8.2  nathanw 
    524  1.34.8.2  nathanw 
    525  1.34.8.2  nathanw #ifndef ZS_TOLERANCE
    526  1.34.8.2  nathanw #define ZS_TOLERANCE 51
    527  1.34.8.2  nathanw /* 5% in tenths of a %, plus 1 so that exactly 5% will be ok. */
    528  1.34.8.2  nathanw #endif
    529  1.34.8.2  nathanw 
    530  1.34.8.2  nathanw /*
    531  1.34.8.2  nathanw  * check out a rate for acceptability from the internal clock
    532  1.34.8.2  nathanw  * source. Used in console config to validate a requested
    533  1.34.8.2  nathanw  * default speed. Placed here so that all the speed checking code is
    534  1.34.8.2  nathanw  * in one place.
    535  1.34.8.2  nathanw  *
    536  1.34.8.2  nathanw  * != 0 means ok.
    537  1.34.8.2  nathanw  */
    538  1.34.8.2  nathanw int
    539  1.34.8.2  nathanw zs_cn_check_speed(bps)
    540  1.34.8.2  nathanw 	int bps;	/* target rate */
    541  1.34.8.2  nathanw {
    542  1.34.8.2  nathanw 	int tc, rate;
    543  1.34.8.2  nathanw 
    544  1.34.8.2  nathanw 	tc = BPS_TO_TCONST(PCLK / 16, bps);
    545  1.34.8.2  nathanw 	if (tc < 0)
    546  1.34.8.2  nathanw 		return 0;
    547  1.34.8.2  nathanw 	rate = TCONST_TO_BPS(PCLK / 16, tc);
    548  1.34.8.2  nathanw 	if (ZS_TOLERANCE > abs(((rate - bps)*1000)/bps))
    549  1.34.8.2  nathanw 		return 1;
    550  1.34.8.2  nathanw 	else
    551  1.34.8.2  nathanw 		return 0;
    552  1.34.8.2  nathanw }
    553  1.34.8.2  nathanw 
    554  1.34.8.2  nathanw /*
    555  1.34.8.2  nathanw  * Search through the signal sources in the channel, and
    556  1.34.8.2  nathanw  * pick the best one for the baud rate requested. Return
    557  1.34.8.2  nathanw  * a -1 if not achievable in tolerance. Otherwise return 0
    558  1.34.8.2  nathanw  * and fill in the values.
    559  1.34.8.2  nathanw  *
    560  1.34.8.2  nathanw  * This routine draws inspiration from the Atari port's zs.c
    561  1.34.8.2  nathanw  * driver in NetBSD 1.1 which did the same type of source switching.
    562  1.34.8.2  nathanw  * Tolerance code inspired by comspeed routine in isa/com.c.
    563  1.34.8.2  nathanw  *
    564  1.34.8.2  nathanw  * By Bill Studenmund, 1996-05-12
    565  1.34.8.2  nathanw  */
    566  1.34.8.2  nathanw int
    567  1.34.8.2  nathanw zs_set_speed(cs, bps)
    568  1.34.8.2  nathanw 	struct zs_chanstate *cs;
    569  1.34.8.2  nathanw 	int bps;	/* bits per second */
    570  1.34.8.2  nathanw {
    571  1.34.8.2  nathanw 	struct xzs_chanstate *xcs = (void *) cs;
    572  1.34.8.2  nathanw 	int i, tc, tc0 = 0, tc1, s, sf = 0;
    573  1.34.8.2  nathanw 	int src, rate0, rate1, err, tol;
    574  1.34.8.2  nathanw 
    575  1.34.8.2  nathanw 	if (bps == 0)
    576  1.34.8.2  nathanw 		return (0);
    577  1.34.8.2  nathanw 
    578  1.34.8.2  nathanw 	src = -1;		/* no valid source yet */
    579  1.34.8.2  nathanw 	tol = ZS_TOLERANCE;
    580  1.34.8.2  nathanw 
    581  1.34.8.2  nathanw 	/*
    582  1.34.8.2  nathanw 	 * Step through all the sources and see which one matches
    583  1.34.8.2  nathanw 	 * the best. A source has to match BETTER than tol to be chosen.
    584  1.34.8.2  nathanw 	 * Thus if two sources give the same error, the first one will be
    585  1.34.8.2  nathanw 	 * chosen. Also, allow for the possability that one source might run
    586  1.34.8.2  nathanw 	 * both the BRG and the direct divider (i.e. RTxC).
    587  1.34.8.2  nathanw 	 */
    588  1.34.8.2  nathanw 	for (i=0; i < xcs->cs_clock_count; i++) {
    589  1.34.8.2  nathanw 		if (xcs->cs_clocks[i].clk <= 0)
    590  1.34.8.2  nathanw 			continue;	/* skip non-existent or bad clocks */
    591  1.34.8.2  nathanw 		if (xcs->cs_clocks[i].flags & ZSC_BRG) {
    592  1.34.8.2  nathanw 			/* check out BRG at /16 */
    593  1.34.8.2  nathanw 			tc1 = BPS_TO_TCONST(xcs->cs_clocks[i].clk >> 4, bps);
    594  1.34.8.2  nathanw 			if (tc1 >= 0) {
    595  1.34.8.2  nathanw 				rate1 = TCONST_TO_BPS(xcs->cs_clocks[i].clk >> 4, tc1);
    596  1.34.8.2  nathanw 				err = abs(((rate1 - bps)*1000)/bps);
    597  1.34.8.2  nathanw 				if (err < tol) {
    598  1.34.8.2  nathanw 					tol = err;
    599  1.34.8.2  nathanw 					src = i;
    600  1.34.8.2  nathanw 					sf = xcs->cs_clocks[i].flags & ~ZSC_DIV;
    601  1.34.8.2  nathanw 					tc0 = tc1;
    602  1.34.8.2  nathanw 					rate0 = rate1;
    603  1.34.8.2  nathanw 				}
    604  1.34.8.2  nathanw 			}
    605  1.34.8.2  nathanw 		}
    606  1.34.8.2  nathanw 		if (xcs->cs_clocks[i].flags & ZSC_DIV) {
    607  1.34.8.2  nathanw 			/*
    608  1.34.8.2  nathanw 			 * Check out either /1, /16, /32, or /64
    609  1.34.8.2  nathanw 			 * Note: for /1, you'd better be using a synchronized
    610  1.34.8.2  nathanw 			 * clock!
    611  1.34.8.2  nathanw 			 */
    612  1.34.8.2  nathanw 			int b0 = xcs->cs_clocks[i].clk, e0 = abs(b0-bps);
    613  1.34.8.2  nathanw 			int b1 = b0 >> 4, e1 = abs(b1-bps);
    614  1.34.8.2  nathanw 			int b2 = b1 >> 1, e2 = abs(b2-bps);
    615  1.34.8.2  nathanw 			int b3 = b2 >> 1, e3 = abs(b3-bps);
    616  1.34.8.2  nathanw 
    617  1.34.8.2  nathanw 			if (e0 < e1 && e0 < e2 && e0 < e3) {
    618  1.34.8.2  nathanw 				err = e0;
    619  1.34.8.2  nathanw 				rate1 = b0;
    620  1.34.8.2  nathanw 				tc1 = ZSWR4_CLK_X1;
    621  1.34.8.2  nathanw 			} else if (e0 > e1 && e1 < e2  && e1 < e3) {
    622  1.34.8.2  nathanw 				err = e1;
    623  1.34.8.2  nathanw 				rate1 = b1;
    624  1.34.8.2  nathanw 				tc1 = ZSWR4_CLK_X16;
    625  1.34.8.2  nathanw 			} else if (e0 > e2 && e1 > e2 && e2 < e3) {
    626  1.34.8.2  nathanw 				err = e2;
    627  1.34.8.2  nathanw 				rate1 = b2;
    628  1.34.8.2  nathanw 				tc1 = ZSWR4_CLK_X32;
    629  1.34.8.2  nathanw 			} else {
    630  1.34.8.2  nathanw 				err = e3;
    631  1.34.8.2  nathanw 				rate1 = b3;
    632  1.34.8.2  nathanw 				tc1 = ZSWR4_CLK_X64;
    633  1.34.8.2  nathanw 			}
    634  1.34.8.2  nathanw 
    635  1.34.8.2  nathanw 			err = (err * 1000)/bps;
    636  1.34.8.2  nathanw 			if (err < tol) {
    637  1.34.8.2  nathanw 				tol = err;
    638  1.34.8.2  nathanw 				src = i;
    639  1.34.8.2  nathanw 				sf = xcs->cs_clocks[i].flags & ~ZSC_BRG;
    640  1.34.8.2  nathanw 				tc0 = tc1;
    641  1.34.8.2  nathanw 				rate0 = rate1;
    642  1.34.8.2  nathanw 			}
    643  1.34.8.2  nathanw 		}
    644  1.34.8.2  nathanw 	}
    645  1.34.8.2  nathanw #ifdef ZSMACDEBUG
    646  1.34.8.2  nathanw 	zsprintf("Checking for rate %d. Found source #%d.\n",bps, src);
    647  1.34.8.2  nathanw #endif
    648  1.34.8.2  nathanw 	if (src == -1)
    649  1.34.8.2  nathanw 		return (EINVAL); /* no can do */
    650  1.34.8.2  nathanw 
    651  1.34.8.2  nathanw 	/*
    652  1.34.8.2  nathanw 	 * The M.I. layer likes to keep cs_brg_clk current, even though
    653  1.34.8.2  nathanw 	 * we are the only ones who should be touching the BRG's rate.
    654  1.34.8.2  nathanw 	 *
    655  1.34.8.2  nathanw 	 * Note: we are assuming that any ZSC_EXTERN signal source comes in
    656  1.34.8.2  nathanw 	 * on the RTxC pin. Correct for the mac68k obio zsc.
    657  1.34.8.2  nathanw 	 */
    658  1.34.8.2  nathanw 	if (sf & ZSC_EXTERN)
    659  1.34.8.2  nathanw 		cs->cs_brg_clk = xcs->cs_clocks[i].clk >> 4;
    660  1.34.8.2  nathanw 	else
    661  1.34.8.2  nathanw 		cs->cs_brg_clk = PCLK / 16;
    662  1.34.8.2  nathanw 
    663  1.34.8.2  nathanw 	/*
    664  1.34.8.2  nathanw 	 * Now we have a source, so set it up.
    665  1.34.8.2  nathanw 	 */
    666  1.34.8.2  nathanw 	s = splzs();
    667  1.34.8.2  nathanw 	xcs->cs_psource = src;
    668  1.34.8.2  nathanw 	xcs->cs_pclk_flag = sf;
    669  1.34.8.2  nathanw 	bps = rate0;
    670  1.34.8.2  nathanw 	if (sf & ZSC_BRG) {
    671  1.34.8.2  nathanw 		cs->cs_preg[4] = ZSWR4_CLK_X16;
    672  1.34.8.2  nathanw 		cs->cs_preg[11]= ZSWR11_RXCLK_BAUD | ZSWR11_TXCLK_BAUD;
    673  1.34.8.2  nathanw 		if (sf & ZSC_PCLK) {
    674  1.34.8.2  nathanw 			cs->cs_preg[14] = ZSWR14_BAUD_ENA | ZSWR14_BAUD_FROM_PCLK;
    675  1.34.8.2  nathanw 		} else {
    676  1.34.8.2  nathanw 			cs->cs_preg[14] = ZSWR14_BAUD_ENA;
    677  1.34.8.2  nathanw 		}
    678  1.34.8.2  nathanw 		tc = tc0;
    679  1.34.8.2  nathanw 	} else {
    680  1.34.8.2  nathanw 		cs->cs_preg[4] = tc0;
    681  1.34.8.2  nathanw 		if (sf & ZSC_RTXDIV) {
    682  1.34.8.2  nathanw 			cs->cs_preg[11] = ZSWR11_RXCLK_RTXC | ZSWR11_TXCLK_RTXC;
    683  1.34.8.2  nathanw 		} else {
    684  1.34.8.2  nathanw 			cs->cs_preg[11] = ZSWR11_RXCLK_TRXC | ZSWR11_TXCLK_TRXC;
    685  1.34.8.2  nathanw 		}
    686  1.34.8.2  nathanw 		cs->cs_preg[14]= 0;
    687  1.34.8.2  nathanw 		tc = 0xffff;
    688  1.34.8.2  nathanw 	}
    689  1.34.8.2  nathanw 	/* Set the BAUD rate divisor. */
    690  1.34.8.2  nathanw 	cs->cs_preg[12] = tc;
    691  1.34.8.2  nathanw 	cs->cs_preg[13] = tc >> 8;
    692  1.34.8.2  nathanw 	splx(s);
    693  1.34.8.2  nathanw 
    694  1.34.8.2  nathanw #ifdef ZSMACDEBUG
    695  1.34.8.2  nathanw 	zsprintf("Rate is %7d, tc is %7d, source no. %2d, flags %4x\n", \
    696  1.34.8.2  nathanw 	    bps, tc, src, sf);
    697  1.34.8.2  nathanw 	zsprintf("Registers are: 4 %x, 11 %x, 14 %x\n\n",
    698  1.34.8.2  nathanw 		cs->cs_preg[4], cs->cs_preg[11], cs->cs_preg[14]);
    699  1.34.8.2  nathanw #endif
    700  1.34.8.2  nathanw 
    701  1.34.8.2  nathanw 	cs->cs_preg[5] |= ZSWR5_RTS;	/* Make sure the drivers are on! */
    702  1.34.8.2  nathanw 
    703  1.34.8.2  nathanw 	/* Caller will stuff the pending registers. */
    704  1.34.8.2  nathanw 	return (0);
    705  1.34.8.2  nathanw }
    706  1.34.8.2  nathanw 
    707  1.34.8.2  nathanw int
    708  1.34.8.2  nathanw zs_set_modes(cs, cflag)
    709  1.34.8.2  nathanw 	struct zs_chanstate *cs;
    710  1.34.8.2  nathanw 	int cflag;	/* bits per second */
    711  1.34.8.2  nathanw {
    712  1.34.8.2  nathanw 	struct xzs_chanstate *xcs = (void*)cs;
    713  1.34.8.2  nathanw 	int s;
    714  1.34.8.2  nathanw 
    715  1.34.8.2  nathanw 	/*
    716  1.34.8.2  nathanw 	 * Make sure we don't enable hfc on a signal line we're ignoring.
    717  1.34.8.2  nathanw 	 * As we enable CTS interrupts only if we have CRTSCTS or CDTRCTS,
    718  1.34.8.2  nathanw 	 * this code also effectivly turns off ZSWR15_CTS_IE.
    719  1.34.8.2  nathanw 	 *
    720  1.34.8.2  nathanw 	 * Also, disable DCD interrupts if we've been told to ignore
    721  1.34.8.2  nathanw 	 * the DCD pin. Happens on mac68k because the input line for
    722  1.34.8.2  nathanw 	 * DCD can also be used as a clock input.  (Just set CLOCAL.)
    723  1.34.8.2  nathanw 	 *
    724  1.34.8.2  nathanw 	 * If someone tries to turn an invalid flow mode on, Just Say No
    725  1.34.8.2  nathanw 	 * (Suggested by gwr)
    726  1.34.8.2  nathanw 	 */
    727  1.34.8.2  nathanw 	if ((cflag & CDTRCTS) && (cflag & (CRTSCTS | MDMBUF)))
    728  1.34.8.2  nathanw 		return (EINVAL);
    729  1.34.8.2  nathanw 	cs->cs_rr0_pps = 0;
    730  1.34.8.2  nathanw 	if (xcs->cs_hwflags & ZS_HWFLAG_NO_DCD) {
    731  1.34.8.2  nathanw 		if (cflag & MDMBUF)
    732  1.34.8.2  nathanw 			return (EINVAL);
    733  1.34.8.2  nathanw 		cflag |= CLOCAL;
    734  1.34.8.2  nathanw 	} else {
    735  1.34.8.2  nathanw 		/*
    736  1.34.8.2  nathanw 		 * cs->cs_rr0_pps indicates which bit MAY be used for pps.
    737  1.34.8.2  nathanw 		 * Enable only if nothing else will want the interrupt and
    738  1.34.8.2  nathanw 		 * it's ok to enable interrupts on this line.
    739  1.34.8.2  nathanw 		 */
    740  1.34.8.2  nathanw 		if ((cflag & (CLOCAL | MDMBUF)) == CLOCAL)
    741  1.34.8.2  nathanw 			cs->cs_rr0_pps = ZSRR0_DCD;
    742  1.34.8.2  nathanw 	}
    743  1.34.8.2  nathanw 	if ((xcs->cs_hwflags & ZS_HWFLAG_NO_CTS) && (cflag & (CRTSCTS | CDTRCTS)))
    744  1.34.8.2  nathanw 		return (EINVAL);
    745  1.34.8.2  nathanw 
    746  1.34.8.2  nathanw 	/*
    747  1.34.8.2  nathanw 	 * Output hardware flow control on the chip is horrendous:
    748  1.34.8.2  nathanw 	 * if carrier detect drops, the receiver is disabled, and if
    749  1.34.8.2  nathanw 	 * CTS drops, the transmitter is stoped IN MID CHARACTER!
    750  1.34.8.2  nathanw 	 * Therefore, NEVER set the HFC bit, and instead use the
    751  1.34.8.2  nathanw 	 * status interrupt to detect CTS changes.
    752  1.34.8.2  nathanw 	 */
    753  1.34.8.2  nathanw 	s = splzs();
    754  1.34.8.2  nathanw 	if ((cflag & (CLOCAL | MDMBUF)) != 0)
    755  1.34.8.2  nathanw 		cs->cs_rr0_dcd = 0;
    756  1.34.8.2  nathanw 	else
    757  1.34.8.2  nathanw 		cs->cs_rr0_dcd = ZSRR0_DCD;
    758  1.34.8.2  nathanw 	/*
    759  1.34.8.2  nathanw 	 * The mac hardware only has one output, DTR (HSKo in Mac
    760  1.34.8.2  nathanw 	 * parlance). In HFC mode, we use it for the functions
    761  1.34.8.2  nathanw 	 * typically served by RTS and DTR on other ports, so we
    762  1.34.8.2  nathanw 	 * have to fake the upper layer out some.
    763  1.34.8.2  nathanw 	 *
    764  1.34.8.2  nathanw 	 * CRTSCTS we use CTS as an input which tells us when to shut up.
    765  1.34.8.2  nathanw 	 * We make no effort to shut up the other side of the connection.
    766  1.34.8.2  nathanw 	 * DTR is used to hang up the modem.
    767  1.34.8.2  nathanw 	 *
    768  1.34.8.2  nathanw 	 * In CDTRCTS, we use CTS to tell us to stop, but we use DTR to
    769  1.34.8.2  nathanw 	 * shut up the other side.
    770  1.34.8.2  nathanw 	 */
    771  1.34.8.2  nathanw 	if ((cflag & CRTSCTS) != 0) {
    772  1.34.8.2  nathanw 		cs->cs_wr5_dtr = ZSWR5_DTR;
    773  1.34.8.2  nathanw 		cs->cs_wr5_rts = 0;
    774  1.34.8.2  nathanw 		cs->cs_rr0_cts = ZSRR0_CTS;
    775  1.34.8.2  nathanw 	} else if ((cflag & CDTRCTS) != 0) {
    776  1.34.8.2  nathanw 		cs->cs_wr5_dtr = 0;
    777  1.34.8.2  nathanw 		cs->cs_wr5_rts = ZSWR5_DTR;
    778  1.34.8.2  nathanw 		cs->cs_rr0_cts = ZSRR0_CTS;
    779  1.34.8.2  nathanw 	} else if ((cflag & MDMBUF) != 0) {
    780  1.34.8.2  nathanw 		cs->cs_wr5_dtr = 0;
    781  1.34.8.2  nathanw 		cs->cs_wr5_rts = ZSWR5_DTR;
    782  1.34.8.2  nathanw 		cs->cs_rr0_cts = ZSRR0_DCD;
    783  1.34.8.2  nathanw 	} else {
    784  1.34.8.2  nathanw 		cs->cs_wr5_dtr = ZSWR5_DTR;
    785  1.34.8.2  nathanw 		cs->cs_wr5_rts = 0;
    786  1.34.8.2  nathanw 		cs->cs_rr0_cts = 0;
    787  1.34.8.2  nathanw 	}
    788  1.34.8.2  nathanw 	splx(s);
    789  1.34.8.2  nathanw 
    790  1.34.8.2  nathanw 	/* Caller will stuff the pending registers. */
    791  1.34.8.2  nathanw 	return (0);
    792  1.34.8.2  nathanw }
    793  1.34.8.2  nathanw 
    794  1.34.8.2  nathanw 
    795  1.34.8.2  nathanw /*
    796  1.34.8.2  nathanw  * Read or write the chip with suitable delays.
    797  1.34.8.2  nathanw  * MacII hardware has the delay built in.
    798  1.34.8.2  nathanw  * No need for extra delay. :-) However, some clock-chirped
    799  1.34.8.2  nathanw  * macs, or zsc's on serial add-on boards might need it.
    800  1.34.8.2  nathanw  */
    801  1.34.8.2  nathanw #define	ZS_DELAY()
    802  1.34.8.2  nathanw 
    803  1.34.8.2  nathanw u_char
    804  1.34.8.2  nathanw zs_read_reg(cs, reg)
    805  1.34.8.2  nathanw 	struct zs_chanstate *cs;
    806  1.34.8.2  nathanw 	u_char reg;
    807  1.34.8.2  nathanw {
    808  1.34.8.2  nathanw 	u_char val;
    809  1.34.8.2  nathanw 
    810  1.34.8.2  nathanw 	*cs->cs_reg_csr = reg;
    811  1.34.8.2  nathanw 	ZS_DELAY();
    812  1.34.8.2  nathanw 	val = *cs->cs_reg_csr;
    813  1.34.8.2  nathanw 	ZS_DELAY();
    814  1.34.8.2  nathanw 	return val;
    815  1.34.8.2  nathanw }
    816  1.34.8.2  nathanw 
    817  1.34.8.2  nathanw void
    818  1.34.8.2  nathanw zs_write_reg(cs, reg, val)
    819  1.34.8.2  nathanw 	struct zs_chanstate *cs;
    820  1.34.8.2  nathanw 	u_char reg, val;
    821  1.34.8.2  nathanw {
    822  1.34.8.2  nathanw 	*cs->cs_reg_csr = reg;
    823  1.34.8.2  nathanw 	ZS_DELAY();
    824  1.34.8.2  nathanw 	*cs->cs_reg_csr = val;
    825  1.34.8.2  nathanw 	ZS_DELAY();
    826  1.34.8.2  nathanw }
    827  1.34.8.2  nathanw 
    828  1.34.8.2  nathanw u_char zs_read_csr(cs)
    829  1.34.8.2  nathanw 	struct zs_chanstate *cs;
    830  1.34.8.2  nathanw {
    831  1.34.8.2  nathanw 	u_char val;
    832  1.34.8.2  nathanw 
    833  1.34.8.2  nathanw 	val = *cs->cs_reg_csr;
    834  1.34.8.2  nathanw 	ZS_DELAY();
    835  1.34.8.2  nathanw 	/* make up for the fact CTS is wired backwards */
    836  1.34.8.2  nathanw 	val ^= ZSRR0_CTS;
    837  1.34.8.2  nathanw 	return val;
    838  1.34.8.2  nathanw }
    839  1.34.8.2  nathanw 
    840  1.34.8.2  nathanw void  zs_write_csr(cs, val)
    841  1.34.8.2  nathanw 	struct zs_chanstate *cs;
    842  1.34.8.2  nathanw 	u_char val;
    843  1.34.8.2  nathanw {
    844  1.34.8.2  nathanw 	/* Note, the csr does not write CTS... */
    845  1.34.8.2  nathanw 	*cs->cs_reg_csr = val;
    846  1.34.8.2  nathanw 	ZS_DELAY();
    847  1.34.8.2  nathanw }
    848  1.34.8.2  nathanw 
    849  1.34.8.2  nathanw u_char zs_read_data(cs)
    850  1.34.8.2  nathanw 	struct zs_chanstate *cs;
    851  1.34.8.2  nathanw {
    852  1.34.8.2  nathanw 	u_char val;
    853  1.34.8.2  nathanw 
    854  1.34.8.2  nathanw 	val = *cs->cs_reg_data;
    855  1.34.8.2  nathanw 	ZS_DELAY();
    856  1.34.8.2  nathanw 	return val;
    857  1.34.8.2  nathanw }
    858  1.34.8.2  nathanw 
    859  1.34.8.2  nathanw void  zs_write_data(cs, val)
    860  1.34.8.2  nathanw 	struct zs_chanstate *cs;
    861  1.34.8.2  nathanw 	u_char val;
    862  1.34.8.2  nathanw {
    863  1.34.8.2  nathanw 	*cs->cs_reg_data = val;
    864  1.34.8.2  nathanw 	ZS_DELAY();
    865  1.34.8.2  nathanw }
    866  1.34.8.2  nathanw 
    867  1.34.8.2  nathanw /****************************************************************
    868  1.34.8.2  nathanw  * Console support functions (mac68k specific!)
    869  1.34.8.2  nathanw  * Note: this code is allowed to know about the layout of
    870  1.34.8.2  nathanw  * the chip registers, and uses that to keep things simple.
    871  1.34.8.2  nathanw  * XXX - I think I like the mvme167 code better. -gwr
    872  1.34.8.2  nathanw  * XXX - Well :-P  :-)  -wrs
    873  1.34.8.2  nathanw  ****************************************************************/
    874  1.34.8.2  nathanw 
    875  1.34.8.2  nathanw #define zscnpollc	nullcnpollc
    876  1.34.8.2  nathanw cons_decl(zs);
    877  1.34.8.2  nathanw 
    878  1.34.8.2  nathanw static void	zscnsetup __P((void));
    879  1.34.8.2  nathanw 
    880  1.34.8.2  nathanw /*
    881  1.34.8.2  nathanw  * Console functions.
    882  1.34.8.2  nathanw  */
    883  1.34.8.2  nathanw 
    884  1.34.8.2  nathanw /*
    885  1.34.8.2  nathanw  * This code modled after the zs_setparam routine in zskgdb
    886  1.34.8.2  nathanw  * It sets the console unit to a known state so we can output
    887  1.34.8.2  nathanw  * correctly.
    888  1.34.8.2  nathanw  */
    889  1.34.8.2  nathanw static void
    890  1.34.8.2  nathanw zscnsetup()
    891  1.34.8.2  nathanw {
    892  1.34.8.2  nathanw 	struct xzs_chanstate xcs;
    893  1.34.8.2  nathanw 	struct zs_chanstate *cs;
    894  1.34.8.2  nathanw 	struct zschan *zc;
    895  1.34.8.2  nathanw 	int    tconst, s;
    896  1.34.8.2  nathanw 
    897  1.34.8.2  nathanw 	/* Setup temporary chanstate. */
    898  1.34.8.2  nathanw 	bzero((caddr_t)&xcs, sizeof(xcs));
    899  1.34.8.2  nathanw 	cs = &xcs.xzs_cs;
    900  1.34.8.2  nathanw 	zc = zs_conschan;
    901  1.34.8.2  nathanw 	cs->cs_reg_csr  = &zc->zc_csr;
    902  1.34.8.2  nathanw 	cs->cs_reg_data = &zc->zc_data;
    903  1.34.8.2  nathanw 	cs->cs_channel = zs_consunit;
    904  1.34.8.2  nathanw 	cs->cs_brg_clk = PCLK / 16;
    905  1.34.8.2  nathanw 
    906  1.34.8.2  nathanw 	bcopy(zs_init_reg, cs->cs_preg, 16);
    907  1.34.8.2  nathanw 	cs->cs_preg[5] |= ZSWR5_DTR | ZSWR5_RTS;
    908  1.34.8.2  nathanw 	cs->cs_preg[15] = ZSWR15_BREAK_IE;
    909  1.34.8.2  nathanw 	tconst = BPS_TO_TCONST(cs->cs_brg_clk,
    910  1.34.8.2  nathanw 		zs_defspeed[0][zs_consunit]);
    911  1.34.8.2  nathanw 	cs->cs_preg[12] = tconst;
    912  1.34.8.2  nathanw 	cs->cs_preg[13] = tconst >> 8;
    913  1.34.8.2  nathanw 	/* can't use zs_set_speed as we haven't set up the
    914  1.34.8.2  nathanw 	 * signal sources, and it's not worth it for now
    915  1.34.8.2  nathanw 	 */
    916  1.34.8.2  nathanw 
    917  1.34.8.2  nathanw 	/*
    918  1.34.8.2  nathanw 	 * As zs_loadchannelregs doesn't touch reg 9 (interupt control),
    919  1.34.8.2  nathanw 	 * we won't accidentally turn on interupts below
    920  1.34.8.2  nathanw 	 */
    921  1.34.8.2  nathanw 	s = splhigh();
    922  1.34.8.2  nathanw 	zs_loadchannelregs(cs);
    923  1.34.8.2  nathanw 	splx(s);
    924  1.34.8.2  nathanw }
    925  1.34.8.2  nathanw 
    926  1.34.8.2  nathanw /*
    927  1.34.8.2  nathanw  * zscnprobe is the routine which gets called as the kernel is trying to
    928  1.34.8.2  nathanw  * figure out where the console should be. Each io driver which might
    929  1.34.8.2  nathanw  * be the console (as defined in mac68k/conf.c) gets probed. The probe
    930  1.34.8.2  nathanw  * fills in the consdev structure. Important parts are the device #,
    931  1.34.8.2  nathanw  * and the console priority. Values are CN_DEAD (don't touch me),
    932  1.34.8.2  nathanw  * CN_NORMAL (I'm here, but elsewhere might be better), CN_INTERNAL
    933  1.34.8.2  nathanw  * (the video, better than CN_NORMAL), and CN_REMOTE (pick me!)
    934  1.34.8.2  nathanw  *
    935  1.34.8.2  nathanw  * As the mac's a bit different, we do extra work here. We mainly check
    936  1.34.8.2  nathanw  * to see if we have serial echo going on. Also chould check for default
    937  1.34.8.2  nathanw  * speeds.
    938  1.34.8.2  nathanw  */
    939  1.34.8.2  nathanw void
    940  1.34.8.2  nathanw zscnprobe(struct consdev * cp)
    941  1.34.8.2  nathanw {
    942  1.34.8.2  nathanw 	extern u_long   IOBase;
    943  1.34.8.2  nathanw 	int     maj, unit, i;
    944  1.34.8.3  nathanw 	extern const struct cdevsw zstty_cdevsw;
    945  1.34.8.2  nathanw 
    946  1.34.8.3  nathanw 	maj = cdevsw_lookup_major(&zstty_cdevsw);
    947  1.34.8.3  nathanw 	if (maj != -1) {
    948  1.34.8.2  nathanw 		cp->cn_pri = CN_NORMAL;		 /* Lower than CN_INTERNAL */
    949  1.34.8.2  nathanw 		if (mac68k_machine.serial_console != 0) {
    950  1.34.8.2  nathanw 			cp->cn_pri = CN_REMOTE;	 /* Higher than CN_INTERNAL */
    951  1.34.8.2  nathanw 			mac68k_machine.serial_boot_echo =0;
    952  1.34.8.2  nathanw 		}
    953  1.34.8.2  nathanw 
    954  1.34.8.2  nathanw 		unit = (mac68k_machine.serial_console == 1) ? 0 : 1;
    955  1.34.8.2  nathanw 		zs_consunit = unit;
    956  1.34.8.2  nathanw 		zs_conschan = (struct zschan *) -1; /* dummy flag for zs_init() */
    957  1.34.8.2  nathanw 
    958  1.34.8.2  nathanw 		mac68k_zsdev = cp->cn_dev = makedev(maj, unit);
    959  1.34.8.2  nathanw 	}
    960  1.34.8.2  nathanw 	if (mac68k_machine.serial_boot_echo) {
    961  1.34.8.2  nathanw 		/*
    962  1.34.8.2  nathanw 		 * at this point, we know that we don't have a serial
    963  1.34.8.2  nathanw 		 * console, but are doing echo
    964  1.34.8.2  nathanw 		 */
    965  1.34.8.2  nathanw 		zs_conschan = (struct zschan *) -1; /* dummy flag for zs_init() */
    966  1.34.8.2  nathanw 		zs_consunit = 1;
    967  1.34.8.2  nathanw 		zs_hwflags[0][zs_consunit] = ZS_HWFLAG_CONSOLE;
    968  1.34.8.2  nathanw 	}
    969  1.34.8.2  nathanw 
    970  1.34.8.2  nathanw 	if ((i = mac68k_machine.modem_d_speed) > 0) {
    971  1.34.8.2  nathanw 		if (zs_cn_check_speed(i))
    972  1.34.8.2  nathanw 			zs_defspeed[0][0] = i;
    973  1.34.8.2  nathanw 	}
    974  1.34.8.2  nathanw 	if ((i = mac68k_machine.print_d_speed) > 0) {
    975  1.34.8.2  nathanw 		if (zs_cn_check_speed(i))
    976  1.34.8.2  nathanw 			zs_defspeed[0][1] = i;
    977  1.34.8.2  nathanw 	}
    978  1.34.8.2  nathanw 	mac68k_set_io_offsets(IOBase);
    979  1.34.8.2  nathanw 	zs_init();
    980  1.34.8.2  nathanw 	/*
    981  1.34.8.2  nathanw 	 * zsinit will set up the addresses of the scc. It will also, if
    982  1.34.8.2  nathanw 	 * zs_conschan != 0, calculate the new address of the conschan for
    983  1.34.8.2  nathanw 	 * unit zs_consunit. So if we are (or think we are) going to use the
    984  1.34.8.2  nathanw 	 * chip for console I/O, we just set up the internal addresses for it.
    985  1.34.8.2  nathanw 	 *
    986  1.34.8.2  nathanw 	 * Now turn off interrupts for the chip. Note: using sccA to get at
    987  1.34.8.2  nathanw 	 * the chip is the only vestage of the NetBSD 1.0 ser driver. :-)
    988  1.34.8.2  nathanw 	 */
    989  1.34.8.2  nathanw 	unit = sccA[2];			/* reset reg. access */
    990  1.34.8.2  nathanw 	unit = sccA[0];
    991  1.34.8.2  nathanw 	sccA[2] = 9; sccA[2] = 0;	/* write 0 to reg. 9, clearing MIE */
    992  1.34.8.2  nathanw 	sccA[2] = ZSWR0_CLR_INTR; unit = sccA[2]; /* reset any pending ints. */
    993  1.34.8.2  nathanw 	sccA[0] = ZSWR0_CLR_INTR; unit = sccA[0];
    994  1.34.8.2  nathanw 
    995  1.34.8.2  nathanw 	if (mac68k_machine.serial_boot_echo)
    996  1.34.8.2  nathanw 		zscnsetup();
    997  1.34.8.2  nathanw 	return;
    998  1.34.8.2  nathanw }
    999  1.34.8.2  nathanw 
   1000  1.34.8.2  nathanw void
   1001  1.34.8.2  nathanw zscninit(struct consdev * cp)
   1002  1.34.8.2  nathanw {
   1003  1.34.8.2  nathanw 
   1004  1.34.8.2  nathanw 	zs_hwflags[0][zs_consunit] = ZS_HWFLAG_CONSOLE;
   1005  1.34.8.2  nathanw 	/*
   1006  1.34.8.2  nathanw 	 * zsinit will set up the addresses of the scc. It will also, if
   1007  1.34.8.2  nathanw 	 * zs_conschan != 0, calculate the new address of the conschan for
   1008  1.34.8.2  nathanw 	 * unit zs_consunit. So zs_init implicitly sets zs_conschan to the right
   1009  1.34.8.2  nathanw 	 * number. :-)
   1010  1.34.8.2  nathanw 	 */
   1011  1.34.8.2  nathanw 	zscnsetup();
   1012  1.34.8.2  nathanw 	printf("\nNetBSD/mac68k console\n");
   1013  1.34.8.2  nathanw }
   1014  1.34.8.2  nathanw 
   1015  1.34.8.2  nathanw 
   1016  1.34.8.2  nathanw /*
   1017  1.34.8.2  nathanw  * Polled input char.
   1018  1.34.8.2  nathanw  */
   1019  1.34.8.2  nathanw int
   1020  1.34.8.2  nathanw zs_getc(arg)
   1021  1.34.8.2  nathanw 	void *arg;
   1022  1.34.8.2  nathanw {
   1023  1.34.8.2  nathanw 	volatile struct zschan *zc = arg;
   1024  1.34.8.2  nathanw 	int s, c, rr0;
   1025  1.34.8.2  nathanw 
   1026  1.34.8.2  nathanw 	s = splhigh();
   1027  1.34.8.2  nathanw 	/* Wait for a character to arrive. */
   1028  1.34.8.2  nathanw 	do {
   1029  1.34.8.2  nathanw 		rr0 = zc->zc_csr;
   1030  1.34.8.2  nathanw 		ZS_DELAY();
   1031  1.34.8.2  nathanw 	} while ((rr0 & ZSRR0_RX_READY) == 0);
   1032  1.34.8.2  nathanw 
   1033  1.34.8.2  nathanw 	c = zc->zc_data;
   1034  1.34.8.2  nathanw 	ZS_DELAY();
   1035  1.34.8.2  nathanw 	splx(s);
   1036  1.34.8.2  nathanw 
   1037  1.34.8.2  nathanw 	/*
   1038  1.34.8.2  nathanw 	 * This is used by the kd driver to read scan codes,
   1039  1.34.8.2  nathanw 	 * so don't translate '\r' ==> '\n' here...
   1040  1.34.8.2  nathanw 	 */
   1041  1.34.8.2  nathanw 	return (c);
   1042  1.34.8.2  nathanw }
   1043  1.34.8.2  nathanw 
   1044  1.34.8.2  nathanw /*
   1045  1.34.8.2  nathanw  * Polled output char.
   1046  1.34.8.2  nathanw  */
   1047  1.34.8.2  nathanw void
   1048  1.34.8.2  nathanw zs_putc(arg, c)
   1049  1.34.8.2  nathanw 	void *arg;
   1050  1.34.8.2  nathanw 	int c;
   1051  1.34.8.2  nathanw {
   1052  1.34.8.2  nathanw 	volatile struct zschan *zc = arg;
   1053  1.34.8.2  nathanw 	int s, rr0;
   1054  1.34.8.2  nathanw 	long wait = 0;
   1055  1.34.8.2  nathanw 
   1056  1.34.8.2  nathanw 	s = splhigh();
   1057  1.34.8.2  nathanw 	/* Wait for transmitter to become ready. */
   1058  1.34.8.2  nathanw 	do {
   1059  1.34.8.2  nathanw 		rr0 = zc->zc_csr;
   1060  1.34.8.2  nathanw 		ZS_DELAY();
   1061  1.34.8.2  nathanw 	} while (((rr0 & ZSRR0_TX_READY) == 0) && (wait++ < 1000000));
   1062  1.34.8.2  nathanw 
   1063  1.34.8.2  nathanw 	if ((rr0 & ZSRR0_TX_READY) != 0) {
   1064  1.34.8.2  nathanw 		zc->zc_data = c;
   1065  1.34.8.2  nathanw 		ZS_DELAY();
   1066  1.34.8.2  nathanw 	}
   1067  1.34.8.2  nathanw 	splx(s);
   1068  1.34.8.2  nathanw }
   1069  1.34.8.2  nathanw 
   1070  1.34.8.2  nathanw 
   1071  1.34.8.2  nathanw /*
   1072  1.34.8.2  nathanw  * Polled console input putchar.
   1073  1.34.8.2  nathanw  */
   1074  1.34.8.2  nathanw int
   1075  1.34.8.2  nathanw zscngetc(dev)
   1076  1.34.8.2  nathanw 	dev_t dev;
   1077  1.34.8.2  nathanw {
   1078  1.34.8.2  nathanw 	struct zschan *zc = zs_conschan;
   1079  1.34.8.2  nathanw 	int c;
   1080  1.34.8.2  nathanw 
   1081  1.34.8.2  nathanw 	c = zs_getc(zc);
   1082  1.34.8.2  nathanw 	return (c);
   1083  1.34.8.2  nathanw }
   1084  1.34.8.2  nathanw 
   1085  1.34.8.2  nathanw /*
   1086  1.34.8.2  nathanw  * Polled console output putchar.
   1087  1.34.8.2  nathanw  */
   1088  1.34.8.2  nathanw void
   1089  1.34.8.2  nathanw zscnputc(dev, c)
   1090  1.34.8.2  nathanw 	dev_t dev;
   1091  1.34.8.2  nathanw 	int c;
   1092  1.34.8.2  nathanw {
   1093  1.34.8.2  nathanw 	struct zschan *zc = zs_conschan;
   1094  1.34.8.2  nathanw 
   1095  1.34.8.2  nathanw 	zs_putc(zc, c);
   1096  1.34.8.2  nathanw }
   1097  1.34.8.2  nathanw 
   1098  1.34.8.2  nathanw 
   1099  1.34.8.2  nathanw 
   1100  1.34.8.2  nathanw /*
   1101  1.34.8.2  nathanw  * Handle user request to enter kernel debugger.
   1102  1.34.8.2  nathanw  */
   1103  1.34.8.2  nathanw void
   1104  1.34.8.2  nathanw zs_abort(cs)
   1105  1.34.8.2  nathanw 	struct zs_chanstate *cs;
   1106  1.34.8.2  nathanw {
   1107  1.34.8.2  nathanw 	volatile struct zschan *zc = zs_conschan;
   1108  1.34.8.2  nathanw 	int rr0;
   1109  1.34.8.2  nathanw 	long wait = 0;
   1110  1.34.8.2  nathanw 
   1111  1.34.8.2  nathanw 	if (zs_cons_canabort == 0)
   1112  1.34.8.2  nathanw 		return;
   1113  1.34.8.2  nathanw 
   1114  1.34.8.2  nathanw 	/* Wait for end of break to avoid PROM abort. */
   1115  1.34.8.2  nathanw 	do {
   1116  1.34.8.2  nathanw 		rr0 = zc->zc_csr;
   1117  1.34.8.2  nathanw 		ZS_DELAY();
   1118  1.34.8.2  nathanw 	} while ((rr0 & ZSRR0_BREAK) && (wait++ < ZSABORT_DELAY));
   1119  1.34.8.2  nathanw 
   1120  1.34.8.2  nathanw 	if (wait > ZSABORT_DELAY) {
   1121  1.34.8.2  nathanw 		zs_cons_canabort = 0;
   1122  1.34.8.2  nathanw 	/* If we time out, turn off the abort ability! */
   1123  1.34.8.2  nathanw 	}
   1124  1.34.8.2  nathanw 
   1125  1.34.8.2  nathanw #ifdef DDB
   1126  1.34.8.2  nathanw 	Debugger();
   1127  1.34.8.2  nathanw #endif
   1128  1.34.8.2  nathanw }
   1129  1.34.8.2  nathanw 
   1130