Home | History | Annotate | Line # | Download | only in dev
zs.c revision 1.28.8.3
      1  1.28.8.3  thorpej /*	$NetBSD: zs.c,v 1.28.8.3 2003/01/03 16:48:28 thorpej Exp $	*/
      2  1.28.8.2  nathanw 
      3  1.28.8.2  nathanw /*-
      4  1.28.8.2  nathanw  * Copyright (c) 1996 The NetBSD Foundation, Inc.
      5  1.28.8.2  nathanw  * All rights reserved.
      6  1.28.8.2  nathanw  *
      7  1.28.8.2  nathanw  * This code is derived from software contributed to The NetBSD Foundation
      8  1.28.8.2  nathanw  * by Gordon W. Ross.
      9  1.28.8.2  nathanw  *
     10  1.28.8.2  nathanw  * Redistribution and use in source and binary forms, with or without
     11  1.28.8.2  nathanw  * modification, are permitted provided that the following conditions
     12  1.28.8.2  nathanw  * are met:
     13  1.28.8.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     14  1.28.8.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     15  1.28.8.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.28.8.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     17  1.28.8.2  nathanw  *    documentation and/or other materials provided with the distribution.
     18  1.28.8.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     19  1.28.8.2  nathanw  *    must display the following acknowledgement:
     20  1.28.8.2  nathanw  *        This product includes software developed by the NetBSD
     21  1.28.8.2  nathanw  *        Foundation, Inc. and its contributors.
     22  1.28.8.2  nathanw  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.28.8.2  nathanw  *    contributors may be used to endorse or promote products derived
     24  1.28.8.2  nathanw  *    from this software without specific prior written permission.
     25  1.28.8.2  nathanw  *
     26  1.28.8.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.28.8.2  nathanw  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.28.8.2  nathanw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.28.8.2  nathanw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.28.8.2  nathanw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.28.8.2  nathanw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.28.8.2  nathanw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.28.8.2  nathanw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.28.8.2  nathanw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.28.8.2  nathanw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.28.8.2  nathanw  * POSSIBILITY OF SUCH DAMAGE.
     37  1.28.8.2  nathanw  */
     38  1.28.8.2  nathanw 
     39  1.28.8.2  nathanw /*
     40  1.28.8.2  nathanw  * Zilog Z8530 Dual UART driver (machine-dependent part)
     41  1.28.8.2  nathanw  *
     42  1.28.8.2  nathanw  * Runs two serial lines per chip using slave drivers.
     43  1.28.8.2  nathanw  * Plain tty/async lines use the zs_async slave.
     44  1.28.8.2  nathanw  *
     45  1.28.8.2  nathanw  * Modified for NetBSD/mvme68k by Jason R. Thorpe <thorpej (at) NetBSD.ORG>
     46  1.28.8.2  nathanw  */
     47  1.28.8.2  nathanw 
     48  1.28.8.2  nathanw #include <sys/param.h>
     49  1.28.8.2  nathanw #include <sys/systm.h>
     50  1.28.8.2  nathanw #include <sys/conf.h>
     51  1.28.8.2  nathanw #include <sys/device.h>
     52  1.28.8.2  nathanw #include <sys/file.h>
     53  1.28.8.2  nathanw #include <sys/ioctl.h>
     54  1.28.8.2  nathanw #include <sys/kernel.h>
     55  1.28.8.2  nathanw #include <sys/proc.h>
     56  1.28.8.2  nathanw #include <sys/tty.h>
     57  1.28.8.2  nathanw #include <sys/time.h>
     58  1.28.8.2  nathanw #include <sys/syslog.h>
     59  1.28.8.2  nathanw 
     60  1.28.8.2  nathanw #include <dev/cons.h>
     61  1.28.8.2  nathanw #include <dev/ic/z8530reg.h>
     62  1.28.8.2  nathanw #include <machine/z8530var.h>
     63  1.28.8.2  nathanw 
     64  1.28.8.2  nathanw #include <machine/cpu.h>
     65  1.28.8.2  nathanw #include <machine/bus.h>
     66  1.28.8.2  nathanw #include <machine/intr.h>
     67  1.28.8.2  nathanw 
     68  1.28.8.2  nathanw #include <mvme68k/dev/zsvar.h>
     69  1.28.8.2  nathanw 
     70  1.28.8.2  nathanw /*
     71  1.28.8.2  nathanw  * Some warts needed by z8530tty.c -
     72  1.28.8.2  nathanw  * The default parity REALLY needs to be the same as the PROM uses,
     73  1.28.8.2  nathanw  * or you can not see messages done with printf during boot-up...
     74  1.28.8.2  nathanw  */
     75  1.28.8.2  nathanw int zs_def_cflag = (CREAD | CS8 | HUPCL);
     76  1.28.8.2  nathanw 
     77  1.28.8.2  nathanw /* Flags from zscnprobe() */
     78  1.28.8.2  nathanw static int zs_hwflags[NZSC][2];
     79  1.28.8.2  nathanw 
     80  1.28.8.2  nathanw /* Default speed for each channel */
     81  1.28.8.2  nathanw static int zs_defspeed[NZSC][2] = {
     82  1.28.8.2  nathanw 	{ 9600, 	/* port 1 */
     83  1.28.8.2  nathanw 	  9600 },	/* port 2 */
     84  1.28.8.2  nathanw 	{ 9600, 	/* port 3 */
     85  1.28.8.2  nathanw 	  9600 },	/* port 4 */
     86  1.28.8.2  nathanw };
     87  1.28.8.2  nathanw 
     88  1.28.8.2  nathanw static struct zs_chanstate zs_conschan_store;
     89  1.28.8.2  nathanw static struct zs_chanstate *zs_conschan;
     90  1.28.8.2  nathanw 
     91  1.28.8.2  nathanw u_char zs_init_reg[16] = {
     92  1.28.8.2  nathanw 	0,	/* 0: CMD (reset, etc.) */
     93  1.28.8.2  nathanw 	0,	/* 1: No interrupts yet. */
     94  1.28.8.2  nathanw 	0x18 + ZSHARD_PRI,	/* IVECT */
     95  1.28.8.2  nathanw 	ZSWR3_RX_8 | ZSWR3_RX_ENABLE,
     96  1.28.8.2  nathanw 	ZSWR4_CLK_X16 | ZSWR4_ONESB | ZSWR4_EVENP,
     97  1.28.8.2  nathanw 	ZSWR5_TX_8 | ZSWR5_TX_ENABLE,
     98  1.28.8.2  nathanw 	0,	/* 6: TXSYNC/SYNCLO */
     99  1.28.8.2  nathanw 	0,	/* 7: RXSYNC/SYNCHI */
    100  1.28.8.2  nathanw 	0,	/* 8: alias for data port */
    101  1.28.8.2  nathanw 	ZSWR9_MASTER_IE,
    102  1.28.8.2  nathanw 	0,	/*10: Misc. TX/RX control bits */
    103  1.28.8.2  nathanw 	ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD,
    104  1.28.8.2  nathanw 	0,			/*12: BAUDLO (default=9600) */
    105  1.28.8.2  nathanw 	0,			/*13: BAUDHI (default=9600) */
    106  1.28.8.2  nathanw 	ZSWR14_BAUD_ENA | ZSWR14_BAUD_FROM_PCLK,
    107  1.28.8.2  nathanw 	ZSWR15_BREAK_IE,
    108  1.28.8.2  nathanw };
    109  1.28.8.2  nathanw 
    110  1.28.8.2  nathanw 
    111  1.28.8.2  nathanw /****************************************************************
    112  1.28.8.2  nathanw  * Autoconfig
    113  1.28.8.2  nathanw  ****************************************************************/
    114  1.28.8.2  nathanw 
    115  1.28.8.2  nathanw /* Definition of the driver for autoconfig. */
    116  1.28.8.2  nathanw static int	zsc_print __P((void *, const char *name));
    117  1.28.8.2  nathanw int	zs_getc __P((void *));
    118  1.28.8.2  nathanw void	zs_putc __P((void *, int));
    119  1.28.8.2  nathanw 
    120  1.28.8.2  nathanw #if 0
    121  1.28.8.2  nathanw static int zs_get_speed __P((struct zs_chanstate *));
    122  1.28.8.2  nathanw #endif
    123  1.28.8.2  nathanw 
    124  1.28.8.2  nathanw extern struct cfdriver zsc_cd;
    125  1.28.8.2  nathanw 
    126  1.28.8.2  nathanw cons_decl(zsc_pcc);
    127  1.28.8.2  nathanw 
    128  1.28.8.2  nathanw 
    129  1.28.8.2  nathanw /*
    130  1.28.8.2  nathanw  * Configure children of an SCC.
    131  1.28.8.2  nathanw  */
    132  1.28.8.2  nathanw void
    133  1.28.8.2  nathanw zs_config(zsc, zs, vector, pclk)
    134  1.28.8.2  nathanw 	struct zsc_softc *zsc;
    135  1.28.8.2  nathanw 	struct zsdevice *zs;
    136  1.28.8.2  nathanw 	int vector, pclk;
    137  1.28.8.2  nathanw {
    138  1.28.8.2  nathanw 	struct zsc_attach_args zsc_args;
    139  1.28.8.2  nathanw 	volatile struct zschan *zc;
    140  1.28.8.2  nathanw 	struct zs_chanstate *cs;
    141  1.28.8.2  nathanw 	int zsc_unit, channel, s;
    142  1.28.8.2  nathanw 
    143  1.28.8.2  nathanw 	zsc_unit = zsc->zsc_dev.dv_unit;
    144  1.28.8.2  nathanw 	printf(": Zilog 8530 SCC at vector 0x%x\n", vector);
    145  1.28.8.2  nathanw 
    146  1.28.8.2  nathanw 	/*
    147  1.28.8.2  nathanw 	 * Initialize software state for each channel.
    148  1.28.8.2  nathanw 	 */
    149  1.28.8.2  nathanw 	for (channel = 0; channel < 2; channel++) {
    150  1.28.8.2  nathanw 		zsc_args.channel = channel;
    151  1.28.8.2  nathanw 		zsc_args.hwflags = zs_hwflags[zsc_unit][channel];
    152  1.28.8.2  nathanw 		cs = &zsc->zsc_cs_store[channel];
    153  1.28.8.2  nathanw 		zsc->zsc_cs[channel] = cs;
    154  1.28.8.2  nathanw 
    155  1.28.8.2  nathanw 		/*
    156  1.28.8.2  nathanw 		 * If we're the console, copy the channel state, and
    157  1.28.8.2  nathanw 		 * adjust the console channel pointer.
    158  1.28.8.2  nathanw 		 */
    159  1.28.8.2  nathanw 		if (zsc_args.hwflags & ZS_HWFLAG_CONSOLE) {
    160  1.28.8.2  nathanw 			memcpy(cs, zs_conschan, sizeof(struct zs_chanstate));
    161  1.28.8.2  nathanw 			zs_conschan = cs;
    162  1.28.8.2  nathanw 		} else {
    163  1.28.8.2  nathanw 			zc = (channel == 0) ? &zs->zs_chan_a : &zs->zs_chan_b;
    164  1.28.8.2  nathanw 			cs->cs_reg_csr  = zc->zc_csr;
    165  1.28.8.2  nathanw 			cs->cs_reg_data = zc->zc_data;
    166  1.28.8.2  nathanw 			memcpy(cs->cs_creg, zs_init_reg, 16);
    167  1.28.8.2  nathanw 			memcpy(cs->cs_preg, zs_init_reg, 16);
    168  1.28.8.2  nathanw 			cs->cs_defspeed = zs_defspeed[zsc_unit][channel];
    169  1.28.8.2  nathanw 		}
    170  1.28.8.2  nathanw 
    171  1.28.8.2  nathanw 		cs->cs_brg_clk = pclk / 16;
    172  1.28.8.2  nathanw 		cs->cs_creg[2] = cs->cs_preg[2] = vector;
    173  1.28.8.2  nathanw 		zs_set_speed(cs, cs->cs_defspeed);
    174  1.28.8.2  nathanw 		cs->cs_creg[12] = cs->cs_preg[12];
    175  1.28.8.2  nathanw 		cs->cs_creg[13] = cs->cs_preg[13];
    176  1.28.8.2  nathanw 		cs->cs_defcflag = zs_def_cflag;
    177  1.28.8.2  nathanw 
    178  1.28.8.2  nathanw 		/* Make these correspond to cs_defcflag (-crtscts) */
    179  1.28.8.2  nathanw 		cs->cs_rr0_dcd = ZSRR0_DCD;
    180  1.28.8.2  nathanw 		cs->cs_rr0_cts = 0;
    181  1.28.8.2  nathanw 		cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
    182  1.28.8.2  nathanw 		cs->cs_wr5_rts = 0;
    183  1.28.8.2  nathanw 
    184  1.28.8.2  nathanw 		cs->cs_channel = channel;
    185  1.28.8.2  nathanw 		cs->cs_private = NULL;
    186  1.28.8.2  nathanw 		cs->cs_ops = &zsops_null;
    187  1.28.8.2  nathanw 
    188  1.28.8.2  nathanw 		/*
    189  1.28.8.2  nathanw 		 * Clear the master interrupt enable.
    190  1.28.8.2  nathanw 		 * The INTENA is common to both channels,
    191  1.28.8.2  nathanw 		 * so just do it on the A channel.
    192  1.28.8.2  nathanw 		 * Write the interrupt vector while we're at it.
    193  1.28.8.2  nathanw 		 */
    194  1.28.8.2  nathanw 		if (channel == 0) {
    195  1.28.8.2  nathanw 			zs_write_reg(cs, 9, 0);
    196  1.28.8.2  nathanw 			zs_write_reg(cs, 2, vector);
    197  1.28.8.2  nathanw 		}
    198  1.28.8.2  nathanw 
    199  1.28.8.2  nathanw 		/*
    200  1.28.8.2  nathanw 		 * Look for a child driver for this channel.
    201  1.28.8.2  nathanw 		 * The child attach will setup the hardware.
    202  1.28.8.2  nathanw 		 */
    203  1.28.8.2  nathanw 		if (!config_found(&zsc->zsc_dev, (void *)&zsc_args, zsc_print)) {
    204  1.28.8.2  nathanw 			/* No sub-driver.  Just reset it. */
    205  1.28.8.2  nathanw 			u_char reset = (channel == 0) ?
    206  1.28.8.2  nathanw 				ZSWR9_A_RESET : ZSWR9_B_RESET;
    207  1.28.8.2  nathanw 			s = splzs();
    208  1.28.8.2  nathanw 			zs_write_reg(cs,  9, reset);
    209  1.28.8.2  nathanw 			splx(s);
    210  1.28.8.2  nathanw 		}
    211  1.28.8.2  nathanw 	}
    212  1.28.8.2  nathanw 
    213  1.28.8.2  nathanw 	/*
    214  1.28.8.2  nathanw 	 * Allocate a software interrupt cookie.
    215  1.28.8.2  nathanw 	 */
    216  1.28.8.2  nathanw 	zsc->zsc_softintr_cookie = softintr_establish(IPL_SOFTSERIAL,
    217  1.28.8.2  nathanw 	    (void (*)(void *)) zsc_intr_soft, zsc);
    218  1.28.8.2  nathanw #ifdef DEBUG
    219  1.28.8.2  nathanw 	assert(zsc->zsc_softintr_cookie);
    220  1.28.8.2  nathanw #endif
    221  1.28.8.2  nathanw }
    222  1.28.8.2  nathanw 
    223  1.28.8.2  nathanw static int
    224  1.28.8.2  nathanw zsc_print(aux, name)
    225  1.28.8.2  nathanw 	void *aux;
    226  1.28.8.2  nathanw 	const char *name;
    227  1.28.8.2  nathanw {
    228  1.28.8.2  nathanw 	struct zsc_attach_args *args = aux;
    229  1.28.8.2  nathanw 
    230  1.28.8.2  nathanw 	if (name != NULL)
    231  1.28.8.3  thorpej 		aprint_normal("%s: ", name);
    232  1.28.8.2  nathanw 
    233  1.28.8.2  nathanw 	if (args->channel != -1)
    234  1.28.8.3  thorpej 		aprint_normal(" channel %d", args->channel);
    235  1.28.8.2  nathanw 
    236  1.28.8.2  nathanw 	return UNCONF;
    237  1.28.8.2  nathanw }
    238  1.28.8.2  nathanw 
    239  1.28.8.2  nathanw #if defined(MVME162) || defined(MVME172)
    240  1.28.8.2  nathanw /*
    241  1.28.8.2  nathanw  * Our ZS chips each have their own interrupt vector.
    242  1.28.8.2  nathanw  */
    243  1.28.8.2  nathanw int
    244  1.28.8.2  nathanw zshard_unshared(arg)
    245  1.28.8.2  nathanw 	void *arg;
    246  1.28.8.2  nathanw {
    247  1.28.8.2  nathanw 	struct zsc_softc *zsc = arg;
    248  1.28.8.2  nathanw 	int rval;
    249  1.28.8.2  nathanw 
    250  1.28.8.2  nathanw 	rval = zsc_intr_hard(zsc);
    251  1.28.8.2  nathanw 
    252  1.28.8.2  nathanw 	if (rval) {
    253  1.28.8.2  nathanw 		if ((zsc->zsc_cs[0]->cs_softreq) ||
    254  1.28.8.2  nathanw 		    (zsc->zsc_cs[1]->cs_softreq))
    255  1.28.8.2  nathanw 			softintr_schedule(zsc->zsc_softintr_cookie);
    256  1.28.8.2  nathanw 		zsc->zsc_evcnt.ev_count++;
    257  1.28.8.2  nathanw 	}
    258  1.28.8.2  nathanw 
    259  1.28.8.2  nathanw 	return (rval);
    260  1.28.8.2  nathanw }
    261  1.28.8.2  nathanw #endif
    262  1.28.8.2  nathanw 
    263  1.28.8.2  nathanw #ifdef MVME147
    264  1.28.8.2  nathanw /*
    265  1.28.8.2  nathanw  * Our ZS chips all share a common, PCC-vectored interrupt,
    266  1.28.8.2  nathanw  * so we have to look at all of them on each interrupt.
    267  1.28.8.2  nathanw  */
    268  1.28.8.2  nathanw int
    269  1.28.8.2  nathanw zshard_shared(arg)
    270  1.28.8.2  nathanw 	void *arg;
    271  1.28.8.2  nathanw {
    272  1.28.8.2  nathanw 	struct zsc_softc *zsc;
    273  1.28.8.2  nathanw 	int unit, rval;
    274  1.28.8.2  nathanw 
    275  1.28.8.2  nathanw 	rval = 0;
    276  1.28.8.2  nathanw 	for (unit = 0; unit < zsc_cd.cd_ndevs; unit++) {
    277  1.28.8.2  nathanw 		zsc = zsc_cd.cd_devs[unit];
    278  1.28.8.2  nathanw 		if (zsc != NULL && zsc_intr_hard(zsc)) {
    279  1.28.8.2  nathanw 			if ((zsc->zsc_cs[0]->cs_softreq) ||
    280  1.28.8.2  nathanw 			    (zsc->zsc_cs[1]->cs_softreq))
    281  1.28.8.2  nathanw 				softintr_schedule(zsc->zsc_softintr_cookie);
    282  1.28.8.2  nathanw 			zsc->zsc_evcnt.ev_count++;
    283  1.28.8.2  nathanw 			rval++;
    284  1.28.8.2  nathanw 		}
    285  1.28.8.2  nathanw 	}
    286  1.28.8.2  nathanw 	return (rval);
    287  1.28.8.2  nathanw }
    288  1.28.8.2  nathanw #endif
    289  1.28.8.2  nathanw 
    290  1.28.8.2  nathanw 
    291  1.28.8.2  nathanw #if 0
    292  1.28.8.2  nathanw /*
    293  1.28.8.2  nathanw  * Compute the current baud rate given a ZSCC channel.
    294  1.28.8.2  nathanw  */
    295  1.28.8.2  nathanw static int
    296  1.28.8.2  nathanw zs_get_speed(cs)
    297  1.28.8.2  nathanw 	struct zs_chanstate *cs;
    298  1.28.8.2  nathanw {
    299  1.28.8.2  nathanw 	int tconst;
    300  1.28.8.2  nathanw 
    301  1.28.8.2  nathanw 	tconst = zs_read_reg(cs, 12);
    302  1.28.8.2  nathanw 	tconst |= zs_read_reg(cs, 13) << 8;
    303  1.28.8.2  nathanw 	return (TCONST_TO_BPS(cs->cs_brg_clk, tconst));
    304  1.28.8.2  nathanw }
    305  1.28.8.2  nathanw #endif
    306  1.28.8.2  nathanw 
    307  1.28.8.2  nathanw /*
    308  1.28.8.2  nathanw  * MD functions for setting the baud rate and control modes.
    309  1.28.8.2  nathanw  */
    310  1.28.8.2  nathanw int
    311  1.28.8.2  nathanw zs_set_speed(cs, bps)
    312  1.28.8.2  nathanw 	struct zs_chanstate *cs;
    313  1.28.8.2  nathanw 	int bps;	/* bits per second */
    314  1.28.8.2  nathanw {
    315  1.28.8.2  nathanw 	int tconst, real_bps;
    316  1.28.8.2  nathanw 
    317  1.28.8.2  nathanw 	if (bps == 0)
    318  1.28.8.2  nathanw 		return (0);
    319  1.28.8.2  nathanw 
    320  1.28.8.2  nathanw #ifdef	DIAGNOSTIC
    321  1.28.8.2  nathanw 	if (cs->cs_brg_clk == 0)
    322  1.28.8.2  nathanw 		panic("zs_set_speed");
    323  1.28.8.2  nathanw #endif
    324  1.28.8.2  nathanw 
    325  1.28.8.2  nathanw 	tconst = BPS_TO_TCONST(cs->cs_brg_clk, bps);
    326  1.28.8.2  nathanw 	if (tconst < 0)
    327  1.28.8.2  nathanw 		return (EINVAL);
    328  1.28.8.2  nathanw 
    329  1.28.8.2  nathanw 	/* Convert back to make sure we can do it. */
    330  1.28.8.2  nathanw 	real_bps = TCONST_TO_BPS(cs->cs_brg_clk, tconst);
    331  1.28.8.2  nathanw 
    332  1.28.8.2  nathanw 	/* Allow 2% tolerance WRT the required bps */
    333  1.28.8.2  nathanw 	if (((abs(real_bps - bps) * 1000) / bps) > 20)
    334  1.28.8.2  nathanw 		return (EINVAL);
    335  1.28.8.2  nathanw 
    336  1.28.8.2  nathanw 	cs->cs_preg[12] = tconst;
    337  1.28.8.2  nathanw 	cs->cs_preg[13] = tconst >> 8;
    338  1.28.8.2  nathanw 
    339  1.28.8.2  nathanw 	/* Caller will stuff the pending registers. */
    340  1.28.8.2  nathanw 	return (0);
    341  1.28.8.2  nathanw }
    342  1.28.8.2  nathanw 
    343  1.28.8.2  nathanw int
    344  1.28.8.2  nathanw zs_set_modes(cs, cflag)
    345  1.28.8.2  nathanw 	struct zs_chanstate *cs;
    346  1.28.8.2  nathanw 	int cflag;	/* bits per second */
    347  1.28.8.2  nathanw {
    348  1.28.8.2  nathanw 	int s;
    349  1.28.8.2  nathanw 
    350  1.28.8.2  nathanw 	/*
    351  1.28.8.2  nathanw 	 * Output hardware flow control on the chip is horrendous:
    352  1.28.8.2  nathanw 	 * if carrier detect drops, the receiver is disabled, and if
    353  1.28.8.2  nathanw 	 * CTS drops, the transmitter is stoped IN MID CHARACTER!
    354  1.28.8.2  nathanw 	 * Therefore, NEVER set the HFC bit, and instead use the
    355  1.28.8.2  nathanw 	 * status interrupt to detect CTS changes.
    356  1.28.8.2  nathanw 	 */
    357  1.28.8.2  nathanw 	s = splzs();
    358  1.28.8.2  nathanw 	cs->cs_rr0_pps = 0;
    359  1.28.8.2  nathanw 	if ((cflag & (CLOCAL | MDMBUF)) != 0) {
    360  1.28.8.2  nathanw 		cs->cs_rr0_dcd = 0;
    361  1.28.8.2  nathanw 		if ((cflag & MDMBUF) == 0)
    362  1.28.8.2  nathanw 			cs->cs_rr0_pps = ZSRR0_DCD;
    363  1.28.8.2  nathanw 	} else
    364  1.28.8.2  nathanw 		cs->cs_rr0_dcd = ZSRR0_DCD;
    365  1.28.8.2  nathanw 	if ((cflag & CRTSCTS) != 0) {
    366  1.28.8.2  nathanw 		cs->cs_wr5_dtr = ZSWR5_DTR;
    367  1.28.8.2  nathanw 		cs->cs_wr5_rts = ZSWR5_RTS;
    368  1.28.8.2  nathanw 		cs->cs_rr0_cts = ZSRR0_CTS;
    369  1.28.8.2  nathanw 	} else if ((cflag & MDMBUF) != 0) {
    370  1.28.8.2  nathanw 		cs->cs_wr5_dtr = 0;
    371  1.28.8.2  nathanw 		cs->cs_wr5_rts = ZSWR5_DTR;
    372  1.28.8.2  nathanw 		cs->cs_rr0_cts = ZSRR0_DCD;
    373  1.28.8.2  nathanw 	} else {
    374  1.28.8.2  nathanw 		cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
    375  1.28.8.2  nathanw 		cs->cs_wr5_rts = 0;
    376  1.28.8.2  nathanw 		cs->cs_rr0_cts = 0;
    377  1.28.8.2  nathanw 	}
    378  1.28.8.2  nathanw 	splx(s);
    379  1.28.8.2  nathanw 
    380  1.28.8.2  nathanw 	/* Caller will stuff the pending registers. */
    381  1.28.8.2  nathanw 	return (0);
    382  1.28.8.2  nathanw }
    383  1.28.8.2  nathanw 
    384  1.28.8.2  nathanw 
    385  1.28.8.2  nathanw /*
    386  1.28.8.2  nathanw  * Read or write the chip with suitable delays.
    387  1.28.8.2  nathanw  */
    388  1.28.8.2  nathanw 
    389  1.28.8.2  nathanw u_char
    390  1.28.8.2  nathanw zs_read_reg(cs, reg)
    391  1.28.8.2  nathanw 	struct zs_chanstate *cs;
    392  1.28.8.2  nathanw 	u_char reg;
    393  1.28.8.2  nathanw {
    394  1.28.8.2  nathanw 	u_char val;
    395  1.28.8.2  nathanw 
    396  1.28.8.2  nathanw 	*cs->cs_reg_csr = reg;
    397  1.28.8.2  nathanw 	ZS_DELAY();
    398  1.28.8.2  nathanw 	val = *cs->cs_reg_csr;
    399  1.28.8.2  nathanw 	ZS_DELAY();
    400  1.28.8.2  nathanw 	return val;
    401  1.28.8.2  nathanw }
    402  1.28.8.2  nathanw 
    403  1.28.8.2  nathanw void
    404  1.28.8.2  nathanw zs_write_reg(cs, reg, val)
    405  1.28.8.2  nathanw 	struct zs_chanstate *cs;
    406  1.28.8.2  nathanw 	u_char reg, val;
    407  1.28.8.2  nathanw {
    408  1.28.8.2  nathanw 	*cs->cs_reg_csr = reg;
    409  1.28.8.2  nathanw 	ZS_DELAY();
    410  1.28.8.2  nathanw 	*cs->cs_reg_csr = val;
    411  1.28.8.2  nathanw 	ZS_DELAY();
    412  1.28.8.2  nathanw }
    413  1.28.8.2  nathanw 
    414  1.28.8.2  nathanw u_char zs_read_csr(cs)
    415  1.28.8.2  nathanw 	struct zs_chanstate *cs;
    416  1.28.8.2  nathanw {
    417  1.28.8.2  nathanw 	u_char val;
    418  1.28.8.2  nathanw 
    419  1.28.8.2  nathanw 	val = *cs->cs_reg_csr;
    420  1.28.8.2  nathanw 	ZS_DELAY();
    421  1.28.8.2  nathanw 	return val;
    422  1.28.8.2  nathanw }
    423  1.28.8.2  nathanw 
    424  1.28.8.2  nathanw void  zs_write_csr(cs, val)
    425  1.28.8.2  nathanw 	struct zs_chanstate *cs;
    426  1.28.8.2  nathanw 	u_char val;
    427  1.28.8.2  nathanw {
    428  1.28.8.2  nathanw 	*cs->cs_reg_csr = val;
    429  1.28.8.2  nathanw 	ZS_DELAY();
    430  1.28.8.2  nathanw }
    431  1.28.8.2  nathanw 
    432  1.28.8.2  nathanw u_char zs_read_data(cs)
    433  1.28.8.2  nathanw 	struct zs_chanstate *cs;
    434  1.28.8.2  nathanw {
    435  1.28.8.2  nathanw 	u_char val;
    436  1.28.8.2  nathanw 
    437  1.28.8.2  nathanw 	val = *cs->cs_reg_data;
    438  1.28.8.2  nathanw 	ZS_DELAY();
    439  1.28.8.2  nathanw 	return val;
    440  1.28.8.2  nathanw }
    441  1.28.8.2  nathanw 
    442  1.28.8.2  nathanw void  zs_write_data(cs, val)
    443  1.28.8.2  nathanw 	struct zs_chanstate *cs;
    444  1.28.8.2  nathanw 	u_char val;
    445  1.28.8.2  nathanw {
    446  1.28.8.2  nathanw 	*cs->cs_reg_data = val;
    447  1.28.8.2  nathanw 	ZS_DELAY();
    448  1.28.8.2  nathanw }
    449  1.28.8.2  nathanw 
    450  1.28.8.2  nathanw /****************************************************************
    451  1.28.8.2  nathanw  * Console support functions (MVME specific!)
    452  1.28.8.2  nathanw  ****************************************************************/
    453  1.28.8.2  nathanw 
    454  1.28.8.2  nathanw /*
    455  1.28.8.2  nathanw  * Polled input char.
    456  1.28.8.2  nathanw  */
    457  1.28.8.2  nathanw int
    458  1.28.8.2  nathanw zs_getc(arg)
    459  1.28.8.2  nathanw 	void *arg;
    460  1.28.8.2  nathanw {
    461  1.28.8.2  nathanw 	struct zs_chanstate *cs = arg;
    462  1.28.8.2  nathanw 	int s, c, rr0, stat;
    463  1.28.8.2  nathanw 
    464  1.28.8.2  nathanw 	s = splhigh();
    465  1.28.8.2  nathanw  top:
    466  1.28.8.2  nathanw 	/* Wait for a character to arrive. */
    467  1.28.8.2  nathanw 	do {
    468  1.28.8.2  nathanw 		rr0 = *cs->cs_reg_csr;
    469  1.28.8.2  nathanw 		ZS_DELAY();
    470  1.28.8.2  nathanw 	} while ((rr0 & ZSRR0_RX_READY) == 0);
    471  1.28.8.2  nathanw 
    472  1.28.8.2  nathanw 	/* Read error register. */
    473  1.28.8.2  nathanw 	stat = zs_read_reg(cs, 1) & (ZSRR1_FE | ZSRR1_DO | ZSRR1_PE);
    474  1.28.8.2  nathanw 	if (stat) {
    475  1.28.8.2  nathanw 		zs_write_csr(cs, ZSM_RESET_ERR);
    476  1.28.8.2  nathanw 		goto top;
    477  1.28.8.2  nathanw 	}
    478  1.28.8.2  nathanw 
    479  1.28.8.2  nathanw 	/* Read character. */
    480  1.28.8.2  nathanw 	c = *cs->cs_reg_data;
    481  1.28.8.2  nathanw 	ZS_DELAY();
    482  1.28.8.2  nathanw 	splx(s);
    483  1.28.8.2  nathanw 
    484  1.28.8.2  nathanw 	return (c);
    485  1.28.8.2  nathanw }
    486  1.28.8.2  nathanw 
    487  1.28.8.2  nathanw /*
    488  1.28.8.2  nathanw  * Polled output char.
    489  1.28.8.2  nathanw  */
    490  1.28.8.2  nathanw void
    491  1.28.8.2  nathanw zs_putc(arg, c)
    492  1.28.8.2  nathanw 	void *arg;
    493  1.28.8.2  nathanw 	int c;
    494  1.28.8.2  nathanw {
    495  1.28.8.2  nathanw 	struct zs_chanstate *cs = arg;
    496  1.28.8.2  nathanw 	int s, rr0;
    497  1.28.8.2  nathanw 
    498  1.28.8.2  nathanw 	s = splhigh();
    499  1.28.8.2  nathanw 	/* Wait for transmitter to become ready. */
    500  1.28.8.2  nathanw 	do {
    501  1.28.8.2  nathanw 		rr0 = *cs->cs_reg_csr;
    502  1.28.8.2  nathanw 		ZS_DELAY();
    503  1.28.8.2  nathanw 	} while ((rr0 & ZSRR0_TX_READY) == 0);
    504  1.28.8.2  nathanw 
    505  1.28.8.2  nathanw 	*cs->cs_reg_data = c;
    506  1.28.8.2  nathanw 	ZS_DELAY();
    507  1.28.8.2  nathanw 	splx(s);
    508  1.28.8.2  nathanw }
    509  1.28.8.2  nathanw 
    510  1.28.8.2  nathanw /*
    511  1.28.8.2  nathanw  * Common parts of console init.
    512  1.28.8.2  nathanw  */
    513  1.28.8.2  nathanw void
    514  1.28.8.2  nathanw zs_cnconfig(zsc_unit, channel, zs, pclk)
    515  1.28.8.2  nathanw 	int zsc_unit, channel;
    516  1.28.8.2  nathanw 	struct zsdevice *zs;
    517  1.28.8.2  nathanw 	int pclk;
    518  1.28.8.2  nathanw {
    519  1.28.8.2  nathanw 	struct zs_chanstate *cs;
    520  1.28.8.2  nathanw 	struct zschan *zc;
    521  1.28.8.2  nathanw 
    522  1.28.8.2  nathanw 	zc = (channel == 0) ? &zs->zs_chan_a : &zs->zs_chan_b;
    523  1.28.8.2  nathanw 
    524  1.28.8.2  nathanw 	/*
    525  1.28.8.2  nathanw 	 * Pointer to channel state.  Later, the console channel
    526  1.28.8.2  nathanw 	 * state is copied into the softc, and the console channel
    527  1.28.8.2  nathanw 	 * pointer adjusted to point to the new copy.
    528  1.28.8.2  nathanw 	 */
    529  1.28.8.2  nathanw 	zs_conschan = cs = &zs_conschan_store;
    530  1.28.8.2  nathanw 	zs_hwflags[zsc_unit][channel] = ZS_HWFLAG_CONSOLE;
    531  1.28.8.2  nathanw 
    532  1.28.8.2  nathanw 	/* Setup temporary chanstate. */
    533  1.28.8.2  nathanw 	cs->cs_brg_clk = pclk / 16;
    534  1.28.8.2  nathanw 	cs->cs_reg_csr  = zc->zc_csr;
    535  1.28.8.2  nathanw 	cs->cs_reg_data = zc->zc_data;
    536  1.28.8.2  nathanw 
    537  1.28.8.2  nathanw 	/* Initialize the pending registers. */
    538  1.28.8.2  nathanw 	memcpy(cs->cs_preg, zs_init_reg, 16);
    539  1.28.8.2  nathanw 	cs->cs_preg[5] |= (ZSWR5_DTR | ZSWR5_RTS);
    540  1.28.8.2  nathanw 
    541  1.28.8.2  nathanw #if 0
    542  1.28.8.2  nathanw 	/* XXX: Preserve BAUD rate from boot loader. */
    543  1.28.8.2  nathanw 	/* XXX: Also, why reset the chip here? -gwr */
    544  1.28.8.2  nathanw 	cs->cs_defspeed = zs_get_speed(cs);
    545  1.28.8.2  nathanw #else
    546  1.28.8.2  nathanw 	cs->cs_defspeed = 9600;	/* XXX */
    547  1.28.8.2  nathanw #endif
    548  1.28.8.2  nathanw 	zs_set_speed(cs, cs->cs_defspeed);
    549  1.28.8.2  nathanw 	cs->cs_creg[12] = cs->cs_preg[12];
    550  1.28.8.2  nathanw 	cs->cs_creg[13] = cs->cs_preg[13];
    551  1.28.8.2  nathanw 
    552  1.28.8.2  nathanw 	/* Clear the master interrupt enable. */
    553  1.28.8.2  nathanw 	zs_write_reg(cs, 9, 0);
    554  1.28.8.2  nathanw 
    555  1.28.8.2  nathanw 	/* Reset the whole SCC chip. */
    556  1.28.8.2  nathanw 	zs_write_reg(cs, 9, ZSWR9_HARD_RESET);
    557  1.28.8.2  nathanw 
    558  1.28.8.2  nathanw 	/* Copy "pending" to "current" and H/W. */
    559  1.28.8.2  nathanw 	zs_loadchannelregs(cs);
    560  1.28.8.2  nathanw }
    561  1.28.8.2  nathanw 
    562  1.28.8.2  nathanw /*
    563  1.28.8.2  nathanw  * Polled console input putchar.
    564  1.28.8.2  nathanw  */
    565  1.28.8.2  nathanw int
    566  1.28.8.2  nathanw zsc_pcccngetc(dev)
    567  1.28.8.2  nathanw 	dev_t dev;
    568  1.28.8.2  nathanw {
    569  1.28.8.2  nathanw 	struct zs_chanstate *cs = zs_conschan;
    570  1.28.8.2  nathanw 	int c;
    571  1.28.8.2  nathanw 
    572  1.28.8.2  nathanw 	c = zs_getc(cs);
    573  1.28.8.2  nathanw 	return (c);
    574  1.28.8.2  nathanw }
    575  1.28.8.2  nathanw 
    576  1.28.8.2  nathanw /*
    577  1.28.8.2  nathanw  * Polled console output putchar.
    578  1.28.8.2  nathanw  */
    579  1.28.8.2  nathanw void
    580  1.28.8.2  nathanw zsc_pcccnputc(dev, c)
    581  1.28.8.2  nathanw 	dev_t dev;
    582  1.28.8.2  nathanw 	int c;
    583  1.28.8.2  nathanw {
    584  1.28.8.2  nathanw 	struct zs_chanstate *cs = zs_conschan;
    585  1.28.8.2  nathanw 
    586  1.28.8.2  nathanw 	zs_putc(cs, c);
    587  1.28.8.2  nathanw }
    588  1.28.8.2  nathanw 
    589  1.28.8.2  nathanw /*
    590  1.28.8.2  nathanw  * Handle user request to enter kernel debugger.
    591  1.28.8.2  nathanw  */
    592  1.28.8.2  nathanw void
    593  1.28.8.2  nathanw zs_abort(cs)
    594  1.28.8.2  nathanw 	struct zs_chanstate *cs;
    595  1.28.8.2  nathanw {
    596  1.28.8.2  nathanw 	int rr0;
    597  1.28.8.2  nathanw 
    598  1.28.8.2  nathanw 	/* Wait for end of break to avoid PROM abort. */
    599  1.28.8.2  nathanw 	/* XXX - Limit the wait? */
    600  1.28.8.2  nathanw 	do {
    601  1.28.8.2  nathanw 		rr0 = *cs->cs_reg_csr;
    602  1.28.8.2  nathanw 		ZS_DELAY();
    603  1.28.8.2  nathanw 	} while (rr0 & ZSRR0_BREAK);
    604  1.28.8.2  nathanw 
    605  1.28.8.2  nathanw 	mvme68k_abort("SERIAL LINE ABORT");
    606  1.28.8.2  nathanw }
    607