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