Home | History | Annotate | Line # | Download | only in dev
zs.c revision 1.33
      1  1.33    gwr /*	$NetBSD: zs.c,v 1.33 1996/02/16 18:00:33 gwr Exp $	*/
      2  1.10    cgd 
      3   1.1  glass /*
      4  1.31    gwr  * Copyright (c) 1995 Gordon W. Ross
      5  1.31    gwr  * All rights reserved.
      6   1.1  glass  *
      7   1.1  glass  * Redistribution and use in source and binary forms, with or without
      8   1.1  glass  * modification, are permitted provided that the following conditions
      9   1.1  glass  * are met:
     10   1.1  glass  * 1. Redistributions of source code must retain the above copyright
     11   1.1  glass  *    notice, this list of conditions and the following disclaimer.
     12   1.1  glass  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1  glass  *    notice, this list of conditions and the following disclaimer in the
     14   1.1  glass  *    documentation and/or other materials provided with the distribution.
     15  1.31    gwr  * 3. The name of the author may not be used to endorse or promote products
     16  1.31    gwr  *    derived from this software without specific prior written permission.
     17  1.31    gwr  * 4. All advertising materials mentioning features or use of this software
     18   1.1  glass  *    must display the following acknowledgement:
     19  1.31    gwr  *      This product includes software developed by Gordon Ross
     20   1.1  glass  *
     21  1.31    gwr  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  1.31    gwr  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  1.31    gwr  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  1.31    gwr  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  1.31    gwr  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  1.31    gwr  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  1.31    gwr  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  1.31    gwr  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  1.31    gwr  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  1.31    gwr  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31   1.1  glass  */
     32   1.1  glass 
     33   1.1  glass /*
     34  1.31    gwr  * Zilog Z8530 Dual UART driver (machine-dependent part)
     35   1.1  glass  *
     36  1.31    gwr  * Runs two serial lines per chip using slave drivers.
     37  1.31    gwr  * Plain tty/async lines use the zs_async slave.
     38  1.31    gwr  * Sun keyboard/mouse uses the zs_kbd/zs_ms slaves.
     39   1.1  glass  */
     40   1.1  glass 
     41   1.5    gwr #include <sys/param.h>
     42   1.1  glass #include <sys/systm.h>
     43   1.1  glass #include <sys/proc.h>
     44   1.1  glass #include <sys/device.h>
     45   1.1  glass #include <sys/conf.h>
     46   1.1  glass #include <sys/file.h>
     47   1.1  glass #include <sys/ioctl.h>
     48   1.1  glass #include <sys/tty.h>
     49   1.1  glass #include <sys/time.h>
     50   1.1  glass #include <sys/kernel.h>
     51   1.1  glass #include <sys/syslog.h>
     52   1.1  glass 
     53  1.31    gwr #include <dev/cons.h>
     54  1.31    gwr #include <dev/ic/z8530reg.h>
     55  1.31    gwr #include <machine/z8530var.h>
     56  1.31    gwr 
     57   1.1  glass #include <machine/autoconf.h>
     58   1.1  glass #include <machine/cpu.h>
     59  1.31    gwr #include <machine/eeprom.h>
     60  1.18    gwr #include <machine/isr.h>
     61   1.1  glass #include <machine/obio.h>
     62   1.3    gwr #include <machine/mon.h>
     63   1.1  glass 
     64  1.16    gwr /*
     65  1.31    gwr  * XXX: Hard code this to make console init easier...
     66  1.16    gwr  */
     67  1.31    gwr #define	NZS	2		/* XXX */
     68   1.1  glass 
     69   1.1  glass 
     70   1.2  glass /* The Sun3 provides a 4.9152 MHz clock to the ZS chips. */
     71   1.2  glass #define PCLK	(9600 * 512)	/* PCLK pin input clock rate */
     72   1.2  glass 
     73   1.2  glass /*
     74  1.22    gwr  * Define interrupt levels.
     75   1.2  glass  */
     76   1.2  glass #define ZSHARD_PRI	6	/* Wired on the CPU board... */
     77  1.22    gwr #define ZSSOFT_PRI	3	/* Want tty pri (4) but this is OK. */
     78   1.1  glass 
     79  1.33    gwr #define ZS_DELAY()			delay(2)
     80  1.31    gwr 
     81  1.31    gwr /* The layout of this is hardware-dependent (padding, order). */
     82  1.31    gwr struct zschan {
     83  1.31    gwr 	volatile u_char	zc_csr;		/* ctrl,status, and indirect access */
     84  1.31    gwr 	u_char		zc_xxx0;
     85  1.31    gwr 	volatile u_char	zc_data;	/* data */
     86  1.31    gwr 	u_char		zc_xxx1;
     87  1.31    gwr };
     88  1.31    gwr struct zsdevice {
     89  1.31    gwr 	/* Yes, they are backwards. */
     90  1.31    gwr 	struct	zschan zs_chan_b;
     91  1.31    gwr 	struct	zschan zs_chan_a;
     92   1.1  glass };
     93   1.1  glass 
     94   1.1  glass 
     95  1.31    gwr /* Default OBIO addresses. */
     96  1.31    gwr static int zs_physaddr[NZS] = { OBIO_KEYBD_MS, OBIO_ZS };
     97  1.31    gwr /* Saved PROM mappings */
     98  1.31    gwr static struct zsdevice *zsaddr[NZS];	/* See zs_init() */
     99  1.31    gwr /* Flags from cninit() */
    100  1.31    gwr static int zs_hwflags[NZS][2];
    101  1.31    gwr /* Default speed for each channel */
    102  1.31    gwr static int zs_defspeed[NZS][2] = {
    103  1.31    gwr 	{ 1200, 	/* keyboard */
    104  1.31    gwr 	  1200 },	/* mouse */
    105  1.31    gwr 	{ 9600, 	/* ttya */
    106  1.31    gwr 	  9600 },	/* ttyb */
    107  1.31    gwr };
    108  1.13    gwr 
    109   1.1  glass 
    110  1.31    gwr /* Find PROM mappings (for console support). */
    111  1.31    gwr void zs_init()
    112  1.31    gwr {
    113  1.31    gwr 	int i;
    114   1.1  glass 
    115  1.31    gwr 	for (i = 0; i < NZS; i++) {
    116  1.31    gwr 		zsaddr[i] = (struct zsdevice *)
    117  1.31    gwr 			obio_find_mapping(zs_physaddr[i], OBIO_ZS_SIZE);
    118  1.31    gwr 	}
    119  1.31    gwr }
    120   1.1  glass 
    121  1.13    gwr 
    122  1.31    gwr struct zschan *
    123  1.31    gwr zs_get_chan_addr(zsc_unit, channel)
    124  1.31    gwr 	int zsc_unit, channel;
    125  1.31    gwr {
    126  1.31    gwr 	struct zsdevice *addr;
    127  1.31    gwr 	struct zschan *zc;
    128  1.31    gwr 
    129  1.31    gwr 	if (zsc_unit >= NZS)
    130  1.31    gwr 		return NULL;
    131  1.31    gwr 	addr = zsaddr[zsc_unit];
    132  1.31    gwr 	if (addr == NULL)
    133  1.31    gwr 		return NULL;
    134  1.31    gwr 	if (channel == 0) {
    135  1.31    gwr 		zc = &addr->zs_chan_a;
    136  1.31    gwr 	} else {
    137  1.31    gwr 		zc = &addr->zs_chan_b;
    138  1.31    gwr 	}
    139  1.31    gwr 	return (zc);
    140  1.31    gwr }
    141  1.13    gwr 
    142  1.18    gwr 
    143  1.18    gwr static u_char zs_init_reg[16] = {
    144  1.18    gwr 	0,	/* 0: CMD (reset, etc.) */
    145  1.18    gwr 	ZSWR1_RIE | ZSWR1_TIE | ZSWR1_SIE,
    146  1.18    gwr 	0x18 + ZSHARD_PRI,	/* IVECT */
    147  1.18    gwr 	ZSWR3_RX_8 | ZSWR3_RX_ENABLE,
    148  1.18    gwr 	ZSWR4_CLK_X16 | ZSWR4_ONESB | ZSWR4_EVENP,
    149  1.18    gwr 	ZSWR5_TX_8 | ZSWR5_TX_ENABLE,
    150  1.18    gwr 	0,	/* 6: TXSYNC/SYNCLO */
    151  1.18    gwr 	0,	/* 7: RXSYNC/SYNCHI */
    152  1.18    gwr 	0,	/* 8: alias for data port */
    153  1.31    gwr 	ZSWR9_MASTER_IE,
    154  1.18    gwr 	0,	/*10: Misc. TX/RX control bits */
    155  1.18    gwr 	ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD,
    156  1.31    gwr 	14,	/*12: BAUDLO (default=9600) */
    157  1.31    gwr 	0,	/*13: BAUDHI (default=9600) */
    158  1.18    gwr 	ZSWR14_BAUD_FROM_PCLK | ZSWR14_BAUD_ENA,
    159  1.18    gwr 	ZSWR15_BREAK_IE | ZSWR15_DCD_IE,
    160  1.18    gwr };
    161   1.9    gwr 
    162  1.21    gwr 
    163  1.31    gwr /****************************************************************
    164  1.31    gwr  * Autoconfig
    165  1.31    gwr  ****************************************************************/
    166  1.31    gwr 
    167  1.31    gwr /* Definition of the driver for autoconfig. */
    168  1.31    gwr static int	zsc_match(struct device *, void *, void *);
    169  1.31    gwr static void	zsc_attach(struct device *, struct device *, void *);
    170  1.31    gwr 
    171  1.31    gwr struct cfdriver zsccd = {
    172  1.31    gwr 	NULL, "zsc", zsc_match, zsc_attach,
    173  1.31    gwr 	DV_DULL, sizeof(struct zsc_softc), NULL,
    174  1.31    gwr };
    175  1.31    gwr 
    176  1.31    gwr static int zshard(void *);
    177  1.31    gwr static int zssoft(void *);
    178  1.31    gwr 
    179   1.9    gwr 
    180   1.1  glass /*
    181  1.31    gwr  * Is the zs chip present?
    182   1.1  glass  */
    183   1.1  glass static int
    184  1.31    gwr zsc_match(parent, vcf, aux)
    185  1.31    gwr 	struct device *parent;
    186  1.31    gwr 	void *vcf;
    187  1.31    gwr 	void *aux;
    188   1.1  glass {
    189  1.12    gwr 	struct cfdata *cf = vcf;
    190  1.31    gwr 	struct confargs *ca = aux;
    191  1.13    gwr 	int unit, x;
    192  1.21    gwr 	void *zsva;
    193  1.13    gwr 
    194  1.13    gwr 	unit = cf->cf_unit;
    195  1.13    gwr 	if (unit < 0 || unit >= NZS)
    196  1.13    gwr 		return (0);
    197   1.1  glass 
    198  1.31    gwr 	/* Make sure zs_init() found mappings. */
    199  1.21    gwr 	zsva = zsaddr[unit];
    200  1.21    gwr 	if (zsva == NULL)
    201  1.21    gwr 		return (0);
    202  1.21    gwr 
    203  1.13    gwr 	if (ca->ca_paddr == -1)
    204  1.13    gwr 		ca->ca_paddr = zs_physaddr[unit];
    205  1.13    gwr 	if (ca->ca_intpri == -1)
    206  1.13    gwr 		ca->ca_intpri = ZSHARD_PRI;
    207  1.13    gwr 
    208  1.21    gwr 	/* This returns -1 on a fault (bus error). */
    209  1.21    gwr 	x = peek_byte(zsva);
    210  1.14    gwr 	return (x != -1);
    211   1.1  glass }
    212   1.1  glass 
    213  1.31    gwr static int
    214  1.31    gwr zsc_print(aux, name)
    215  1.31    gwr 	void *aux;
    216  1.31    gwr 	char *name;
    217  1.31    gwr {
    218  1.31    gwr 	struct zsc_attach_args *args = aux;
    219  1.31    gwr 
    220  1.31    gwr 	if (name != NULL)
    221  1.31    gwr 		printf("%s: ", name);
    222  1.31    gwr 
    223  1.31    gwr 	if (args->channel != -1)
    224  1.31    gwr 		printf(" channel %d", args->channel);
    225  1.31    gwr 
    226  1.31    gwr 	return UNCONF;
    227  1.31    gwr }
    228  1.31    gwr 
    229   1.1  glass /*
    230   1.1  glass  * Attach a found zs.
    231   1.1  glass  *
    232  1.31    gwr  * Match slave number to zs unit number, so that misconfiguration will
    233  1.31    gwr  * not set up the keyboard as ttya, etc.
    234   1.1  glass  */
    235   1.1  glass static void
    236  1.31    gwr zsc_attach(parent, self, aux)
    237  1.31    gwr 	struct device *parent;
    238  1.31    gwr 	struct device *self;
    239  1.31    gwr 	void *aux;
    240  1.31    gwr {
    241  1.31    gwr 	struct zsc_softc *zsc = (void *) self;
    242  1.31    gwr 	struct confargs *ca = aux;
    243  1.31    gwr 	struct zsc_attach_args zsc_args;
    244  1.31    gwr 	volatile struct zschan *zc;
    245  1.31    gwr 	struct zs_chanstate *cs;
    246  1.31    gwr 	int zsc_unit, channel;
    247  1.31    gwr 	int reset, s;
    248   1.2  glass 	static int didintr;
    249   1.2  glass 
    250  1.31    gwr 	zsc_unit = zsc->zsc_dev.dv_unit;
    251  1.13    gwr 
    252  1.13    gwr 	printf(" softpri %d\n", ZSSOFT_PRI);
    253   1.1  glass 
    254  1.31    gwr 	/* Use the mapping setup by the Sun PROM. */
    255  1.31    gwr 	if (zsaddr[zsc_unit] == NULL)
    256  1.31    gwr 		panic("zs_attach: zs%d not mapped\n", zsc_unit);
    257  1.31    gwr 
    258  1.31    gwr 	/*
    259  1.31    gwr 	 * Initialize software state for each channel.
    260  1.31    gwr 	 */
    261  1.31    gwr 	for (channel = 0; channel < 2; channel++) {
    262  1.31    gwr 		cs = &zsc->zsc_cs[channel];
    263  1.31    gwr 
    264  1.31    gwr 		zc = zs_get_chan_addr(zsc_unit, channel);
    265  1.31    gwr 		cs->cs_reg_csr  = &zc->zc_csr;
    266  1.31    gwr 		cs->cs_reg_data = &zc->zc_data;
    267   1.1  glass 
    268  1.31    gwr 		cs->cs_channel = channel;
    269  1.31    gwr 		cs->cs_private = NULL;
    270  1.31    gwr 		cs->cs_ops = &zsops_null;
    271  1.31    gwr 
    272  1.31    gwr 		/* Define BAUD rate clock for the MI code. */
    273  1.31    gwr 		cs->cs_pclk_div16 = PCLK / 16;
    274  1.31    gwr 
    275  1.31    gwr 		/* XXX: get defspeed from EEPROM instead? */
    276  1.31    gwr 		cs->cs_defspeed = zs_defspeed[zsc_unit][channel];
    277   1.2  glass 
    278  1.31    gwr 		bcopy(zs_init_reg, cs->cs_creg, 16);
    279  1.31    gwr 		bcopy(zs_init_reg, cs->cs_preg, 16);
    280  1.15    gwr 
    281   1.1  glass 		/*
    282  1.31    gwr 		 * Clear the master interrupt enable.
    283  1.31    gwr 		 * The INTENA is common to both channels,
    284  1.31    gwr 		 * so just do it on the A channel.
    285   1.1  glass 		 */
    286  1.31    gwr 		if (channel == 0) {
    287  1.32    gwr 			zs_write_reg(cs, 9, 0);
    288  1.31    gwr 		}
    289  1.15    gwr 
    290   1.1  glass 		/*
    291  1.31    gwr 		 * Look for a child driver for this channel.
    292  1.31    gwr 		 * The child attach will setup the hardware.
    293   1.1  glass 		 */
    294  1.31    gwr 		zsc_args.channel = channel;
    295  1.31    gwr 		zsc_args.hwflags = zs_hwflags[zsc_unit][channel];
    296  1.31    gwr 		if (!config_found(self, (void *) &zsc_args, zsc_print)) {
    297  1.31    gwr 			/* No sub-driver.  Just reset it. */
    298  1.31    gwr 			reset = (channel == 0) ?
    299  1.31    gwr 				ZSWR9_A_RESET : ZSWR9_B_RESET;
    300  1.31    gwr 			s = splzs();
    301  1.32    gwr 			zs_write_reg(cs,  9, reset);
    302  1.31    gwr 			splx(s);
    303  1.31    gwr 		}
    304   1.1  glass 	}
    305   1.1  glass 
    306  1.31    gwr 	/* Now safe to install interrupt handlers */
    307  1.31    gwr 	if (!didintr) {
    308  1.31    gwr 		didintr = 1;
    309  1.31    gwr 		isr_add_autovect(zssoft, NULL, ZSSOFT_PRI);
    310  1.31    gwr 		isr_add_autovect(zshard, NULL, ZSHARD_PRI);
    311  1.31    gwr 	}
    312  1.24    gwr 
    313  1.31    gwr 	/*
    314  1.31    gwr 	 * Set the master interrupt enable and interrupt vector.
    315  1.31    gwr 	 * (common to both channels, do it on A)
    316  1.31    gwr 	 */
    317  1.31    gwr 	cs = &zsc->zsc_cs[0];
    318  1.31    gwr 	s = splzs();
    319  1.31    gwr 	/* interrupt vector */
    320  1.32    gwr 	zs_write_reg(cs, 2, zs_init_reg[2]);
    321  1.31    gwr 	/* master interrupt control (enable) */
    322  1.32    gwr 	zs_write_reg(cs, 9, zs_init_reg[9]);
    323  1.31    gwr 	splx(s);
    324  1.24    gwr }
    325  1.24    gwr 
    326  1.31    gwr static int
    327  1.31    gwr zshard(arg)
    328  1.31    gwr 	void *arg;
    329   1.1  glass {
    330  1.31    gwr 	struct zsc_softc *zsc;
    331  1.31    gwr 	int unit, rval;
    332  1.31    gwr 
    333  1.31    gwr 	/* Do ttya/ttyb first, because they go faster. */
    334  1.31    gwr 	rval = 0;
    335  1.31    gwr 	unit = zsccd.cd_ndevs;
    336  1.31    gwr 	while (--unit >= 0) {
    337  1.31    gwr 		zsc = zsccd.cd_devs[unit];
    338  1.31    gwr 		if (zsc != NULL) {
    339  1.31    gwr 			rval |= zsc_intr_hard(zsc);
    340  1.31    gwr 		}
    341  1.31    gwr 	}
    342  1.31    gwr 	return (rval);
    343   1.1  glass }
    344   1.1  glass 
    345  1.31    gwr int zssoftpending;
    346   1.2  glass 
    347  1.31    gwr void
    348  1.31    gwr zsc_req_softint(zsc)
    349  1.31    gwr 	struct zsc_softc *zsc;
    350  1.31    gwr {
    351  1.31    gwr 	if (zssoftpending == 0) {
    352  1.31    gwr 		/* We are at splzs here, so no need to lock. */
    353  1.31    gwr 		zssoftpending = ZSSOFT_PRI;
    354  1.31    gwr 		isr_soft_request(ZSSOFT_PRI);
    355   1.3    gwr 	}
    356   1.3    gwr }
    357   1.3    gwr 
    358   1.3    gwr static int
    359  1.31    gwr zssoft(arg)
    360  1.31    gwr 	void *arg;
    361   1.3    gwr {
    362  1.31    gwr 	struct zsc_softc *zsc;
    363  1.31    gwr 	int unit;
    364  1.31    gwr 
    365  1.31    gwr 	/* This is not the only ISR on this IPL. */
    366  1.31    gwr 	if (zssoftpending == 0)
    367  1.31    gwr 		return (0);
    368   1.3    gwr 
    369  1.31    gwr 	/*
    370  1.31    gwr 	 * The soft intr. bit will be set by zshard only if
    371  1.31    gwr 	 * the variable zssoftpending is zero.  The order of
    372  1.31    gwr 	 * these next two statements prevents our clearing
    373  1.31    gwr 	 * the soft intr bit just after zshard has set it.
    374  1.31    gwr 	 */
    375  1.31    gwr 	isr_soft_clear(ZSSOFT_PRI);
    376  1.31    gwr 	zssoftpending = 0;
    377   1.2  glass 
    378  1.31    gwr 	/* Do ttya/ttyb first, because they go faster. */
    379  1.31    gwr 	unit = zsccd.cd_ndevs;
    380  1.31    gwr 	while (--unit >= 0) {
    381  1.31    gwr 		zsc = zsccd.cd_devs[unit];
    382  1.31    gwr 		if (zsc != NULL) {
    383  1.31    gwr 			(void) zsc_intr_soft(zsc);
    384  1.31    gwr 		}
    385   1.3    gwr 	}
    386  1.31    gwr 	return (1);
    387   1.2  glass }
    388   1.2  glass 
    389   1.2  glass 
    390  1.31    gwr /*
    391  1.31    gwr  * Read or write the chip with suitable delays.
    392  1.31    gwr  */
    393   1.2  glass 
    394  1.31    gwr u_char
    395  1.31    gwr zs_read_reg(cs, reg)
    396  1.31    gwr 	struct zs_chanstate *cs;
    397  1.31    gwr 	u_char reg;
    398   1.1  glass {
    399  1.31    gwr 	u_char val;
    400   1.1  glass 
    401  1.31    gwr 	*cs->cs_reg_csr = reg;
    402  1.31    gwr 	ZS_DELAY();
    403  1.31    gwr 	val = *cs->cs_reg_csr;
    404  1.31    gwr 	ZS_DELAY();
    405  1.31    gwr 	return val;
    406  1.17    gwr }
    407   1.3    gwr 
    408  1.31    gwr void
    409  1.31    gwr zs_write_reg(cs, reg, val)
    410  1.31    gwr 	struct zs_chanstate *cs;
    411  1.31    gwr 	u_char reg, val;
    412  1.17    gwr {
    413  1.31    gwr 	*cs->cs_reg_csr = reg;
    414  1.31    gwr 	ZS_DELAY();
    415  1.31    gwr 	*cs->cs_reg_csr = val;
    416  1.32    gwr 	ZS_DELAY();
    417  1.32    gwr }
    418  1.32    gwr 
    419  1.32    gwr u_char zs_read_csr(cs)
    420  1.32    gwr 	struct zs_chanstate *cs;
    421  1.32    gwr {
    422  1.32    gwr 	register u_char v;
    423  1.32    gwr 
    424  1.32    gwr 	v = *cs->cs_reg_csr;
    425  1.32    gwr 	ZS_DELAY();
    426  1.32    gwr 	return v;
    427  1.32    gwr }
    428  1.32    gwr 
    429  1.32    gwr u_char zs_read_data(cs)
    430  1.32    gwr 	struct zs_chanstate *cs;
    431  1.32    gwr {
    432  1.32    gwr 	register u_char v;
    433  1.32    gwr 
    434  1.32    gwr 	v = *cs->cs_reg_data;
    435  1.32    gwr 	ZS_DELAY();
    436  1.32    gwr 	return v;
    437  1.32    gwr }
    438  1.32    gwr 
    439  1.32    gwr void  zs_write_csr(cs, val)
    440  1.32    gwr 	struct zs_chanstate *cs;
    441  1.32    gwr 	u_char val;
    442  1.32    gwr {
    443  1.32    gwr 	*cs->cs_reg_csr = val;
    444  1.32    gwr 	ZS_DELAY();
    445  1.32    gwr }
    446  1.32    gwr 
    447  1.32    gwr void  zs_write_data(cs, val)
    448  1.32    gwr 	struct zs_chanstate *cs;
    449  1.32    gwr 	u_char val;
    450  1.32    gwr {
    451  1.32    gwr 	*cs->cs_reg_data = val;
    452  1.31    gwr 	ZS_DELAY();
    453   1.1  glass }
    454   1.3    gwr 
    455  1.31    gwr /****************************************************************
    456  1.31    gwr  * Console support functions (Sun3 specific!)
    457  1.31    gwr  ****************************************************************/
    458   1.1  glass 
    459   1.2  glass /*
    460  1.31    gwr  * Polled input char.
    461   1.2  glass  */
    462   1.2  glass int
    463  1.31    gwr zs_getc(arg)
    464  1.31    gwr 	void *arg;
    465   1.2  glass {
    466  1.31    gwr 	register volatile struct zschan *zc = arg;
    467  1.25    gwr 	register int s, c, rr0;
    468   1.2  glass 
    469   1.2  glass 	s = splhigh();
    470   1.9    gwr 	/* Wait for a character to arrive. */
    471  1.25    gwr 	do {
    472  1.25    gwr 		rr0 = zc->zc_csr;
    473   1.3    gwr 		ZS_DELAY();
    474  1.25    gwr 	} while ((rr0 & ZSRR0_RX_READY) == 0);
    475   1.9    gwr 
    476   1.2  glass 	c = zc->zc_data;
    477   1.9    gwr 	ZS_DELAY();
    478   1.2  glass 	splx(s);
    479  1.17    gwr 
    480  1.17    gwr 	/*
    481  1.17    gwr 	 * This is used by the kd driver to read scan codes,
    482  1.17    gwr 	 * so don't translate '\r' ==> '\n' here...
    483  1.17    gwr 	 */
    484   1.2  glass 	return (c);
    485   1.2  glass }
    486   1.1  glass 
    487   1.1  glass /*
    488  1.31    gwr  * Polled output char.
    489   1.1  glass  */
    490  1.31    gwr void
    491  1.31    gwr zs_putc(arg, c)
    492  1.31    gwr 	void *arg;
    493   1.1  glass 	int c;
    494   1.1  glass {
    495  1.31    gwr 	register volatile struct zschan *zc = arg;
    496  1.25    gwr 	register int s, rr0;
    497   1.1  glass 
    498   1.9    gwr 	s = splhigh();
    499   1.9    gwr 	/* Wait for transmitter to become ready. */
    500  1.25    gwr 	do {
    501  1.25    gwr 		rr0 = zc->zc_csr;
    502   1.3    gwr 		ZS_DELAY();
    503  1.25    gwr 	} while ((rr0 & ZSRR0_TX_READY) == 0);
    504   1.9    gwr 
    505   1.1  glass 	zc->zc_data = c;
    506   1.3    gwr 	ZS_DELAY();
    507   1.1  glass 	splx(s);
    508   1.1  glass }
    509   1.2  glass 
    510  1.31    gwr extern struct consdev consdev_kd;	/* keyboard/display */
    511  1.31    gwr extern struct consdev consdev_tty;
    512  1.31    gwr extern struct consdev *cn_tab;	/* physical console device info */
    513  1.31    gwr extern void nullcnpollc();
    514  1.31    gwr 
    515  1.31    gwr void *zs_conschan;
    516  1.31    gwr 
    517   1.1  glass /*
    518  1.31    gwr  * This function replaces sys/dev/cninit.c
    519  1.31    gwr  * Determine which device is the console using
    520  1.31    gwr  * the "console" byte from the EEPROM.
    521   1.1  glass  */
    522  1.31    gwr void
    523  1.31    gwr cninit()
    524   1.1  glass {
    525  1.31    gwr 	struct zschan *zc;
    526  1.31    gwr 	struct consdev *cn;
    527  1.31    gwr 	int zsc_unit, channel;
    528  1.31    gwr 
    529  1.31    gwr 	switch (ee_console) {
    530  1.31    gwr 
    531  1.31    gwr 	case EE_CONS_TTYA:
    532  1.31    gwr 	case EE_CONS_TTYB:
    533  1.31    gwr 		zsc_unit = 1;
    534  1.31    gwr 		channel = (ee_console & 1);
    535  1.31    gwr 		cn = &consdev_tty;
    536  1.31    gwr 		cn->cn_dev = makedev(ZSTTY_MAJOR, channel);
    537  1.31    gwr 		cn->cn_pri = CN_REMOTE;
    538  1.31    gwr 		break;
    539   1.1  glass 
    540  1.31    gwr 	default:
    541  1.31    gwr 		mon_printf("cninit: unknown eeprom console setting\n");
    542  1.31    gwr 		/* assume keyboard/display */
    543  1.31    gwr 		/* fallthrough */
    544  1.31    gwr 	case EE_CONS_BW:
    545  1.31    gwr 	case EE_CONS_COLOR:
    546  1.31    gwr 	case EE_CONS_P4OPT:
    547  1.31    gwr 		zsc_unit = 0;
    548  1.31    gwr 		channel = 0;
    549  1.31    gwr 		cn = &consdev_kd;
    550  1.31    gwr 		/* Set cn_dev, cn_pri in kd.c */
    551  1.31    gwr 		break;
    552   1.1  glass 	}
    553   1.1  glass 
    554  1.31    gwr 	zc = zs_get_chan_addr(zsc_unit, channel);
    555  1.31    gwr 	if (zc == NULL) {
    556  1.31    gwr 		mon_printf("cninit: zs not mapped.\n");
    557  1.31    gwr 		return;
    558  1.31    gwr 	}
    559  1.31    gwr 	zs_conschan = zc;
    560  1.31    gwr 	zs_hwflags[zsc_unit][channel] = ZS_HWFLAG_CONSOLE;
    561  1.31    gwr 	cn_tab = cn;
    562  1.31    gwr 	(*cn->cn_init)(cn);
    563   1.1  glass }
    564   1.1  glass 
    565   1.1  glass 
    566  1.31    gwr /* We never call this. */
    567  1.31    gwr void
    568  1.31    gwr nullcnprobe(cn)
    569  1.31    gwr 	struct consdev *cn;
    570   1.1  glass {
    571   1.1  glass }
    572   1.1  glass 
    573  1.31    gwr void
    574  1.31    gwr zscninit(cn)
    575  1.31    gwr 	struct consdev *cn;
    576   1.1  glass {
    577  1.31    gwr 	int unit = minor(cn->cn_dev) & 1;
    578   1.1  glass 
    579  1.31    gwr 	mon_printf("console is zstty%d (tty%c)\n",
    580  1.31    gwr 		   unit, unit + 'a');
    581   1.1  glass }
    582   1.1  glass 
    583   1.1  glass /*
    584  1.31    gwr  * Polled console input putchar.
    585   1.1  glass  */
    586   1.1  glass int
    587  1.31    gwr zscngetc(dev)
    588  1.29    gwr 	dev_t dev;
    589   1.1  glass {
    590  1.31    gwr 	register volatile struct zschan *zc = zs_conschan;
    591  1.31    gwr 	register int c;
    592   1.1  glass 
    593  1.31    gwr 	c = zs_getc(zc);
    594  1.31    gwr 	return (c);
    595   1.1  glass }
    596   1.1  glass 
    597   1.1  glass /*
    598  1.31    gwr  * Polled console output putchar.
    599   1.1  glass  */
    600  1.31    gwr void
    601  1.31    gwr zscnputc(dev, c)
    602  1.29    gwr 	dev_t dev;
    603  1.31    gwr 	int c;
    604   1.1  glass {
    605  1.31    gwr 	register volatile struct zschan *zc = zs_conschan;
    606   1.1  glass 
    607  1.31    gwr 	zs_putc(zc, c);
    608   1.1  glass }
    609   1.1  glass 
    610   1.1  glass 
    611  1.31    gwr struct consdev consdev_tty = {
    612  1.31    gwr 	nullcnprobe,
    613  1.31    gwr 	zscninit,
    614  1.31    gwr 	zscngetc,
    615  1.31    gwr 	zscnputc,
    616  1.31    gwr 	nullcnpollc,
    617  1.31    gwr };
    618  1.31    gwr 
    619   1.1  glass 
    620   1.1  glass /*
    621  1.31    gwr  * Handle user request to enter kernel debugger.
    622   1.1  glass  */
    623  1.31    gwr void
    624  1.31    gwr zs_abort()
    625   1.1  glass {
    626  1.31    gwr 	register volatile struct zschan *zc = zs_conschan;
    627  1.31    gwr 	int rr0;
    628   1.3    gwr 
    629  1.31    gwr 	/* Wait for end of break to avoid PROM abort. */
    630  1.31    gwr 	/* XXX - Limit the wait? */
    631  1.31    gwr 	do {
    632  1.31    gwr 		rr0 = zc->zc_csr;
    633  1.31    gwr 		ZS_DELAY();
    634  1.31    gwr 	} while (rr0 & ZSRR0_BREAK);
    635   1.1  glass 
    636  1.31    gwr 	/* XXX - Always available, but may be the PROM monitor. */
    637  1.31    gwr 	Debugger();
    638   1.1  glass }
    639