Home | History | Annotate | Line # | Download | only in dev
zs.c revision 1.14
      1  1.14   mycroft /*	$NetBSD: zs.c,v 1.14 1999/02/11 15:28:06 mycroft Exp $	*/
      2   1.1       oki 
      3  1.12   minoura /*-
      4  1.12   minoura  * Copyright (c) 1998 Minoura Makoto
      5  1.12   minoura  * Copyright (c) 1996 The NetBSD Foundation, Inc.
      6  1.12   minoura  * All rights reserved.
      7   1.1       oki  *
      8  1.12   minoura  * This code is derived from software contributed to The NetBSD Foundation
      9  1.12   minoura  * by Gordon W. Ross.
     10   1.1       oki  *
     11   1.1       oki  * Redistribution and use in source and binary forms, with or without
     12   1.1       oki  * modification, are permitted provided that the following conditions
     13   1.1       oki  * are met:
     14   1.1       oki  * 1. Redistributions of source code must retain the above copyright
     15   1.1       oki  *    notice, this list of conditions and the following disclaimer.
     16   1.1       oki  * 2. Redistributions in binary form must reproduce the above copyright
     17   1.1       oki  *    notice, this list of conditions and the following disclaimer in the
     18   1.1       oki  *    documentation and/or other materials provided with the distribution.
     19   1.1       oki  * 3. All advertising materials mentioning features or use of this software
     20   1.1       oki  *    must display the following acknowledgement:
     21  1.12   minoura  *        This product includes software developed by the NetBSD
     22  1.12   minoura  *        Foundation, Inc. and its contributors.
     23  1.12   minoura  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  1.12   minoura  *    contributors may be used to endorse or promote products derived
     25  1.12   minoura  *    from this software without specific prior written permission.
     26  1.12   minoura  *
     27  1.12   minoura  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  1.12   minoura  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  1.12   minoura  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  1.12   minoura  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  1.12   minoura  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  1.12   minoura  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  1.12   minoura  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  1.12   minoura  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  1.12   minoura  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  1.12   minoura  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  1.12   minoura  * POSSIBILITY OF SUCH DAMAGE.
     38   1.1       oki  */
     39   1.1       oki 
     40   1.1       oki /*
     41  1.12   minoura  * Zilog Z8530 Dual UART driver (machine-dependent part)
     42  1.12   minoura  *
     43  1.12   minoura  * X68k uses one Z8530 built-in. Channel A is for RS-232C serial port;
     44  1.12   minoura  * while channel B is dedicated to the mouse.
     45  1.12   minoura  * Extra Z8530's can be installed.  This driver supports up to 5 chips
     46  1.12   minoura  * including the built-in one.
     47   1.1       oki  */
     48  1.10  jonathan 
     49   1.1       oki #include <sys/param.h>
     50   1.1       oki #include <sys/systm.h>
     51  1.12   minoura #include <sys/conf.h>
     52   1.1       oki #include <sys/device.h>
     53   1.1       oki #include <sys/file.h>
     54   1.1       oki #include <sys/ioctl.h>
     55  1.12   minoura #include <sys/kernel.h>
     56  1.12   minoura #include <sys/proc.h>
     57   1.1       oki #include <sys/tty.h>
     58   1.1       oki #include <sys/time.h>
     59   1.1       oki #include <sys/syslog.h>
     60   1.1       oki 
     61   1.1       oki #include <machine/cpu.h>
     62  1.12   minoura #include <machine/z8530var.h>
     63  1.12   minoura /*#include <arch/x68k/x68k/iodevice.h>*/
     64   1.1       oki 
     65   1.1       oki #include <dev/ic/z8530reg.h>
     66   1.1       oki 
     67  1.12   minoura #include "zsc.h"	/* NZSC */
     68  1.12   minoura #include "zstty.h"
     69   1.1       oki 
     70  1.12   minoura /* Make life easier for the initialized arrays here. */
     71   1.1       oki 
     72  1.12   minoura extern void Debugger __P((void));
     73   1.1       oki 
     74  1.12   minoura /*
     75  1.12   minoura  * Some warts needed by z8530tty.c -
     76  1.12   minoura  * The default parity REALLY needs to be the same as the PROM uses,
     77  1.12   minoura  * or you can not see messages done with printf during boot-up...
     78  1.12   minoura  */
     79  1.12   minoura int zs_def_cflag = (CREAD | CS8 | HUPCL);
     80  1.12   minoura int zs_major = 12;
     81  1.12   minoura 
     82  1.12   minoura /*
     83  1.12   minoura  * X68k provides a 5.0 MHz clock to the ZS chips.
     84  1.12   minoura  * XXX: use 4.9152MHz constant for now!!!
     85  1.12   minoura  */
     86  1.12   minoura #define PCLK	(9600 * 512)	/* PCLK pin input clock rate */
     87  1.12   minoura 
     88  1.12   minoura static u_char zs_init_reg[16] = {
     89  1.12   minoura 	0,	/* 0: CMD (reset, etc.) */
     90  1.12   minoura 	0,	/* 1: No interrupts yet. */
     91  1.12   minoura 	0x70,	/* 2: XXX: IVECT */
     92  1.12   minoura 	ZSWR3_RX_8 | ZSWR3_RX_ENABLE,
     93  1.12   minoura 	ZSWR4_CLK_X16 | ZSWR4_ONESB | ZSWR4_EVENP,
     94  1.12   minoura 	ZSWR5_TX_8 | ZSWR5_TX_ENABLE,
     95  1.12   minoura 	0,	/* 6: TXSYNC/SYNCLO */
     96  1.12   minoura 	0,	/* 7: RXSYNC/SYNCHI */
     97  1.12   minoura 	0,	/* 8: alias for data port */
     98  1.12   minoura 	ZSWR9_MASTER_IE,
     99  1.12   minoura 	ZSWR10_NRZ,	/*10: Misc. TX/RX control bits */
    100  1.12   minoura 	ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD,
    101  1.14   mycroft 	((PCLK/32)/9600)-2,	/*12: BAUDLO (default=9600) */
    102  1.14   mycroft 	0,			/*13: BAUDHI (default=9600) */
    103  1.12   minoura 	ZSWR14_BAUD_ENA | ZSWR14_BAUD_FROM_PCLK,
    104  1.13   mycroft 	ZSWR15_BREAK_IE,
    105  1.12   minoura };
    106   1.1       oki 
    107  1.12   minoura static volatile struct zschan *conschan = 0;
    108   1.1       oki 
    109   1.1       oki 
    110  1.12   minoura /****************************************************************
    111  1.12   minoura  * Autoconfig
    112  1.12   minoura  ****************************************************************/
    113   1.1       oki 
    114   1.1       oki /* Definition of the driver for autoconfig. */
    115  1.12   minoura static int	zs_match __P((struct device *, struct cfdata *, void *));
    116  1.12   minoura static void	zs_attach __P((struct device *, struct device *, void *));
    117  1.12   minoura static int  zs_print __P((void *, const char *name));
    118   1.1       oki 
    119  1.12   minoura struct cfattach zsc_ca = {
    120  1.12   minoura 	sizeof(struct zsc_softc), zs_match, zs_attach
    121   1.1       oki };
    122   1.1       oki 
    123  1.12   minoura extern struct cfdriver zsc_cd;
    124   1.1       oki 
    125  1.12   minoura static volatile struct zsdevice *findzs(int);
    126  1.12   minoura int zshard __P((void));
    127  1.12   minoura int zssoft __P((void *));
    128  1.12   minoura static int zs_get_speed __P((struct zs_chanstate *));
    129   1.1       oki 
    130   1.1       oki 
    131   1.1       oki /*
    132   1.1       oki  * find zs address for x68k architecture
    133   1.1       oki  */
    134   1.1       oki static volatile struct zsdevice *
    135   1.1       oki findzs(zs)
    136   1.1       oki 	int zs;
    137   1.1       oki {
    138   1.1       oki 	if (zs == 0)
    139   1.1       oki 		return &IODEVbase->io_inscc;
    140   1.1       oki 	if (1 <= zs && zs <= 4)
    141   1.1       oki 		return &(IODEVbase->io_exscc)[zs - 1];
    142   1.1       oki 	/* none */
    143   1.1       oki 	return 0;
    144   1.1       oki }
    145   1.1       oki 
    146   1.1       oki /*
    147  1.12   minoura  * Is the zs chip present?
    148   1.1       oki  */
    149   1.1       oki static int
    150  1.12   minoura zs_match(parent, cfp, aux)
    151   1.1       oki 	struct device *parent;
    152  1.11   minoura 	struct cfdata *cfp;
    153  1.11   minoura 	void *aux;
    154   1.1       oki {
    155   1.1       oki 	volatile void *addr;
    156   1.1       oki 
    157   1.1       oki 	if(strcmp("zs", aux) || (addr = findzs(cfp->cf_unit)) == 0)
    158   1.1       oki 		return(0);
    159   1.1       oki 	if (badaddr(addr))
    160   1.1       oki 		return 0;
    161   1.1       oki 	return(1);
    162   1.1       oki }
    163   1.1       oki 
    164   1.1       oki /*
    165   1.1       oki  * Attach a found zs.
    166   1.1       oki  */
    167   1.1       oki static void
    168  1.12   minoura zs_attach(parent, self, aux)
    169   1.1       oki 	struct device *parent;
    170  1.12   minoura 	struct device *self;
    171   1.1       oki 	void *aux;
    172   1.1       oki {
    173  1.12   minoura 	struct zsc_softc *zsc = (void *) self;
    174  1.12   minoura 	struct zsc_attach_args zsc_args;
    175   1.1       oki 	volatile struct zschan *zc;
    176   1.1       oki 	struct zs_chanstate *cs;
    177  1.12   minoura 	int s, zs_unit, channel;
    178   1.1       oki 
    179  1.12   minoura 	zs_unit = zsc->zsc_dev.dv_unit;
    180  1.12   minoura 	zsc->zsc_addr = (void*) findzs (zs_unit);
    181   1.1       oki 
    182  1.12   minoura 	printf("\n");
    183   1.1       oki 
    184   1.1       oki 	/*
    185  1.12   minoura 	 * Initialize software state for each channel.
    186   1.1       oki 	 */
    187  1.12   minoura 	for (channel = 0; channel < 2; channel++) {
    188  1.12   minoura 		struct device *child;
    189   1.1       oki 
    190  1.12   minoura 		zsc_args.channel = channel;
    191  1.12   minoura 		zsc_args.hwflags = 0;
    192  1.12   minoura 		cs = &zsc->zsc_cs_store[channel];
    193  1.12   minoura 		zsc->zsc_cs[channel] = cs;
    194  1.12   minoura 
    195  1.12   minoura 		cs->cs_channel = channel;
    196  1.12   minoura 		cs->cs_private = NULL;
    197  1.12   minoura 		cs->cs_ops = &zsops_null;
    198  1.12   minoura 		cs->cs_brg_clk = PCLK / 16;
    199  1.12   minoura 
    200  1.12   minoura 		if (channel == 0)
    201  1.12   minoura 			zc = (void*) &zsc->zsc_addr->zs_chan_a;
    202  1.12   minoura 		else
    203  1.12   minoura 			zc = (void*) &zsc->zsc_addr->zs_chan_b;
    204  1.12   minoura 		cs->cs_reg_csr  = &zc->zc_csr;
    205  1.12   minoura 		cs->cs_reg_data = &zc->zc_data;
    206  1.12   minoura 
    207  1.12   minoura 		zs_init_reg[2] = 0x70 + zs_unit;
    208  1.12   minoura 		bcopy(zs_init_reg, cs->cs_creg, 16);
    209  1.12   minoura 		bcopy(zs_init_reg, cs->cs_preg, 16);
    210  1.12   minoura 
    211  1.12   minoura 		cs->cs_defspeed = 9600;
    212  1.12   minoura 		cs->cs_defcflag = zs_def_cflag;
    213  1.12   minoura 
    214  1.12   minoura 		/* Make these correspond to cs_defcflag (-crtscts) */
    215  1.12   minoura 		cs->cs_rr0_dcd = ZSRR0_DCD;
    216  1.12   minoura 		cs->cs_rr0_cts = 0;
    217  1.12   minoura 		cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
    218  1.12   minoura 		cs->cs_wr5_rts = 0;
    219   1.1       oki 
    220   1.9   msaitoh 		/*
    221  1.12   minoura 		 * Clear the master interrupt enable.
    222  1.12   minoura 		 * The INTENA is common to both channels,
    223  1.12   minoura 		 * so just do it on the A channel.
    224   1.9   msaitoh 		 */
    225  1.12   minoura 		if (channel == 0) {
    226  1.12   minoura 			s = splzs();
    227  1.12   minoura 			zs_write_reg(cs, 9, 0);
    228  1.12   minoura 			splx(s);
    229   1.1       oki 		}
    230   1.1       oki 
    231   1.1       oki 		/*
    232  1.12   minoura 		 * Look for a child driver for this channel.
    233  1.12   minoura 		 * The child attach will setup the hardware.
    234   1.1       oki 		 */
    235  1.12   minoura 		child = config_found(self, (void *)&zsc_args, zs_print);
    236  1.12   minoura 		if (child == NULL) {
    237  1.12   minoura 			/* No sub-driver.  Just reset it. */
    238  1.12   minoura 			u_char reset = (channel == 0) ?
    239  1.12   minoura 				ZSWR9_A_RESET : ZSWR9_B_RESET;
    240  1.12   minoura 			s = splzs();
    241  1.12   minoura 			zs_write_reg(cs,  9, reset);
    242  1.12   minoura 			splx(s);
    243   1.1       oki 		}
    244   1.1       oki 	}
    245   1.1       oki 
    246  1.12   minoura 	/*
    247  1.12   minoura 	 * Set the master interrupt enable and interrupt vector.
    248  1.12   minoura 	 * (common to both channels, do it on A)
    249  1.12   minoura 	 */
    250  1.12   minoura 	cs = zsc->zsc_cs[0];
    251  1.12   minoura 	s = splzs();
    252  1.12   minoura 	/* interrupt vector */
    253  1.12   minoura 	zs_write_reg(cs, 2, 0x70 + zs_unit);
    254  1.12   minoura 	/* master interrupt control (enable) */
    255  1.12   minoura 	zs_write_reg(cs, 9, zs_init_reg[9]);
    256  1.12   minoura 	splx(s);
    257   1.1       oki }
    258   1.1       oki 
    259   1.1       oki static int
    260  1.12   minoura zs_print(aux, name)
    261  1.12   minoura 	void *aux;
    262  1.12   minoura 	const char *name;
    263   1.1       oki {
    264  1.12   minoura 	struct zsc_attach_args *args = aux;
    265   1.1       oki 
    266  1.12   minoura 	if (name != NULL)
    267  1.12   minoura 		printf("%s: ", name);
    268   1.1       oki 
    269  1.12   minoura 	if (args->channel != -1)
    270  1.12   minoura 		printf(" channel %d", args->channel);
    271   1.1       oki 
    272  1.12   minoura 	return UNCONF;
    273   1.1       oki }
    274   1.1       oki 
    275  1.12   minoura static volatile int zssoftpending;
    276   1.1       oki 
    277   1.1       oki /*
    278  1.12   minoura  * Our ZS chips all share a common, autovectored interrupt,
    279  1.12   minoura  * so we have to look at all of them on each interrupt.
    280   1.1       oki  */
    281  1.12   minoura int
    282  1.12   minoura zshard(void)
    283   1.1       oki {
    284  1.12   minoura 	register struct zsc_softc *zsc;
    285  1.12   minoura 	register int unit, rval, softreq;
    286   1.1       oki 
    287  1.12   minoura 	rval = softreq = 0;
    288  1.12   minoura 	for (unit = 0; unit < zsc_cd.cd_ndevs; unit++) {
    289  1.12   minoura 		zsc = zsc_cd.cd_devs[unit];
    290  1.12   minoura 		if (zsc == NULL)
    291  1.12   minoura 			continue;
    292  1.12   minoura 		rval |= zsc_intr_hard(zsc);
    293  1.12   minoura 		softreq |= zsc->zsc_cs[0]->cs_softreq;
    294  1.12   minoura 		softreq |= zsc->zsc_cs[1]->cs_softreq;
    295  1.12   minoura 	}
    296   1.1       oki 
    297  1.12   minoura 	/* We are at splzs here, so no need to lock. */
    298  1.12   minoura 	if (softreq && (zssoftpending == 0)) {
    299  1.12   minoura 		zssoftpending = 1;
    300  1.12   minoura 		setsoftserial();
    301   1.1       oki 	}
    302  1.12   minoura 	return (rval);
    303   1.1       oki }
    304   1.1       oki 
    305   1.1       oki /*
    306  1.12   minoura  * Similar scheme as for zshard (look at all of them)
    307   1.1       oki  */
    308   1.1       oki int
    309   1.1       oki zssoft(arg)
    310   1.1       oki 	void *arg;
    311   1.1       oki {
    312  1.12   minoura 	register struct zsc_softc *zsc;
    313  1.12   minoura 	register int s, unit;
    314   1.1       oki 
    315  1.12   minoura 	/* This is not the only ISR on this IPL. */
    316  1.12   minoura 	if (zssoftpending == 0)
    317  1.12   minoura 		return (0);
    318   1.1       oki 
    319  1.12   minoura 	zssoftpending = 0;
    320   1.1       oki 
    321  1.12   minoura 	/* Make sure we call the tty layer at spltty. */
    322   1.1       oki 	s = spltty();
    323  1.12   minoura 	for (unit = 0; unit < zsc_cd.cd_ndevs; unit++) {
    324  1.12   minoura 		zsc = zsc_cd.cd_devs[unit];
    325  1.12   minoura 		if (zsc == NULL)
    326  1.12   minoura 			continue;
    327  1.12   minoura 		(void) zsc_intr_soft(zsc);
    328   1.1       oki 	}
    329   1.1       oki 	splx(s);
    330  1.12   minoura 	return (1);
    331   1.1       oki }
    332   1.1       oki 
    333  1.12   minoura 
    334   1.1       oki /*
    335  1.12   minoura  * Compute the current baud rate given a ZS channel.
    336   1.1       oki  */
    337  1.12   minoura static int
    338  1.12   minoura zs_get_speed(cs)
    339  1.12   minoura 	struct zs_chanstate *cs;
    340   1.1       oki {
    341  1.12   minoura 	int tconst;
    342   1.1       oki 
    343  1.12   minoura 	tconst = zs_read_reg(cs, 12);
    344  1.12   minoura 	tconst |= zs_read_reg(cs, 13) << 8;
    345  1.12   minoura 	return (TCONST_TO_BPS(cs->cs_brg_clk, tconst));
    346   1.1       oki }
    347   1.1       oki 
    348   1.1       oki /*
    349  1.12   minoura  * MD functions for setting the baud rate and control modes.
    350   1.1       oki  */
    351  1.12   minoura int
    352  1.12   minoura zs_set_speed(cs, bps)
    353  1.12   minoura 	struct zs_chanstate *cs;
    354  1.12   minoura 	int bps;	/* bits per second */
    355   1.1       oki {
    356  1.12   minoura 	int tconst, real_bps;
    357   1.1       oki 
    358  1.12   minoura 	if (bps == 0)
    359   1.1       oki 		return (0);
    360  1.12   minoura 
    361  1.12   minoura #ifdef	DIAGNOSTIC
    362  1.12   minoura 	if (cs->cs_brg_clk == 0)
    363  1.12   minoura 		panic("zs_set_speed");
    364  1.12   minoura #endif
    365  1.12   minoura 
    366  1.12   minoura 	tconst = BPS_TO_TCONST(cs->cs_brg_clk, bps);
    367  1.12   minoura 	if (tconst < 0)
    368   1.1       oki 		return (EINVAL);
    369   1.1       oki 
    370  1.12   minoura 	/* Convert back to make sure we can do it. */
    371  1.12   minoura 	real_bps = TCONST_TO_BPS(cs->cs_brg_clk, tconst);
    372   1.1       oki 
    373  1.12   minoura 	/* XXX - Allow some tolerance here? */
    374  1.12   minoura 	if (real_bps != bps)
    375  1.12   minoura 		return (EINVAL);
    376  1.12   minoura 
    377  1.12   minoura 	cs->cs_preg[12] = tconst;
    378  1.12   minoura 	cs->cs_preg[13] = tconst >> 8;
    379   1.1       oki 
    380  1.12   minoura 	/* Caller will stuff the pending registers. */
    381  1.12   minoura 	return (0);
    382  1.12   minoura }
    383   1.1       oki 
    384  1.12   minoura int
    385  1.12   minoura zs_set_modes(cs, cflag)
    386  1.12   minoura 	struct zs_chanstate *cs;
    387  1.12   minoura 	int cflag;	/* bits per second */
    388  1.12   minoura {
    389  1.12   minoura 	int s;
    390   1.1       oki 
    391   1.1       oki 	/*
    392  1.12   minoura 	 * Output hardware flow control on the chip is horrendous:
    393  1.12   minoura 	 * if carrier detect drops, the receiver is disabled, and if
    394  1.12   minoura 	 * CTS drops, the transmitter is stoped IN MID CHARACTER!
    395  1.12   minoura 	 * Therefore, NEVER set the HFC bit, and instead use the
    396  1.12   minoura 	 * status interrupt to detect CTS changes.
    397   1.1       oki 	 */
    398  1.12   minoura 	s = splzs();
    399  1.12   minoura 	if ((cflag & (CLOCAL | MDMBUF)) != 0)
    400  1.12   minoura 		cs->cs_rr0_dcd = 0;
    401  1.12   minoura 	else
    402  1.12   minoura 		cs->cs_rr0_dcd = ZSRR0_DCD;
    403  1.12   minoura 	if ((cflag & CRTSCTS) != 0) {
    404  1.12   minoura 		cs->cs_wr5_dtr = ZSWR5_DTR;
    405  1.12   minoura 		cs->cs_wr5_rts = ZSWR5_RTS;
    406  1.12   minoura 		cs->cs_rr0_cts = ZSRR0_CTS;
    407  1.12   minoura 	} else if ((cflag & MDMBUF) != 0) {
    408  1.12   minoura 		cs->cs_wr5_dtr = 0;
    409  1.12   minoura 		cs->cs_wr5_rts = ZSWR5_DTR;
    410  1.12   minoura 		cs->cs_rr0_cts = ZSRR0_DCD;
    411  1.12   minoura 	} else {
    412  1.12   minoura 		cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
    413  1.12   minoura 		cs->cs_wr5_rts = 0;
    414  1.12   minoura 		cs->cs_rr0_cts = 0;
    415   1.1       oki 	}
    416   1.1       oki 	splx(s);
    417  1.12   minoura 
    418  1.12   minoura 	/* Caller will stuff the pending registers. */
    419   1.1       oki 	return (0);
    420   1.1       oki }
    421   1.1       oki 
    422  1.12   minoura 
    423   1.1       oki /*
    424  1.12   minoura  * Read or write the chip with suitable delays.
    425   1.1       oki  */
    426  1.12   minoura 
    427  1.12   minoura u_char
    428  1.12   minoura zs_read_reg(cs, reg)
    429   1.1       oki 	struct zs_chanstate *cs;
    430  1.12   minoura 	u_char reg;
    431   1.1       oki {
    432  1.12   minoura 	u_char val;
    433   1.1       oki 
    434  1.12   minoura 	*cs->cs_reg_csr = reg;
    435  1.12   minoura 	ZS_DELAY();
    436  1.12   minoura 	val = *cs->cs_reg_csr;
    437  1.12   minoura 	ZS_DELAY();
    438  1.12   minoura 	return val;
    439   1.1       oki }
    440   1.1       oki 
    441  1.12   minoura void
    442  1.12   minoura zs_write_reg(cs, reg, val)
    443  1.12   minoura 	struct zs_chanstate *cs;
    444  1.12   minoura 	u_char reg, val;
    445   1.1       oki {
    446  1.12   minoura 	*cs->cs_reg_csr = reg;
    447  1.12   minoura 	ZS_DELAY();
    448  1.12   minoura 	*cs->cs_reg_csr = val;
    449  1.12   minoura 	ZS_DELAY();
    450   1.1       oki }
    451   1.1       oki 
    452  1.12   minoura u_char zs_read_csr(cs)
    453  1.12   minoura 	struct zs_chanstate *cs;
    454   1.1       oki {
    455  1.12   minoura 	register u_char val;
    456   1.1       oki 
    457  1.12   minoura 	val = *cs->cs_reg_csr;
    458   1.1       oki 	ZS_DELAY();
    459  1.12   minoura 	return val;
    460   1.1       oki }
    461   1.1       oki 
    462  1.12   minoura void  zs_write_csr(cs, val)
    463  1.12   minoura 	struct zs_chanstate *cs;
    464  1.12   minoura 	u_char val;
    465   1.1       oki {
    466  1.12   minoura 	*cs->cs_reg_csr = val;
    467  1.12   minoura 	ZS_DELAY();
    468   1.1       oki }
    469   1.1       oki 
    470  1.12   minoura u_char zs_read_data(cs)
    471  1.12   minoura 	struct zs_chanstate *cs;
    472   1.1       oki {
    473  1.12   minoura 	register u_char val;
    474   1.1       oki 
    475  1.12   minoura 	val = *cs->cs_reg_data;
    476  1.12   minoura 	ZS_DELAY();
    477  1.12   minoura 	return val;
    478   1.1       oki }
    479   1.1       oki 
    480  1.12   minoura void  zs_write_data(cs, val)
    481  1.12   minoura 	struct zs_chanstate *cs;
    482  1.12   minoura 	u_char val;
    483   1.1       oki {
    484  1.12   minoura 	*cs->cs_reg_data = val;
    485   1.1       oki 	ZS_DELAY();
    486   1.1       oki }
    487   1.1       oki 
    488   1.1       oki /*
    489  1.12   minoura  * Handle user request to enter kernel debugger.
    490   1.1       oki  */
    491   1.1       oki void
    492  1.12   minoura zs_abort(cs)
    493  1.12   minoura 	struct zs_chanstate *cs;
    494   1.1       oki {
    495  1.12   minoura 	int rr0;
    496  1.12   minoura 
    497  1.12   minoura 	/* Wait for end of break to avoid PROM abort. */
    498  1.12   minoura 	/* XXX - Limit the wait? */
    499  1.12   minoura 	do {
    500  1.12   minoura 		rr0 = *cs->cs_reg_csr;
    501  1.12   minoura 		ZS_DELAY();
    502  1.12   minoura 	} while (rr0 & ZSRR0_BREAK);
    503   1.1       oki 
    504  1.12   minoura #ifdef DDB
    505  1.12   minoura 	Debugger();
    506  1.12   minoura #else
    507  1.12   minoura 	printf ("BREAK!!\n");
    508  1.12   minoura #endif
    509   1.1       oki }
    510