Home | History | Annotate | Line # | Download | only in dev
zs.c revision 1.50
      1 /*	$NetBSD: zs.c,v 1.50 1997/10/06 21:04:21 gwr Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1996 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Gordon W. Ross.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*
     40  * Zilog Z8530 Dual UART driver (machine-dependent part)
     41  *
     42  * Runs two serial lines per chip using slave drivers.
     43  * Plain tty/async lines use the zs_async slave.
     44  * Sun keyboard/mouse uses the zs_kbd/zs_ms slaves.
     45  */
     46 
     47 #include <sys/param.h>
     48 #include <sys/systm.h>
     49 #include <sys/conf.h>
     50 #include <sys/device.h>
     51 #include <sys/file.h>
     52 #include <sys/ioctl.h>
     53 #include <sys/kernel.h>
     54 #include <sys/proc.h>
     55 #include <sys/tty.h>
     56 #include <sys/time.h>
     57 #include <sys/syslog.h>
     58 
     59 #include <machine/autoconf.h>
     60 #include <machine/cpu.h>
     61 #include <machine/obio.h>
     62 #include <machine/machdep.h>
     63 #include <machine/mon.h>
     64 #include <machine/z8530var.h>
     65 
     66 #include <dev/cons.h>
     67 #include <dev/ic/z8530reg.h>
     68 
     69 #include <sun3/dev/zs_cons.h>
     70 
     71 #include "kbd.h"	/* NKBD */
     72 #include "zsc.h"	/* NZSC */
     73 #define NZS NZSC
     74 
     75 /* Make life easier for the initialized arrays here. */
     76 #if NZS < 2
     77 #undef  NZS
     78 #define NZS 2
     79 #endif
     80 
     81 extern void Debugger __P((void));
     82 
     83 /*
     84  * Some warts needed by z8530tty.c -
     85  * The default parity REALLY needs to be the same as the PROM uses,
     86  * or you can not see messages done with printf during boot-up...
     87  */
     88 int zs_def_cflag = (CREAD | CS8 | HUPCL);
     89 int zs_major = 12;
     90 
     91 /*
     92  * The Sun3 provides a 4.9152 MHz clock to the ZS chips.
     93  */
     94 #define PCLK	(9600 * 512)	/* PCLK pin input clock rate */
     95 
     96 /*
     97  * Define interrupt levels.
     98  */
     99 #define ZSHARD_PRI	6	/* Wired on the CPU board... */
    100 #define ZSSOFT_PRI	3	/* Want tty pri (4) but this is OK. */
    101 
    102 #define ZS_DELAY()			delay(2)
    103 
    104 /* The layout of this is hardware-dependent (padding, order). */
    105 struct zschan {
    106 	volatile u_char	zc_csr;		/* ctrl,status, and indirect access */
    107 	u_char		zc_xxx0;
    108 	volatile u_char	zc_data;	/* data */
    109 	u_char		zc_xxx1;
    110 };
    111 struct zsdevice {
    112 	/* Yes, they are backwards. */
    113 	struct	zschan zs_chan_b;
    114 	struct	zschan zs_chan_a;
    115 };
    116 
    117 
    118 /* Default OBIO addresses. */
    119 static int zs_physaddr[NZS] = {
    120 	OBIO_ZS_KBD_MS,
    121 	OBIO_ZS_TTY_AB };
    122 
    123 /* Saved PROM mappings */
    124 static struct zsdevice *zsaddr[NZS];
    125 
    126 /* Flags from cninit() */
    127 static int zs_hwflags[NZS][2];
    128 
    129 /* Default speed for each channel */
    130 static int zs_defspeed[NZS][2] = {
    131 	{ 1200, 	/* keyboard */
    132 	  1200 },	/* mouse */
    133 	{ 9600, 	/* ttya */
    134 	  9600 },	/* ttyb */
    135 };
    136 
    137 static u_char zs_init_reg[16] = {
    138 	0,	/* 0: CMD (reset, etc.) */
    139 	0,	/* 1: No interrupts yet. */
    140 	0x18 + ZSHARD_PRI,	/* IVECT */
    141 	ZSWR3_RX_8 | ZSWR3_RX_ENABLE,
    142 	ZSWR4_CLK_X16 | ZSWR4_ONESB | ZSWR4_EVENP,
    143 	ZSWR5_TX_8 | ZSWR5_TX_ENABLE,
    144 	0,	/* 6: TXSYNC/SYNCLO */
    145 	0,	/* 7: RXSYNC/SYNCHI */
    146 	0,	/* 8: alias for data port */
    147 	ZSWR9_MASTER_IE,
    148 	0,	/*10: Misc. TX/RX control bits */
    149 	ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD,
    150 	14,	/*12: BAUDLO (default=9600) */
    151 	0,	/*13: BAUDHI (default=9600) */
    152 	ZSWR14_BAUD_ENA | ZSWR14_BAUD_FROM_PCLK,
    153 	ZSWR15_BREAK_IE | ZSWR15_DCD_IE,
    154 };
    155 
    156 
    157 /* Find PROM mappings (for console support). */
    158 void
    159 zs_init()
    160 {
    161 	int i;
    162 
    163 	for (i = 0; i < NZS; i++) {
    164 		zsaddr[i] = (struct zsdevice *)
    165 			obio_find_mapping(zs_physaddr[i], sizeof(struct zschan));
    166 	}
    167 }
    168 
    169 struct zschan *
    170 zs_get_chan_addr(zs_unit, channel)
    171 	int zs_unit, channel;
    172 {
    173 	struct zsdevice *addr;
    174 	struct zschan *zc;
    175 
    176 	if (zs_unit >= NZS)
    177 		return NULL;
    178 	addr = zsaddr[zs_unit];
    179 	if (addr == NULL)
    180 		return NULL;
    181 	if (channel == 0) {
    182 		zc = &addr->zs_chan_a;
    183 	} else {
    184 		zc = &addr->zs_chan_b;
    185 	}
    186 	return (zc);
    187 }
    188 
    189 
    190 /****************************************************************
    191  * Autoconfig
    192  ****************************************************************/
    193 
    194 /* Definition of the driver for autoconfig. */
    195 static int	zs_match __P((struct device *, struct cfdata *, void *));
    196 static void	zs_attach __P((struct device *, struct device *, void *));
    197 static int  zs_print __P((void *, const char *name));
    198 
    199 struct cfattach zsc_ca = {
    200 	sizeof(struct zsc_softc), zs_match, zs_attach
    201 };
    202 
    203 struct cfdriver zsc_cd = {
    204 	NULL, "zsc", DV_DULL
    205 };
    206 
    207 static int zshard __P((void *));
    208 static int zssoft __P((void *));
    209 static int zs_get_speed __P((struct zs_chanstate *));
    210 
    211 
    212 /*
    213  * Is the zs chip present?
    214  */
    215 static int
    216 zs_match(parent, cf, aux)
    217 	struct device *parent;
    218 	struct cfdata *cf;
    219 	void *aux;
    220 {
    221 	struct confargs *ca = aux;
    222 	int unit = cf->cf_unit;
    223 	void *va;
    224 
    225 	/*
    226 	 * This driver only supports its wired-in mappings,
    227 	 * because the console support depends on those.
    228 	 */
    229 	if (ca->ca_paddr != zs_physaddr[unit])
    230 		return (0);
    231 
    232 	/* Make sure zs_init() found mappings. */
    233 	va = zsaddr[unit];
    234 	if (va == NULL)
    235 		return (0);
    236 
    237 	/* This returns -1 on a fault (bus error). */
    238 	if (peek_byte(va) == -1)
    239 		return (0);
    240 
    241 	/* Default interrupt priority (always splbio==2) */
    242 	if (ca->ca_intpri == -1)
    243 		ca->ca_intpri = ZSHARD_PRI;
    244 
    245 	return (1);
    246 }
    247 
    248 /*
    249  * Attach a found zs.
    250  *
    251  * Match slave number to zs unit number, so that misconfiguration will
    252  * not set up the keyboard as ttya, etc.
    253  */
    254 static void
    255 zs_attach(parent, self, aux)
    256 	struct device *parent;
    257 	struct device *self;
    258 	void *aux;
    259 {
    260 	struct zsc_softc *zsc = (void *) self;
    261 	struct confargs *ca = aux;
    262 	struct zsc_attach_args zsc_args;
    263 	volatile struct zschan *zc;
    264 	struct zs_chanstate *cs;
    265 	int s, zs_unit, channel;
    266 	static int didintr;
    267 
    268 	zs_unit = zsc->zsc_dev.dv_unit;
    269 
    270 	printf(": (softpri %d)\n", ZSSOFT_PRI);
    271 
    272 	/* Use the mapping setup by the Sun PROM. */
    273 	if (zsaddr[zs_unit] == NULL)
    274 		panic("zs_attach: zs%d not mapped\n", zs_unit);
    275 
    276 	/*
    277 	 * Initialize software state for each channel.
    278 	 */
    279 	for (channel = 0; channel < 2; channel++) {
    280 		zsc_args.channel = channel;
    281 		zsc_args.hwflags = zs_hwflags[zs_unit][channel];
    282 		cs = &zsc->zsc_cs_store[channel];
    283 		zsc->zsc_cs[channel] = cs;
    284 
    285 		cs->cs_channel = channel;
    286 		cs->cs_private = NULL;
    287 		cs->cs_ops = &zsops_null;
    288 		cs->cs_brg_clk = PCLK / 16;
    289 
    290 		zc = zs_get_chan_addr(zs_unit, channel);
    291 		cs->cs_reg_csr  = &zc->zc_csr;
    292 		cs->cs_reg_data = &zc->zc_data;
    293 
    294 		bcopy(zs_init_reg, cs->cs_creg, 16);
    295 		bcopy(zs_init_reg, cs->cs_preg, 16);
    296 
    297 		/* XXX: Get these from the EEPROM instead? */
    298 		/* XXX: See the mvme167 code.  Better. */
    299 		if (zsc_args.hwflags & ZS_HWFLAG_CONSOLE)
    300 			cs->cs_defspeed = zs_get_speed(cs);
    301 		else
    302 			cs->cs_defspeed = zs_defspeed[zs_unit][channel];
    303 		cs->cs_defcflag = zs_def_cflag;
    304 
    305 		/* Make these correspond to cs_defcflag (-crtscts) */
    306 		cs->cs_rr0_dcd = ZSRR0_DCD;
    307 		cs->cs_rr0_cts = 0;
    308 		cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
    309 		cs->cs_wr5_rts = 0;
    310 
    311 		/*
    312 		 * Clear the master interrupt enable.
    313 		 * The INTENA is common to both channels,
    314 		 * so just do it on the A channel.
    315 		 */
    316 		if (channel == 0) {
    317 			zs_write_reg(cs, 9, 0);
    318 		}
    319 
    320 		/*
    321 		 * Look for a child driver for this channel.
    322 		 * The child attach will setup the hardware.
    323 		 */
    324 		if (!config_found(self, (void *)&zsc_args, zs_print)) {
    325 			/* No sub-driver.  Just reset it. */
    326 			u_char reset = (channel == 0) ?
    327 				ZSWR9_A_RESET : ZSWR9_B_RESET;
    328 			s = splhigh();
    329 			zs_write_reg(cs,  9, reset);
    330 			splx(s);
    331 		}
    332 	}
    333 
    334 	/*
    335 	 * Now safe to install interrupt handlers.  Note the arguments
    336 	 * to the interrupt handlers aren't used.  Note, we only do this
    337 	 * once since both SCCs interrupt at the same level and vector.
    338 	 */
    339 	if (!didintr) {
    340 		didintr = 1;
    341 		isr_add_autovect(zssoft, NULL, ZSSOFT_PRI);
    342 		isr_add_autovect(zshard, NULL, ca->ca_intpri);
    343 	}
    344 	/* XXX; evcnt_attach() ? */
    345 
    346 	/*
    347 	 * Set the master interrupt enable and interrupt vector.
    348 	 * (common to both channels, do it on A)
    349 	 */
    350 	cs = zsc->zsc_cs[0];
    351 	s = splhigh();
    352 	/* interrupt vector */
    353 	zs_write_reg(cs, 2, zs_init_reg[2]);
    354 	/* master interrupt control (enable) */
    355 	zs_write_reg(cs, 9, zs_init_reg[9]);
    356 	splx(s);
    357 
    358 	/*
    359 	 * XXX: L1A hack - We would like to be able to break into
    360 	 * the debugger during the rest of autoconfiguration, so
    361 	 * lower interrupts just enough to let zs interrupts in.
    362 	 * This is done after both zs devices are attached.
    363 	 */
    364 	if (zs_unit == 1) {
    365 		printf("zsc1: enabling zs interrupts\n");
    366 		(void)spl5(); /* splzs - 1 */
    367 	}
    368 }
    369 
    370 static int
    371 zs_print(aux, name)
    372 	void *aux;
    373 	const char *name;
    374 {
    375 	struct zsc_attach_args *args = aux;
    376 
    377 	if (name != NULL)
    378 		printf("%s: ", name);
    379 
    380 	if (args->channel != -1)
    381 		printf(" channel %d", args->channel);
    382 
    383 	return UNCONF;
    384 }
    385 
    386 static volatile int zssoftpending;
    387 
    388 /*
    389  * Our ZS chips all share a common, autovectored interrupt,
    390  * so we have to look at all of them on each interrupt.
    391  */
    392 static int
    393 zshard(arg)
    394 	void *arg;
    395 {
    396 	register struct zsc_softc *zsc;
    397 	register int unit, rval, softreq;
    398 
    399 	rval = softreq = 0;
    400 	for (unit = 0; unit < zsc_cd.cd_ndevs; unit++) {
    401 		zsc = zsc_cd.cd_devs[unit];
    402 		if (zsc == NULL)
    403 			continue;
    404 		rval |= zsc_intr_hard(zsc);
    405 		softreq |= zsc->zsc_cs[0]->cs_softreq;
    406 		softreq |= zsc->zsc_cs[1]->cs_softreq;
    407 	}
    408 
    409 	/* We are at splzs here, so no need to lock. */
    410 	if (softreq && (zssoftpending == 0)) {
    411 		zssoftpending = ZSSOFT_PRI;
    412 		isr_soft_request(ZSSOFT_PRI);
    413 	}
    414 	return (rval);
    415 }
    416 
    417 /*
    418  * Similar scheme as for zshard (look at all of them)
    419  */
    420 static int
    421 zssoft(arg)
    422 	void *arg;
    423 {
    424 	register struct zsc_softc *zsc;
    425 	register int s, unit;
    426 
    427 	/* This is not the only ISR on this IPL. */
    428 	if (zssoftpending == 0)
    429 		return (0);
    430 
    431 	/*
    432 	 * The soft intr. bit will be set by zshard only if
    433 	 * the variable zssoftpending is zero.  The order of
    434 	 * these next two statements prevents our clearing
    435 	 * the soft intr bit just after zshard has set it.
    436 	 */
    437 	isr_soft_clear(ZSSOFT_PRI);
    438 	zssoftpending = 0;
    439 
    440 	/* Make sure we call the tty layer at spltty. */
    441 	s = spltty();
    442 	for (unit = 0; unit < zsc_cd.cd_ndevs; unit++) {
    443 		zsc = zsc_cd.cd_devs[unit];
    444 		if (zsc == NULL)
    445 			continue;
    446 		(void) zsc_intr_soft(zsc);
    447 	}
    448 	splx(s);
    449 	return (1);
    450 }
    451 
    452 
    453 /*
    454  * Compute the current baud rate given a ZS channel.
    455  */
    456 static int
    457 zs_get_speed(cs)
    458 	struct zs_chanstate *cs;
    459 {
    460 	int tconst;
    461 
    462 	tconst = zs_read_reg(cs, 12);
    463 	tconst |= zs_read_reg(cs, 13) << 8;
    464 	return (TCONST_TO_BPS(cs->cs_brg_clk, tconst));
    465 }
    466 
    467 /*
    468  * MD functions for setting the baud rate and control modes.
    469  */
    470 int
    471 zs_set_speed(cs, bps)
    472 	struct zs_chanstate *cs;
    473 	int bps;	/* bits per second */
    474 {
    475 	int tconst, real_bps;
    476 
    477 	if (bps == 0)
    478 		return (0);
    479 
    480 #ifdef	DIAGNOSTIC
    481 	if (cs->cs_brg_clk == 0)
    482 		panic("zs_set_speed");
    483 #endif
    484 
    485 	tconst = BPS_TO_TCONST(cs->cs_brg_clk, bps);
    486 	if (tconst < 0)
    487 		return (EINVAL);
    488 
    489 	/* Convert back to make sure we can do it. */
    490 	real_bps = TCONST_TO_BPS(cs->cs_brg_clk, tconst);
    491 
    492 	/* XXX - Allow some tolerance here? */
    493 	if (real_bps != bps)
    494 		return (EINVAL);
    495 
    496 	cs->cs_preg[12] = tconst;
    497 	cs->cs_preg[13] = tconst >> 8;
    498 
    499 	/* Caller will stuff the pending registers. */
    500 	return (0);
    501 }
    502 
    503 int
    504 zs_set_modes(cs, cflag)
    505 	struct zs_chanstate *cs;
    506 	int cflag;	/* bits per second */
    507 {
    508 	int s;
    509 
    510 	/*
    511 	 * Output hardware flow control on the chip is horrendous:
    512 	 * if carrier detect drops, the receiver is disabled, and if
    513 	 * CTS drops, the transmitter is stoped IN MID CHARACTER!
    514 	 * Therefore, NEVER set the HFC bit, and instead use the
    515 	 * status interrupt to detect CTS changes.
    516 	 */
    517 	s = splzs();
    518 #if 0	/* XXX - See below. */
    519 	if (cflag & CLOCAL) {
    520 		cs->cs_rr0_dcd = 0;
    521 		cs->cs_preg[15] &= ~ZSWR15_DCD_IE;
    522 	} else {
    523 		/* XXX - Need to notice DCD change here... */
    524 		cs->cs_rr0_dcd = ZSRR0_DCD;
    525 		cs->cs_preg[15] |= ZSWR15_DCD_IE;
    526 	}
    527 #endif	/* XXX */
    528 	if (cflag & CRTSCTS) {
    529 		cs->cs_wr5_dtr = ZSWR5_DTR;
    530 		cs->cs_wr5_rts = ZSWR5_RTS;
    531 		cs->cs_rr0_cts = ZSRR0_CTS;
    532 		cs->cs_preg[15] |= ZSWR15_CTS_IE;
    533 	} else {
    534 		cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
    535 		cs->cs_wr5_rts = 0;
    536 		cs->cs_rr0_cts = 0;
    537 		cs->cs_preg[15] &= ~ZSWR15_CTS_IE;
    538 	}
    539 	splx(s);
    540 
    541 	/* Caller will stuff the pending registers. */
    542 	return (0);
    543 }
    544 
    545 
    546 /*
    547  * Read or write the chip with suitable delays.
    548  */
    549 
    550 u_char
    551 zs_read_reg(cs, reg)
    552 	struct zs_chanstate *cs;
    553 	u_char reg;
    554 {
    555 	u_char val;
    556 
    557 	*cs->cs_reg_csr = reg;
    558 	ZS_DELAY();
    559 	val = *cs->cs_reg_csr;
    560 	ZS_DELAY();
    561 	return val;
    562 }
    563 
    564 void
    565 zs_write_reg(cs, reg, val)
    566 	struct zs_chanstate *cs;
    567 	u_char reg, val;
    568 {
    569 	*cs->cs_reg_csr = reg;
    570 	ZS_DELAY();
    571 	*cs->cs_reg_csr = val;
    572 	ZS_DELAY();
    573 }
    574 
    575 u_char zs_read_csr(cs)
    576 	struct zs_chanstate *cs;
    577 {
    578 	register u_char val;
    579 
    580 	val = *cs->cs_reg_csr;
    581 	ZS_DELAY();
    582 	return val;
    583 }
    584 
    585 void  zs_write_csr(cs, val)
    586 	struct zs_chanstate *cs;
    587 	u_char val;
    588 {
    589 	*cs->cs_reg_csr = val;
    590 	ZS_DELAY();
    591 }
    592 
    593 u_char zs_read_data(cs)
    594 	struct zs_chanstate *cs;
    595 {
    596 	register u_char val;
    597 
    598 	val = *cs->cs_reg_data;
    599 	ZS_DELAY();
    600 	return val;
    601 }
    602 
    603 void  zs_write_data(cs, val)
    604 	struct zs_chanstate *cs;
    605 	u_char val;
    606 {
    607 	*cs->cs_reg_data = val;
    608 	ZS_DELAY();
    609 }
    610 
    611 /****************************************************************
    612  * Console support functions (Sun3 specific!)
    613  * Note: this code is allowed to know about the layout of
    614  * the chip registers, and uses that to keep things simple.
    615  * XXX - I think I like the mvme167 code better. -gwr
    616  ****************************************************************/
    617 
    618 void *zs_conschan;
    619 
    620 /*
    621  * Handle user request to enter kernel debugger.
    622  */
    623 void
    624 zs_abort(cs)
    625 	struct zs_chanstate *cs;
    626 {
    627 	register volatile struct zschan *zc = zs_conschan;
    628 	int rr0;
    629 
    630 	/* Wait for end of break to avoid PROM abort. */
    631 	/* XXX - Limit the wait? */
    632 	do {
    633 		rr0 = zc->zc_csr;
    634 		ZS_DELAY();
    635 	} while (rr0 & ZSRR0_BREAK);
    636 
    637 	/* This is always available on the Sun3. */
    638 	Debugger();
    639 }
    640 
    641 /*
    642  * Polled input char.
    643  */
    644 int
    645 zs_getc(arg)
    646 	void *arg;
    647 {
    648 	register volatile struct zschan *zc = arg;
    649 	register int s, c, rr0;
    650 
    651 	s = splhigh();
    652 	/* Wait for a character to arrive. */
    653 	do {
    654 		rr0 = zc->zc_csr;
    655 		ZS_DELAY();
    656 	} while ((rr0 & ZSRR0_RX_READY) == 0);
    657 
    658 	c = zc->zc_data;
    659 	ZS_DELAY();
    660 	splx(s);
    661 
    662 	/*
    663 	 * This is used by the kd driver to read scan codes,
    664 	 * so don't translate '\r' ==> '\n' here...
    665 	 */
    666 	return (c);
    667 }
    668 
    669 /*
    670  * Polled output char.
    671  */
    672 void
    673 zs_putc(arg, c)
    674 	void *arg;
    675 	int c;
    676 {
    677 	register volatile struct zschan *zc = arg;
    678 	register int s, rr0;
    679 
    680 	s = splhigh();
    681 	/* Wait for transmitter to become ready. */
    682 	do {
    683 		rr0 = zc->zc_csr;
    684 		ZS_DELAY();
    685 	} while ((rr0 & ZSRR0_TX_READY) == 0);
    686 
    687 	zc->zc_data = c;
    688 	ZS_DELAY();
    689 	splx(s);
    690 }
    691 
    692 /*****************************************************************/
    693 
    694 static void zscninit __P((struct consdev *));
    695 static int  zscngetc __P((dev_t));
    696 static void zscnputc __P((dev_t, int));
    697 
    698 /*
    699  * Console table shared by ttya, ttyb
    700  */
    701 struct consdev consdev_tty = {
    702 	nullcnprobe,
    703 	zscninit,
    704 	zscngetc,
    705 	zscnputc,
    706 	nullcnpollc,
    707 };
    708 
    709 static void
    710 zscninit(cn)
    711 	struct consdev *cn;
    712 {
    713 }
    714 
    715 /*
    716  * Polled console input putchar.
    717  */
    718 static int
    719 zscngetc(dev)
    720 	dev_t dev;
    721 {
    722 	return (zs_getc(zs_conschan));
    723 }
    724 
    725 /*
    726  * Polled console output putchar.
    727  */
    728 static void
    729 zscnputc(dev, c)
    730 	dev_t dev;
    731 	int c;
    732 {
    733 	zs_putc(zs_conschan, c);
    734 }
    735 
    736 /*****************************************************************/
    737 
    738 static void prom_cninit __P((struct consdev *));
    739 static int  prom_cngetc __P((dev_t));
    740 static void prom_cnputc __P((dev_t, int));
    741 
    742 /*
    743  * The console is set to this one initially,
    744  * which lets us use the PROM until consinit()
    745  * is called to select a real console.
    746  */
    747 struct consdev consdev_prom = {
    748 	nullcnprobe,
    749 	prom_cninit,
    750 	prom_cngetc,
    751 	prom_cnputc,
    752 	nullcnpollc,
    753 };
    754 
    755 /*
    756  * The console table pointer is statically initialized
    757  * to point to the PROM (output only) table, so that
    758  * early calls to printf will work.
    759  */
    760 struct consdev *cn_tab = &consdev_prom;
    761 
    762 void
    763 nullcnprobe(cn)
    764 	struct consdev *cn;
    765 {
    766 }
    767 
    768 static void
    769 prom_cninit(cn)
    770 	struct consdev *cn;
    771 {
    772 }
    773 
    774 /*
    775  * PROM console input putchar.
    776  * (dummy - this is output only)
    777  */
    778 static int
    779 prom_cngetc(dev)
    780 	dev_t dev;
    781 {
    782 	return (0);
    783 }
    784 
    785 /*
    786  * PROM console output putchar.
    787  */
    788 static void
    789 prom_cnputc(dev, c)
    790 	dev_t dev;
    791 	int c;
    792 {
    793 	(*romVectorPtr->putChar)(c & 0x7f);
    794 }
    795 
    796 /*****************************************************************/
    797 
    798 extern struct consdev consdev_kd;
    799 
    800 static struct {
    801 	int zs_unit, channel;
    802 } zstty_conf[NZS*2] = {
    803 	/* XXX: knowledge from the config file here... */
    804 	{ 1, 0 },	/* ttya */
    805 	{ 1, 1 },	/* ttyb */
    806 	{ 0, 0 },	/* ttyc */
    807 	{ 0, 1 },	/* ttyd */
    808 };
    809 
    810 static char *prom_inSrc_name[] = {
    811 	"keyboard/display",
    812 	"ttya", "ttyb",
    813 	"ttyc", "ttyd" };
    814 
    815 /*
    816  * This function replaces sys/dev/cninit.c
    817  * Determine which device is the console using
    818  * the PROM "input source" and "output sink".
    819  */
    820 void
    821 cninit()
    822 {
    823 	MachMonRomVector *v;
    824 	struct zschan *zc;
    825 	struct consdev *cn;
    826 	int channel, zs_unit, zstty_unit;
    827 	u_char inSource, outSink;
    828 
    829 	v = romVectorPtr;
    830 	inSource = *v->inSource;
    831 	outSink  = *v->outSink;
    832 	if (inSource != outSink) {
    833 		mon_printf("cninit: mismatched PROM output selector\n");
    834 	}
    835 
    836 	switch (inSource) {
    837 	default:
    838 		mon_printf("cninit: invalid inSource=%d\n", inSource);
    839 		sunmon_abort();
    840 		inSource = 0;
    841 		/* fall through */
    842 
    843 	case 0:	/* keyboard/display */
    844 #if NKBD > 0
    845 		zs_unit = 0;
    846 		channel = 0;
    847 		cn = &consdev_kd;
    848 		/* Set cn_dev, cn_pri in kd.c */
    849 		break;
    850 #else	/* NKBD */
    851 		mon_printf("cninit: kdb/display not configured\n");
    852 		sunmon_abort();
    853 		inSource = 1;
    854 		/* fall through */
    855 #endif	/* NKBD */
    856 
    857 	case 1:	/* ttya */
    858 	case 2:	/* ttyb */
    859 	case 3:	/* ttyc (rewired keyboard connector) */
    860 	case 4:	/* ttyd (rewired mouse connector)   */
    861 		zstty_unit = inSource - 1;
    862 		zs_unit = zstty_conf[zstty_unit].zs_unit;
    863 		channel = zstty_conf[zstty_unit].channel;
    864 		cn = &consdev_tty;
    865 		cn->cn_dev = makedev(zs_major, zstty_unit);
    866 		cn->cn_pri = CN_REMOTE;
    867 		break;
    868 
    869 	}
    870 	/* Now that inSource has been validated, print it. */
    871 	mon_printf("console is %s\n", prom_inSrc_name[inSource]);
    872 
    873 	zc = zs_get_chan_addr(zs_unit, channel);
    874 	if (zc == NULL) {
    875 		mon_printf("cninit: zs not mapped.\n");
    876 		return;
    877 	}
    878 	zs_conschan = zc;
    879 	zs_hwflags[zs_unit][channel] = ZS_HWFLAG_CONSOLE;
    880 	cn_tab = cn;
    881 	(*cn->cn_init)(cn);
    882 #ifdef	KGDB
    883 	zs_kgdb_init();
    884 #endif
    885 }
    886