Home | History | Annotate | Line # | Download | only in dev
zs.c revision 1.32.2.1
      1  1.32.2.1  wrstuden /*	$NetBSD: zs.c,v 1.32.2.1 2008/06/23 04:30:37 wrstuden Exp $	*/
      2       1.1       dbj 
      3       1.1       dbj /*-
      4       1.1       dbj  * Copyright (c) 1996 The NetBSD Foundation, Inc.
      5       1.1       dbj  * All rights reserved.
      6       1.1       dbj  *
      7       1.1       dbj  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1       dbj  * by Gordon W. Ross.
      9       1.1       dbj  *
     10       1.1       dbj  * Redistribution and use in source and binary forms, with or without
     11       1.1       dbj  * modification, are permitted provided that the following conditions
     12       1.1       dbj  * are met:
     13       1.1       dbj  * 1. Redistributions of source code must retain the above copyright
     14       1.1       dbj  *    notice, this list of conditions and the following disclaimer.
     15       1.1       dbj  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1       dbj  *    notice, this list of conditions and the following disclaimer in the
     17       1.1       dbj  *    documentation and/or other materials provided with the distribution.
     18       1.1       dbj  *
     19       1.1       dbj  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20       1.1       dbj  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.1       dbj  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.1       dbj  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23       1.1       dbj  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.1       dbj  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.1       dbj  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.1       dbj  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.1       dbj  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.1       dbj  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.1       dbj  * POSSIBILITY OF SUCH DAMAGE.
     30       1.1       dbj  */
     31       1.1       dbj 
     32       1.1       dbj /*
     33       1.1       dbj  * Zilog Z8530 Dual UART driver (machine-dependent part)
     34       1.1       dbj  *
     35       1.1       dbj  * Runs two serial lines per chip using slave drivers.
     36       1.1       dbj  * Plain tty/async lines use the zs_async slave.
     37       1.1       dbj  * Sun keyboard/mouse uses the zs_kbd/zs_ms slaves.
     38       1.1       dbj  */
     39       1.1       dbj 
     40       1.1       dbj /* This was snarfed from the netbsd sparc/dev/zs.c at version 1.56
     41       1.1       dbj  * and then updated to reflect changes in 1.59
     42       1.1       dbj  * by Darrin B Jewell <jewell (at) mit.edu>  Mon Mar 30 20:24:46 1998
     43       1.1       dbj  */
     44      1.23     lukem 
     45      1.23     lukem #include <sys/cdefs.h>
     46  1.32.2.1  wrstuden __KERNEL_RCSID(0, "$NetBSD: zs.c,v 1.32.2.1 2008/06/23 04:30:37 wrstuden Exp $");
     47       1.2  jonathan 
     48       1.2  jonathan #include "opt_ddb.h"
     49      1.15     lukem #include "opt_kgdb.h"
     50      1.11       dbj #include "opt_serial.h"
     51       1.1       dbj 
     52       1.1       dbj #include <sys/param.h>
     53       1.1       dbj #include <sys/systm.h>
     54       1.1       dbj #include <sys/conf.h>
     55       1.1       dbj #include <sys/device.h>
     56       1.1       dbj #include <sys/file.h>
     57       1.1       dbj #include <sys/ioctl.h>
     58       1.1       dbj #include <sys/kernel.h>
     59       1.1       dbj #include <sys/proc.h>
     60       1.1       dbj #include <sys/tty.h>
     61       1.1       dbj #include <sys/time.h>
     62       1.1       dbj #include <sys/syslog.h>
     63      1.30        ad #include <sys/intr.h>
     64      1.30        ad #include <sys/cpu.h>
     65       1.1       dbj 
     66       1.1       dbj #include <machine/autoconf.h>
     67       1.1       dbj #include <machine/psl.h>
     68       1.1       dbj 
     69       1.1       dbj #include <dev/cons.h>
     70       1.1       dbj 
     71       1.1       dbj #include <dev/ic/z8530reg.h>
     72       1.1       dbj #include <machine/z8530var.h>
     73       1.1       dbj 
     74       1.1       dbj #include <next68k/next68k/isr.h>
     75      1.17   mycroft 
     76      1.17   mycroft #include <next68k/dev/intiovar.h>
     77      1.10       dbj #include <next68k/dev/zs_cons.h>
     78       1.1       dbj 
     79      1.31   tsutsui #include "ioconf.h"
     80       1.1       dbj #include "zsc.h" 	/* NZSC */
     81       1.1       dbj 
     82       1.1       dbj #if (NZSC < 0)
     83       1.1       dbj #error "No serial controllers?"
     84       1.1       dbj #endif
     85       1.1       dbj 
     86       1.1       dbj /*
     87       1.1       dbj  * Some warts needed by z8530tty.c -
     88       1.1       dbj  * The default parity REALLY needs to be the same as the PROM uses,
     89       1.1       dbj  * or you can not see messages done with printf during boot-up...
     90       1.1       dbj  */
     91       1.1       dbj int zs_def_cflag = (CREAD | CS8 | HUPCL);
     92       1.1       dbj 
     93       1.1       dbj /*
     94       1.1       dbj  * The NeXT provides a 3.686400 MHz clock to the ZS chips.
     95       1.1       dbj  */
     96       1.7   mycroft #define PCLK	(9600 * 384)		/* PCLK pin input clock rate */
     97       1.1       dbj 
     98       1.1       dbj #define	ZS_DELAY()		delay(2)
     99       1.1       dbj 
    100       1.1       dbj /* The layout of this is hardware-dependent (padding, order). */
    101       1.1       dbj struct zschan {
    102      1.31   tsutsui 	volatile uint8_t zc_csr;	/* ctrl,status, and indirect access */
    103      1.31   tsutsui 	uint8_t		zc_xxx0;
    104      1.31   tsutsui 	volatile uint8_t zc_data;	/* data */
    105      1.31   tsutsui 	uint8_t		zc_xxx1;
    106       1.1       dbj };
    107       1.1       dbj 
    108       1.1       dbj /* Flags from cninit() */
    109      1.26       chs static int zs_hwflags[2];
    110       1.1       dbj 
    111       1.1       dbj /* Default speed for each channel */
    112      1.26       chs static int zs_defspeed[2] = {
    113      1.26       chs 	9600,	 	/* ttya */
    114      1.26       chs 	9600,		/* ttyb */
    115       1.1       dbj };
    116       1.1       dbj 
    117      1.31   tsutsui static uint8_t zs_init_reg[16] = {
    118       1.1       dbj 	0,	/* 0: CMD (reset, etc.) */
    119       1.1       dbj 	0,	/* 1: No interrupts yet. */
    120       1.1       dbj 	0x18 + NEXT_I_IPL(NEXT_I_SCC),	/* 2: IVECT */
    121       1.1       dbj 	ZSWR3_RX_8 | ZSWR3_RX_ENABLE,
    122       1.1       dbj 	ZSWR4_CLK_X16 | ZSWR4_ONESB | ZSWR4_EVENP,
    123       1.1       dbj 	ZSWR5_TX_8 | ZSWR5_TX_ENABLE,
    124       1.1       dbj 	0,	/* 6: TXSYNC/SYNCLO */
    125       1.1       dbj 	0,	/* 7: RXSYNC/SYNCHI */
    126       1.1       dbj 	0,	/* 8: alias for data port */
    127       1.1       dbj 	ZSWR9_MASTER_IE,
    128       1.1       dbj 	0,	/*10: Misc. TX/RX control bits */
    129       1.1       dbj 	ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD,
    130       1.7   mycroft 	((PCLK/32)/9600)-2,	/*12: BAUDLO (default=9600) */
    131       1.7   mycroft 	0,			/*13: BAUDHI (default=9600) */
    132       1.1       dbj 	ZSWR14_BAUD_ENA | ZSWR14_BAUD_FROM_PCLK,
    133       1.6   mycroft 	ZSWR15_BREAK_IE,
    134       1.1       dbj };
    135       1.1       dbj 
    136      1.10       dbj struct zschan *
    137      1.26       chs zs_get_chan_addr(int channel)
    138       1.1       dbj {
    139       1.1       dbj 	char *addr;
    140       1.1       dbj 	struct zschan *zc;
    141       1.1       dbj 
    142      1.26       chs 	addr = (void *)IIOV(NEXT_P_SCC);
    143       1.1       dbj 	if (channel == 0) {
    144       1.1       dbj 		/* handle the fact the ports are intertwined. */
    145      1.26       chs 		zc = (struct zschan *)(addr + 1);
    146       1.1       dbj 	} else {
    147       1.1       dbj 		zc = (struct zschan *)(addr);
    148       1.1       dbj 	}
    149       1.1       dbj 	return (zc);
    150       1.1       dbj }
    151       1.1       dbj 
    152       1.1       dbj 
    153       1.1       dbj /****************************************************************
    154       1.1       dbj  * Autoconfig
    155       1.1       dbj  ****************************************************************/
    156       1.1       dbj 
    157       1.1       dbj /* Definition of the driver for autoconfig. */
    158      1.31   tsutsui static int	zs_match(device_t, cfdata_t, void *);
    159      1.31   tsutsui static void	zs_attach(device_t, device_t, void *);
    160      1.24       chs static int	zs_print(void *, const char *);
    161       1.1       dbj 
    162      1.24       chs extern int  zs_getc(void *);
    163      1.24       chs extern void zs_putc(void *, int);
    164       1.1       dbj 
    165      1.31   tsutsui CFATTACH_DECL_NEW(zsc, sizeof(struct zsc_softc),
    166      1.20   thorpej     zs_match, zs_attach, NULL, NULL);
    167       1.1       dbj 
    168      1.26       chs static int zs_attached;
    169      1.26       chs 
    170       1.1       dbj /* Interrupt handlers. */
    171      1.24       chs static int zshard(void *);
    172       1.1       dbj 
    173      1.24       chs static int zs_get_speed(struct zs_chanstate *);
    174       1.1       dbj 
    175       1.1       dbj /*
    176       1.1       dbj  * Is the zs chip present?
    177       1.1       dbj  */
    178       1.1       dbj static int
    179      1.31   tsutsui zs_match(device_t parent, cfdata_t cf, void *aux)
    180       1.1       dbj {
    181      1.31   tsutsui 	struct intio_attach_args *ia = aux;
    182      1.17   mycroft 
    183      1.26       chs 	if (zs_attached)
    184      1.26       chs 		return 0;
    185      1.17   mycroft 
    186      1.26       chs 	ia->ia_addr = (void *)IIOV(NEXT_P_SCC);
    187      1.17   mycroft 
    188      1.26       chs 	return 1;
    189       1.1       dbj }
    190       1.1       dbj 
    191       1.1       dbj /*
    192       1.1       dbj  * Attach a found zs.
    193       1.1       dbj  *
    194       1.1       dbj  * USE ROM PROPERTIES port-a-ignore-cd AND port-b-ignore-cd FOR
    195       1.1       dbj  * SOFT CARRIER, AND keyboard PROPERTY FOR KEYBOARD/MOUSE?
    196       1.1       dbj  */
    197       1.1       dbj static void
    198      1.31   tsutsui zs_attach(device_t parent, device_t self, void *aux)
    199       1.1       dbj {
    200      1.31   tsutsui 	struct zsc_softc *zsc = device_private(self);
    201       1.1       dbj 	struct zsc_attach_args zsc_args;
    202       1.1       dbj 	volatile struct zschan *zc;
    203       1.1       dbj 	struct zs_chanstate *cs;
    204      1.28   tsutsui 	int s, channel;
    205      1.26       chs 
    206      1.26       chs 	zs_attached = 1;
    207       1.1       dbj 
    208      1.31   tsutsui 	zsc->zsc_dev = self;
    209      1.31   tsutsui 	aprint_normal("\n");
    210       1.5       dbj 
    211       1.1       dbj 	/*
    212       1.1       dbj 	 * Initialize software state for each channel.
    213       1.1       dbj 	 */
    214       1.1       dbj 	for (channel = 0; channel < 2; channel++) {
    215       1.1       dbj 		zsc_args.channel = channel;
    216      1.26       chs 		zsc_args.hwflags = zs_hwflags[channel];
    217       1.1       dbj 		cs = &zsc->zsc_cs_store[channel];
    218       1.1       dbj 		zsc->zsc_cs[channel] = cs;
    219       1.1       dbj 
    220      1.29        ad 		zs_lock_init(cs);
    221       1.1       dbj 		cs->cs_channel = channel;
    222       1.1       dbj 		cs->cs_private = NULL;
    223       1.1       dbj 		cs->cs_ops = &zsops_null;
    224       1.1       dbj 		cs->cs_brg_clk = PCLK / 16;
    225       1.1       dbj 
    226      1.26       chs 		zc = zs_get_chan_addr(channel);
    227       1.1       dbj 		cs->cs_reg_csr  = &zc->zc_csr;
    228       1.1       dbj 		cs->cs_reg_data = &zc->zc_data;
    229       1.1       dbj 
    230      1.26       chs 		memcpy(cs->cs_creg, zs_init_reg, 16);
    231      1.26       chs 		memcpy(cs->cs_preg, zs_init_reg, 16);
    232       1.1       dbj 
    233       1.1       dbj 		/* XXX: Get these from the PROM properties! */
    234       1.1       dbj 		/* XXX: See the mvme167 code.  Better. */
    235       1.1       dbj 		if (zsc_args.hwflags & ZS_HWFLAG_CONSOLE)
    236       1.1       dbj 			cs->cs_defspeed = zs_get_speed(cs);
    237       1.1       dbj 		else
    238      1.26       chs 			cs->cs_defspeed = zs_defspeed[channel];
    239       1.1       dbj 		cs->cs_defcflag = zs_def_cflag;
    240       1.1       dbj 
    241       1.1       dbj 		/* Make these correspond to cs_defcflag (-crtscts) */
    242       1.1       dbj 		cs->cs_rr0_dcd = ZSRR0_DCD;
    243       1.1       dbj 		cs->cs_rr0_cts = 0;
    244       1.1       dbj 		cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
    245       1.1       dbj 		cs->cs_wr5_rts = 0;
    246       1.1       dbj 
    247       1.1       dbj 		/*
    248       1.1       dbj 		 * Clear the master interrupt enable.
    249       1.1       dbj 		 * The INTENA is common to both channels,
    250       1.1       dbj 		 * so just do it on the A channel.
    251       1.1       dbj 		 */
    252       1.1       dbj 		if (channel == 0) {
    253       1.1       dbj 			zs_write_reg(cs, 9, 0);
    254       1.1       dbj 		}
    255       1.1       dbj 
    256       1.1       dbj 		/*
    257       1.1       dbj 		 * Look for a child driver for this channel.
    258       1.1       dbj 		 * The child attach will setup the hardware.
    259       1.1       dbj 		 */
    260       1.1       dbj 		if (!config_found(self, (void *)&zsc_args, zs_print)) {
    261       1.1       dbj 			/* No sub-driver.  Just reset it. */
    262      1.31   tsutsui 			uint8_t reset = (channel == 0) ?
    263       1.1       dbj 				ZSWR9_A_RESET : ZSWR9_B_RESET;
    264       1.1       dbj 			s = splzs();
    265       1.1       dbj 			zs_write_reg(cs,  9, reset);
    266       1.1       dbj 			splx(s);
    267       1.1       dbj 		}
    268       1.1       dbj 	}
    269       1.1       dbj 
    270      1.17   mycroft 	isrlink_autovec(zshard, NULL, NEXT_I_IPL(NEXT_I_SCC), 0, NULL);
    271      1.30        ad 	zsc->zsc_softintr_cookie = softint_establish(SOFTINT_SERIAL,
    272      1.28   tsutsui 	    (void (*)(void *))zsc_intr_soft, zsc);
    273       1.1       dbj 	INTR_ENABLE(NEXT_I_SCC);
    274       1.1       dbj 
    275       1.1       dbj 	/*
    276       1.1       dbj 	 * Set the master interrupt enable and interrupt vector.
    277       1.1       dbj 	 * (common to both channels, do it on A)
    278       1.1       dbj 	 */
    279       1.1       dbj 	cs = zsc->zsc_cs[0];
    280       1.1       dbj 	s = splhigh();
    281       1.1       dbj 	/* interrupt vector */
    282       1.1       dbj 	zs_write_reg(cs, 2, zs_init_reg[2]);
    283       1.1       dbj 	/* master interrupt control (enable) */
    284       1.1       dbj 	zs_write_reg(cs, 9, zs_init_reg[9]);
    285       1.1       dbj 	splx(s);
    286       1.1       dbj }
    287       1.1       dbj 
    288       1.1       dbj static int
    289      1.24       chs zs_print(void *aux, const char *name)
    290       1.1       dbj {
    291       1.1       dbj 	struct zsc_attach_args *args = aux;
    292       1.1       dbj 
    293       1.1       dbj 	if (name != NULL)
    294      1.21   thorpej 		aprint_normal("%s: ", name);
    295       1.1       dbj 
    296       1.1       dbj 	if (args->channel != -1)
    297      1.21   thorpej 		aprint_normal(" channel %d", args->channel);
    298       1.1       dbj 
    299       1.1       dbj 	return (UNCONF);
    300       1.1       dbj }
    301       1.1       dbj 
    302       1.1       dbj static volatile int zssoftpending;
    303       1.1       dbj 
    304       1.1       dbj /*
    305       1.1       dbj  * Our ZS chips all share a common, autovectored interrupt,
    306       1.1       dbj  * so we have to look at all of them on each interrupt.
    307       1.1       dbj  */
    308       1.1       dbj static int
    309      1.24       chs zshard(void *arg)
    310       1.1       dbj {
    311      1.25       chs 	struct zsc_softc *zsc;
    312      1.28   tsutsui 	int unit, rr3, rval;
    313      1.24       chs 
    314      1.24       chs 	if (!INTR_OCCURRED(NEXT_I_SCC))
    315      1.24       chs 		return 0;
    316       1.1       dbj 
    317      1.28   tsutsui 	rval = 0;
    318       1.1       dbj 	for (unit = 0; unit < zsc_cd.cd_ndevs; unit++) {
    319  1.32.2.1  wrstuden 		zsc = device_lookup_private(&zsc_cd, unit);
    320       1.1       dbj 		if (zsc == NULL)
    321       1.1       dbj 			continue;
    322       1.1       dbj 		rr3 = zsc_intr_hard(zsc);
    323       1.1       dbj 		/* Count up the interrupts. */
    324       1.1       dbj 		if (rr3) {
    325       1.1       dbj 			rval |= rr3;
    326       1.1       dbj 			zsc->zsc_intrcnt.ev_count++;
    327       1.1       dbj 		}
    328      1.28   tsutsui 		/* We are at splzs here, so no need to lock. */
    329      1.28   tsutsui 		if (zsc->zsc_cs[0]->cs_softreq || zsc->zsc_cs[1]->cs_softreq)
    330      1.30        ad 			softint_schedule(zsc->zsc_softintr_cookie);
    331       1.1       dbj 	}
    332       1.1       dbj 
    333       1.1       dbj 	return(1);
    334       1.1       dbj }
    335       1.1       dbj 
    336       1.1       dbj /*
    337       1.1       dbj  * Compute the current baud rate given a ZS channel.
    338       1.1       dbj  */
    339       1.1       dbj static int
    340      1.24       chs zs_get_speed(struct zs_chanstate *cs)
    341       1.1       dbj {
    342       1.1       dbj 	int tconst;
    343       1.1       dbj 
    344       1.1       dbj 	tconst = zs_read_reg(cs, 12);
    345       1.1       dbj 	tconst |= zs_read_reg(cs, 13) << 8;
    346       1.1       dbj 	return (TCONST_TO_BPS(cs->cs_brg_clk, tconst));
    347       1.1       dbj }
    348       1.1       dbj 
    349       1.1       dbj /*
    350       1.1       dbj  * MD functions for setting the baud rate and control modes.
    351       1.1       dbj  */
    352       1.1       dbj int
    353      1.24       chs zs_set_speed(struct zs_chanstate *cs, int bps)
    354       1.1       dbj {
    355       1.1       dbj 	int tconst, real_bps;
    356       1.1       dbj 
    357       1.1       dbj 	if (bps == 0)
    358       1.1       dbj 		return (0);
    359       1.1       dbj 
    360       1.1       dbj #ifdef	DIAGNOSTIC
    361       1.1       dbj 	if (cs->cs_brg_clk == 0)
    362       1.1       dbj 		panic("zs_set_speed");
    363       1.1       dbj #endif
    364       1.1       dbj 
    365       1.1       dbj 	tconst = BPS_TO_TCONST(cs->cs_brg_clk, bps);
    366       1.1       dbj 	if (tconst < 0)
    367       1.1       dbj 		return (EINVAL);
    368       1.1       dbj 
    369       1.1       dbj 	/* Convert back to make sure we can do it. */
    370       1.1       dbj 	real_bps = TCONST_TO_BPS(cs->cs_brg_clk, tconst);
    371       1.1       dbj 
    372       1.1       dbj 	/* XXX - Allow some tolerance here? */
    373       1.1       dbj 	if (real_bps != bps)
    374       1.1       dbj 		return (EINVAL);
    375       1.1       dbj 
    376       1.1       dbj 	cs->cs_preg[12] = tconst;
    377       1.1       dbj 	cs->cs_preg[13] = tconst >> 8;
    378       1.1       dbj 
    379       1.1       dbj 	/* Caller will stuff the pending registers. */
    380       1.1       dbj 	return (0);
    381       1.1       dbj }
    382       1.1       dbj 
    383       1.1       dbj int
    384      1.24       chs zs_set_modes(struct zs_chanstate *cs, int cflag)
    385       1.1       dbj {
    386       1.1       dbj 	int s;
    387       1.1       dbj 
    388       1.1       dbj 	/*
    389       1.1       dbj 	 * Output hardware flow control on the chip is horrendous:
    390       1.1       dbj 	 * if carrier detect drops, the receiver is disabled, and if
    391       1.1       dbj 	 * CTS drops, the transmitter is stoped IN MID CHARACTER!
    392       1.1       dbj 	 * Therefore, NEVER set the HFC bit, and instead use the
    393       1.1       dbj 	 * status interrupt to detect CTS changes.
    394       1.1       dbj 	 */
    395       1.1       dbj 	s = splzs();
    396       1.9  wrstuden 	cs->cs_rr0_pps = 0;
    397       1.9  wrstuden 	if ((cflag & (CLOCAL | MDMBUF)) != 0) {
    398       1.1       dbj 		cs->cs_rr0_dcd = 0;
    399       1.9  wrstuden 		if ((cflag & MDMBUF) == 0)
    400       1.9  wrstuden 			cs->cs_rr0_pps = ZSRR0_DCD;
    401       1.9  wrstuden 	} else
    402       1.1       dbj 		cs->cs_rr0_dcd = ZSRR0_DCD;
    403       1.1       dbj 	if ((cflag & CRTSCTS) != 0) {
    404       1.1       dbj 		cs->cs_wr5_dtr = ZSWR5_DTR;
    405       1.1       dbj 		cs->cs_wr5_rts = ZSWR5_RTS;
    406       1.1       dbj 		cs->cs_rr0_cts = ZSRR0_CTS;
    407       1.1       dbj 	} else if ((cflag & CDTRCTS) != 0) {
    408       1.1       dbj 		cs->cs_wr5_dtr = 0;
    409       1.1       dbj 		cs->cs_wr5_rts = ZSWR5_DTR;
    410       1.1       dbj 		cs->cs_rr0_cts = ZSRR0_CTS;
    411       1.1       dbj 	} else if ((cflag & MDMBUF) != 0) {
    412       1.1       dbj 		cs->cs_wr5_dtr = 0;
    413       1.1       dbj 		cs->cs_wr5_rts = ZSWR5_DTR;
    414       1.1       dbj 		cs->cs_rr0_cts = ZSRR0_DCD;
    415       1.1       dbj 	} else {
    416       1.1       dbj 		cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
    417       1.1       dbj 		cs->cs_wr5_rts = 0;
    418       1.1       dbj 		cs->cs_rr0_cts = 0;
    419       1.1       dbj 	}
    420       1.1       dbj 	splx(s);
    421       1.1       dbj 
    422       1.1       dbj 	/* Caller will stuff the pending registers. */
    423       1.1       dbj 	return (0);
    424       1.1       dbj }
    425       1.1       dbj 
    426       1.1       dbj /*
    427       1.1       dbj  * Read or write the chip with suitable delays.
    428       1.1       dbj  */
    429       1.1       dbj 
    430      1.31   tsutsui uint8_t
    431      1.31   tsutsui zs_read_reg(struct zs_chanstate *cs, uint8_t reg)
    432       1.1       dbj {
    433      1.31   tsutsui 	uint8_t val;
    434       1.1       dbj 
    435       1.1       dbj 	*cs->cs_reg_csr = reg;
    436       1.1       dbj 	ZS_DELAY();
    437       1.1       dbj 	val = *cs->cs_reg_csr;
    438       1.1       dbj 	ZS_DELAY();
    439       1.1       dbj 	return (val);
    440       1.1       dbj }
    441       1.1       dbj 
    442       1.1       dbj void
    443      1.31   tsutsui zs_write_reg(struct zs_chanstate *cs, uint8_t reg, uint8_t val)
    444       1.1       dbj {
    445       1.1       dbj 	*cs->cs_reg_csr = reg;
    446       1.1       dbj 	ZS_DELAY();
    447       1.1       dbj 	*cs->cs_reg_csr = val;
    448       1.1       dbj 	ZS_DELAY();
    449       1.1       dbj }
    450       1.1       dbj 
    451      1.31   tsutsui uint8_t
    452      1.24       chs zs_read_csr(struct zs_chanstate *cs)
    453       1.1       dbj {
    454      1.31   tsutsui 	uint8_t val;
    455       1.1       dbj 
    456       1.1       dbj 	val = *cs->cs_reg_csr;
    457       1.1       dbj 	ZS_DELAY();
    458       1.1       dbj 	return (val);
    459       1.1       dbj }
    460       1.1       dbj 
    461      1.24       chs void
    462      1.31   tsutsui zs_write_csr(struct zs_chanstate *cs, uint8_t val)
    463       1.1       dbj {
    464       1.1       dbj 	*cs->cs_reg_csr = val;
    465       1.1       dbj 	ZS_DELAY();
    466       1.1       dbj }
    467       1.1       dbj 
    468      1.31   tsutsui uint8_t
    469      1.24       chs zs_read_data(struct zs_chanstate *cs)
    470       1.1       dbj {
    471      1.31   tsutsui 	uint8_t val;
    472       1.1       dbj 
    473       1.1       dbj 	val = *cs->cs_reg_data;
    474       1.1       dbj 	ZS_DELAY();
    475       1.1       dbj 	return (val);
    476       1.1       dbj }
    477       1.1       dbj 
    478      1.24       chs void
    479      1.31   tsutsui zs_write_data(struct zs_chanstate *cs, uint8_t val)
    480       1.1       dbj {
    481       1.1       dbj 	*cs->cs_reg_data = val;
    482       1.1       dbj 	ZS_DELAY();
    483       1.1       dbj }
    484       1.1       dbj 
    485       1.1       dbj /****************************************************************
    486       1.1       dbj  * Console support functions (Sun specific!)
    487       1.1       dbj  * Note: this code is allowed to know about the layout of
    488       1.1       dbj  * the chip registers, and uses that to keep things simple.
    489       1.1       dbj  * XXX - I think I like the mvme167 code better. -gwr
    490       1.1       dbj  ****************************************************************/
    491       1.1       dbj 
    492      1.24       chs extern void Debugger(void);
    493       1.1       dbj void *zs_conschan;
    494       1.1       dbj int	zs_consunit = 0;
    495       1.1       dbj 
    496       1.1       dbj /*
    497       1.1       dbj  * Handle user request to enter kernel debugger.
    498       1.1       dbj  */
    499       1.1       dbj void
    500      1.24       chs zs_abort(struct zs_chanstate *cs)
    501       1.1       dbj {
    502      1.10       dbj #if defined(ZS_CONSOLE_ABORT)
    503      1.25       chs 	volatile struct zschan *zc = zs_conschan;
    504       1.1       dbj 	int rr0;
    505       1.1       dbj 
    506       1.1       dbj 	/* Wait for end of break to avoid PROM abort. */
    507       1.1       dbj 	/* XXX - Limit the wait? */
    508       1.1       dbj 	do {
    509       1.1       dbj 		rr0 = zc->zc_csr;
    510       1.1       dbj 		ZS_DELAY();
    511       1.1       dbj 	} while (rr0 & ZSRR0_BREAK);
    512       1.1       dbj 
    513       1.1       dbj #if defined(KGDB)
    514       1.1       dbj 	zskgdb(cs);
    515       1.1       dbj #elif defined(DDB)
    516       1.1       dbj 	Debugger();
    517       1.1       dbj #else
    518      1.12    deberg 	/* XXX eventually, drop into next rom monitor here */
    519      1.12    deberg 	printf("stopping on keyboard abort not supported without DDB or KGDB\n");
    520      1.10       dbj #endif
    521      1.10       dbj #else /* !ZS_CONSOLE_ABORT */
    522      1.10       dbj 	return;
    523       1.1       dbj #endif
    524       1.1       dbj }
    525       1.1       dbj 
    526       1.1       dbj /*
    527       1.1       dbj  * Polled input char.
    528       1.1       dbj  */
    529       1.1       dbj int
    530      1.24       chs zs_getc(void *arg)
    531       1.1       dbj {
    532      1.25       chs 	volatile struct zschan *zc = arg;
    533      1.25       chs 	int s, c, rr0;
    534       1.1       dbj 
    535       1.1       dbj 	s = splhigh();
    536       1.1       dbj 	/* Wait for a character to arrive. */
    537       1.1       dbj 	do {
    538       1.1       dbj 		rr0 = zc->zc_csr;
    539       1.1       dbj 		ZS_DELAY();
    540       1.1       dbj 	} while ((rr0 & ZSRR0_RX_READY) == 0);
    541       1.1       dbj 
    542       1.1       dbj 	c = zc->zc_data;
    543       1.1       dbj 	ZS_DELAY();
    544       1.1       dbj 	splx(s);
    545       1.1       dbj 
    546       1.1       dbj 	/*
    547       1.1       dbj 	 * This is used by the kd driver to read scan codes,
    548       1.1       dbj 	 * so don't translate '\r' ==> '\n' here...
    549       1.1       dbj 	 */
    550       1.1       dbj 	return (c);
    551       1.1       dbj }
    552       1.1       dbj 
    553       1.1       dbj /*
    554       1.1       dbj  * Polled output char.
    555       1.1       dbj  */
    556       1.1       dbj void
    557      1.24       chs zs_putc(void *arg, int c)
    558       1.1       dbj {
    559      1.25       chs 	volatile struct zschan *zc = arg;
    560      1.25       chs 	int s, rr0;
    561       1.1       dbj 
    562       1.1       dbj 	s = splhigh();
    563       1.1       dbj 	/* Wait for transmitter to become ready. */
    564       1.1       dbj 	do {
    565       1.1       dbj 		rr0 = zc->zc_csr;
    566       1.1       dbj 		ZS_DELAY();
    567       1.1       dbj 	} while ((rr0 & ZSRR0_TX_READY) == 0);
    568       1.1       dbj 
    569       1.1       dbj 
    570       1.1       dbj 	zc->zc_data = c;
    571       1.1       dbj 	ZS_DELAY();
    572       1.1       dbj 
    573       1.1       dbj 	splx(s);
    574       1.1       dbj }
    575       1.1       dbj 
    576       1.1       dbj /*****************************************************************/
    577       1.1       dbj 
    578      1.24       chs void zscninit(struct consdev *);
    579      1.24       chs int  zscngetc(dev_t);
    580      1.24       chs void zscnputc(dev_t, int);
    581      1.24       chs void zscnprobe(struct consdev *);
    582       1.1       dbj 
    583       1.1       dbj void
    584      1.24       chs zscnprobe(struct consdev *cp)
    585       1.1       dbj {
    586      1.24       chs 	extern const struct cdevsw zstty_cdevsw;
    587      1.24       chs 	int     maj;
    588      1.24       chs 
    589      1.24       chs 	maj = cdevsw_lookup_major(&zstty_cdevsw);
    590      1.24       chs 	if (maj != -1) {
    591       1.8       dbj #ifdef SERCONSOLE
    592      1.24       chs 		cp->cn_pri = CN_REMOTE;
    593       1.8       dbj #else
    594      1.24       chs 		cp->cn_pri = CN_NORMAL;		 /* Lower than CN_INTERNAL */
    595       1.8       dbj #endif
    596      1.24       chs 		zs_consunit = 0;
    597      1.24       chs 		cp->cn_dev = makedev(maj, zs_consunit);
    598      1.26       chs 		zs_conschan = zs_get_chan_addr(zs_consunit);
    599      1.24       chs 	} else {
    600      1.24       chs 		cp->cn_pri = CN_DEAD;
    601      1.24       chs 	}
    602       1.1       dbj }
    603       1.1       dbj 
    604       1.1       dbj void
    605      1.24       chs zscninit(struct consdev *cn)
    606       1.1       dbj {
    607      1.24       chs 	struct zs_chanstate xcs;
    608      1.24       chs 	struct zs_chanstate *cs;
    609      1.24       chs 	volatile struct zschan *zc;
    610      1.24       chs 	int tconst, s;
    611      1.24       chs 
    612      1.26       chs 	zs_hwflags[zs_consunit] = ZS_HWFLAG_CONSOLE;
    613       1.1       dbj 
    614      1.24       chs 	/* Setup temporary chanstate. */
    615      1.24       chs 	memset(&xcs, 0, sizeof(xcs));
    616      1.24       chs 	cs = &xcs;
    617      1.24       chs 	zc = zs_conschan;
    618      1.24       chs 	cs->cs_reg_csr  = &zc->zc_csr;
    619      1.24       chs 	cs->cs_reg_data = &zc->zc_data;
    620      1.24       chs 	cs->cs_channel = zs_consunit;
    621      1.24       chs 	cs->cs_brg_clk = PCLK / 16;
    622      1.24       chs 
    623      1.24       chs 	memcpy(cs->cs_preg, zs_init_reg, 16);
    624      1.24       chs 	cs->cs_preg[5] |= ZSWR5_DTR | ZSWR5_RTS;
    625      1.24       chs 	cs->cs_preg[15] = ZSWR15_BREAK_IE;
    626       1.1       dbj 
    627      1.26       chs 	tconst = BPS_TO_TCONST(cs->cs_brg_clk, zs_defspeed[zs_consunit]);
    628      1.24       chs 	cs->cs_preg[12] = tconst;
    629      1.24       chs 	cs->cs_preg[13] = tconst >> 8;
    630       1.1       dbj 
    631      1.24       chs 	/*
    632      1.24       chs 	 * can't use zs_set_speed as we haven't set up the
    633      1.24       chs 	 * signal sources, and it's not worth it for now
    634      1.24       chs 	 */
    635       1.1       dbj 
    636      1.24       chs 	cs->cs_preg[9] &= ~ZSWR9_MASTER_IE;
    637      1.24       chs 	/* no interrupts until later, after attach. */
    638       1.1       dbj 
    639      1.24       chs 	s = splhigh();
    640      1.24       chs 	zs_loadchannelregs(cs);
    641      1.24       chs 	splx(s);
    642       1.1       dbj 
    643       1.1       dbj 	printf("\nNetBSD/next68k console\n");
    644       1.1       dbj }
    645       1.1       dbj 
    646       1.1       dbj /*
    647       1.1       dbj  * Polled console input putchar.
    648       1.1       dbj  */
    649       1.1       dbj int
    650      1.24       chs zscngetc(dev_t dev)
    651       1.1       dbj {
    652       1.1       dbj 	return (zs_getc(zs_conschan));
    653       1.1       dbj }
    654       1.1       dbj 
    655       1.1       dbj /*
    656       1.1       dbj  * Polled console output putchar.
    657       1.1       dbj  */
    658       1.1       dbj void
    659      1.24       chs zscnputc(dev_t dev, int c)
    660       1.1       dbj {
    661       1.1       dbj 	zs_putc(zs_conschan, c);
    662       1.1       dbj }
    663       1.1       dbj 
    664       1.1       dbj /*****************************************************************/
    665