xref: /netbsd-src/sys/arch/sgimips/dev/zs.c (revision 37b34d511dea595d3ba03a661cf3b775038ea5f8)
1 /*	$NetBSD: zs.c,v 1.16 2002/10/02 15:52:33 thorpej Exp $	*/
2 
3 /*-
4  * Copyright (c) 1996, 2000 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 and Wayne Knowles
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  */
45 
46 #include "opt_ddb.h"
47 #include "opt_kgdb.h"
48 
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/conf.h>
52 #include <sys/device.h>
53 #include <sys/file.h>
54 #include <sys/ioctl.h>
55 #include <sys/kernel.h>
56 #include <sys/proc.h>
57 #include <sys/tty.h>
58 #include <sys/time.h>
59 #include <sys/syslog.h>
60 
61 #include <machine/cpu.h>
62 #include <machine/intr.h>
63 #include <machine/autoconf.h>
64 #include <machine/z8530var.h>
65 
66 #include <dev/cons.h>
67 #include <dev/ic/z8530reg.h>
68 
69 #include <sgimips/hpc/hpcvar.h>
70 #include <sgimips/hpc/hpcreg.h>
71 
72 #include <dev/arcbios/arcbios.h>
73 #include <dev/arcbios/arcbiosvar.h>
74 
75 /*
76  * Some warts needed by z8530tty.c -
77  * The default parity REALLY needs to be the same as the PROM uses,
78  * or you can not see messages done with printf during boot-up...
79  */
80 int zs_def_cflag = (CREAD | CS8 | HUPCL);
81 
82 #define PCLK		3672000	 /* PCLK pin input clock rate */
83 
84 #ifndef ZS_DEFSPEED
85 #define ZS_DEFSPEED	9600
86 #endif
87 
88 /*
89  * Define interrupt levels.
90  */
91 #define ZSHARD_PRI 64
92 
93 /* SGI shouldn't need ZS_DELAY() as recovery time is done in hardware? */
94 #define ZS_DELAY()	delay(3)
95 
96 /* The layout of this is hardware-dependent (padding, order). */
97 struct zschan {
98 	u_char   pad1[3];
99 	volatile u_char	zc_csr;		/* ctrl,status, and indirect access */
100 	u_char   pad2[3];
101 	volatile u_char	zc_data;	/* data */
102 };
103 
104 struct zsdevice {
105 	struct	zschan zs_chan_b;
106 	struct	zschan zs_chan_a;
107 };
108 
109 /* Return the byte offset of element within a structure */
110 #define OFFSET(struct_def, el)		((size_t)&((struct_def *)0)->el)
111 
112 #define ZS_CHAN_A	OFFSET(struct zsdevice, zs_chan_a)
113 #define ZS_CHAN_B	OFFSET(struct zsdevice, zs_chan_b)
114 #define ZS_REG_CSR	0
115 #define ZS_REG_DATA	1
116 static int zs_chan_offset[] = {ZS_CHAN_A, ZS_CHAN_B};
117 
118 static void zscnprobe __P((struct consdev *));
119 static void zscninit __P((struct consdev *));
120 static int  zscngetc __P((dev_t));
121 static void zscnputc __P((dev_t, int));
122 static void zscnpollc __P((dev_t, int));
123 
124 static int  cons_port;
125 
126 struct consdev zs_cn = {
127 	zscnprobe,
128 	zscninit,
129 	zscngetc,
130 	zscnputc,
131 	zscnpollc
132 };
133 
134 /* Flags from cninit() */
135 static int zs_consunit = -1;
136 static int zs_conschan = -1;
137 
138 /* Default speed for all channels */
139 static int zs_defspeed = ZS_DEFSPEED;
140 static volatile int zssoftpending;
141 
142 static u_char zs_init_reg[16] = {
143 	0,				/* 0: CMD (reset, etc.) */
144 	0,				/* 1: No interrupts yet. */
145 	ZSHARD_PRI,			/* 2: IVECT */
146 	ZSWR3_RX_8 | ZSWR3_RX_ENABLE,
147 	ZSWR4_CLK_X16 | ZSWR4_ONESB,
148 	ZSWR5_TX_8 | ZSWR5_TX_ENABLE,
149 	0,				/* 6: TXSYNC/SYNCLO */
150 	0,				/* 7: RXSYNC/SYNCHI */
151 	0,				/* 8: alias for data port */
152 	ZSWR9_MASTER_IE,
153 	0,				/*10: Misc. TX/RX control bits */
154 	ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD | ZSWR11_TRXC_OUT_ENA,
155 	BPS_TO_TCONST(PCLK/16, ZS_DEFSPEED), /*12: BAUDLO (default=9600) */
156 	0,				/*13: BAUDHI (default=9600) */
157 	ZSWR14_BAUD_ENA,
158 	ZSWR15_BREAK_IE,
159 };
160 
161 
162 /****************************************************************
163  * Autoconfig
164  ****************************************************************/
165 
166 /* Definition of the driver for autoconfig. */
167 static int	zs_hpc_match __P((struct device *, struct cfdata *, void *));
168 static void	zs_hpc_attach __P((struct device *, struct device *, void *));
169 static int	zs_print __P((void *, const char *name));
170 
171 CFATTACH_DECL(zsc_hpc, sizeof(struct zsc_softc),
172     zs_hpc_match, zs_hpc_attach, NULL, NULL);
173 
174 extern struct	cfdriver zsc_cd;
175 
176 static int	zshard __P((void *));
177 void		zssoft __P((void *));
178 static int	zs_get_speed __P((struct zs_chanstate *));
179 struct		zschan *zs_get_chan_addr (int zs_unit, int channel);
180 int		zs_getc __P((void *));
181 void		zs_putc __P((void *, int));
182 
183 /*
184  * Is the zs chip present?
185  */
186 static int
187 zs_hpc_match(parent, cf, aux)
188 	struct device *parent;
189 	struct cfdata *cf;
190 	void *aux;
191 {
192 	struct hpc_attach_args *ha = aux;
193 
194 	if (strcmp(ha->ha_name, cf->cf_name) == 0)
195 		return (1);
196 
197 	return (0);
198 }
199 
200 /*
201  * Attach a found zs.
202  *
203  * Match slave number to zs unit number, so that misconfiguration will
204  * not set up the keyboard as ttya, etc.
205  */
206 static void
207 zs_hpc_attach(parent, self, aux)
208 	struct device *parent;
209 	struct device *self;
210 	void *aux;
211 {
212 	struct zsc_softc *zsc = (void *) self;
213 	struct hpc_attach_args *haa = aux;
214 	struct zsc_attach_args zsc_args;
215 	struct zs_chanstate *cs;
216 	struct zs_channel *ch;
217 	int    zs_unit, channel, err, s;
218 	char  *promconsdev;
219 
220 	promconsdev = ARCBIOS->GetEnvironmentVariable("ConsoleOut");
221 
222 	zsc->zsc_bustag = haa->ha_st;
223 	if ((err = bus_space_subregion(haa->ha_st, haa->ha_sh,
224 				       haa->ha_devoff, 0x10,
225 				       &zsc->zsc_base)) != 0) {
226 		printf(": unable to map 85c30 registers, error = %d\n", err);
227 		return;
228 	}
229 
230 	zs_unit = zsc->zsc_dev.dv_unit;
231 	printf("\n");
232 
233 	/*
234 	 * Initialize software state for each channel.
235 	 *
236 	 * Done in reverse order of channels since the first serial port
237 	 * is actually attached to the *second* channel, and vice versa.
238 	 * Doing it this way should force a 'zstty*' to attach zstty0 to
239 	 * channel 1 and zstty1 to channel 0.  They couldn't have wired
240 	 * it up in a more sensible fashion, could they?
241 	 */
242 	for (channel = 1; channel >= 0; channel--) {
243 		zsc_args.channel = channel;
244 		ch = &zsc->zsc_cs_store[channel];
245 		cs = zsc->zsc_cs[channel] = (struct zs_chanstate *)ch;
246 
247 		cs->cs_reg_csr = NULL;
248 		cs->cs_reg_data = NULL;
249 		cs->cs_channel = channel;
250 		cs->cs_private = NULL;
251 		cs->cs_ops = &zsops_null;
252 		cs->cs_brg_clk = PCLK / 16;
253 
254 		if (bus_space_subregion(zsc->zsc_bustag, zsc->zsc_base,
255 					zs_chan_offset[channel],
256 					sizeof(struct zschan),
257 					&ch->cs_regs) != 0) {
258 			printf(": cannot map regs\n");
259 			return;
260 		}
261 		ch->cs_bustag = zsc->zsc_bustag;
262 
263 		memcpy(cs->cs_creg, zs_init_reg, 16);
264 		memcpy(cs->cs_preg, zs_init_reg, 16);
265 
266 		zsc_args.hwflags = 0;
267 		zsc_args.consdev = NULL;
268 
269 		if (zs_consunit == -1 && zs_conschan == -1) {
270 		    /*
271 		     * If this channel is being used by the PROM console,
272 		     * pass the generic zs driver a 'no reset' flag so the
273 		     * channel gets left in the appropriate state after
274 		     * attach.
275 		     *
276 		     * Note: the channel mappings are swapped.
277 		     */
278 		    if (promconsdev != NULL &&
279 			strlen(promconsdev) == 9 &&
280 			strncmp(promconsdev, "serial", 6) == 0 &&
281 			(promconsdev[7] == '0' || promconsdev[7] == '1')) {
282 			if (promconsdev[7] == '1' && channel == 0)
283 			    zsc_args.hwflags |= ZS_HWFLAG_NORESET;
284 			else if (promconsdev[7] == '0' && channel == 1)
285 			    zsc_args.hwflags |= ZS_HWFLAG_NORESET;
286 		    }
287 		}
288 
289 		/* If console, don't stomp speed, let zstty know */
290 		if (zs_unit == zs_consunit && channel == zs_conschan) {
291 			zsc_args.consdev = &zs_cn;
292 			zsc_args.hwflags = ZS_HWFLAG_CONSOLE;
293 
294 			cs->cs_defspeed = zs_get_speed(cs);
295 		} else
296 			cs->cs_defspeed = zs_defspeed;
297 
298 		cs->cs_defcflag = zs_def_cflag;
299 
300 		/* Make these correspond to cs_defcflag (-crtscts) */
301 		cs->cs_rr0_dcd = ZSRR0_DCD;
302 		cs->cs_rr0_cts = 0;
303 		cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
304 		cs->cs_wr5_rts = 0;
305 
306 		/*
307 		 * Clear the master interrupt enable.
308 		 * The INTENA is common to both channels,
309 		 * so just do it on the A channel.
310 		 */
311 		if (channel == 0) {
312 			zs_write_reg(cs, 9, 0);
313 		}
314 		/*
315 		 * Look for a child driver for this channel.
316 		 * The child attach will setup the hardware.
317 		 */
318 		if (!config_found(self, (void *)&zsc_args, zs_print)) {
319 			/* No sub-driver.  Just reset it. */
320 			u_char reset = (channel == 0) ?
321 				ZSWR9_A_RESET : ZSWR9_B_RESET;
322 
323 			s = splhigh();
324  			zs_write_reg(cs, 9, reset);
325 			splx(s);
326 		}
327 	}
328 
329 
330 	zsc->sc_si = softintr_establish(IPL_SOFTSERIAL, zssoft, zsc);
331 	cpu_intr_establish(haa->ha_irq, IPL_TTY, zshard, NULL);
332 
333 	evcnt_attach_dynamic(&zsc->zsc_intrcnt, EVCNT_TYPE_INTR, NULL,
334 			     self->dv_xname, "intr");
335 
336 	/*
337 	 * Set the master interrupt enable and interrupt vector.
338 	 * (common to both channels, do it on A)
339 	 */
340 	cs = zsc->zsc_cs[0];
341 	s = splhigh();
342 	/* interrupt vector */
343 	zs_write_reg(cs, 2, zs_init_reg[2]);
344 	/* master interrupt control (enable) */
345 	zs_write_reg(cs, 9, zs_init_reg[9]);
346 	splx(s);
347 }
348 
349 static int
350 zs_print(aux, name)
351 	void *aux;
352 	const char *name;
353 {
354 	struct zsc_attach_args *args = aux;
355 
356 	if (name != NULL)
357 		printf("%s: ", name);
358 
359 	if (args->channel != -1)
360 		printf(" channel %d", args->channel);
361 
362 	return UNCONF;
363 }
364 
365 /*
366  * Our ZS chips all share a common, autovectored interrupt,
367  * so we have to look at all of them on each interrupt.
368  */
369 static int
370 zshard(arg)
371 	void *arg;
372 {
373 	register struct zsc_softc *zsc;
374 	register int rr3, unit, rval, softreq;
375 
376 	rval = 0;
377 	for (unit = 0; unit < zsc_cd.cd_ndevs; unit++) {
378 		zsc = zsc_cd.cd_devs[unit];
379 		if (zsc == NULL)
380 			continue;
381 
382 		zsc->zsc_intrcnt.ev_count++;
383 		while ((rr3 = zsc_intr_hard(zsc))) {
384 			rval |= rr3;
385 		}
386 
387 		softreq = zsc->zsc_cs[0]->cs_softreq;
388 		softreq |= zsc->zsc_cs[1]->cs_softreq;
389 		if (softreq && (zssoftpending == 0)) {
390 			zssoftpending = 1;
391 			softintr_schedule(zsc->sc_si);
392 		}
393 	}
394 	return rval;
395 }
396 
397 /*
398  * Similar scheme as for zshard (look at all of them)
399  */
400 void
401 zssoft(arg)
402 	void *arg;
403 {
404 	register struct zsc_softc *zsc;
405 	register int s, unit;
406 
407 	/* This is not the only ISR on this IPL. */
408 	if (zssoftpending == 0)
409 		return;
410 
411 	/*
412 	 * The soft intr. bit will be set by zshard only if
413 	 * the variable zssoftpending is zero.  The order of
414 	 * these next two statements prevents our clearing
415 	 * the soft intr bit just after zshard has set it.
416 	 */
417 	/*isr_soft_clear(ZSSOFT_PRI);*/
418 	zssoftpending = 0;
419 
420 	/* Make sure we call the tty layer at spltty. */
421 	s = spltty();
422 	for (unit = 0; unit < zsc_cd.cd_ndevs; unit++) {
423 		zsc = zsc_cd.cd_devs[unit];
424 		if (zsc == NULL)
425 			continue;
426 		(void) zsc_intr_soft(zsc);
427 	}
428 	splx(s);
429 	return;
430 }
431 
432 
433 /*
434  * Compute the current baud rate given a ZS channel.
435  */
436 static int
437 zs_get_speed(cs)
438 	struct zs_chanstate *cs;
439 {
440 	int tconst;
441 
442 	tconst = zs_read_reg(cs, 12);
443 	tconst |= zs_read_reg(cs, 13) << 8;
444 	return (TCONST_TO_BPS(cs->cs_brg_clk, tconst));
445 }
446 
447 /*
448  * MD functions for setting the baud rate and control modes.
449  */
450 int
451 zs_set_speed(cs, bps)
452 	struct zs_chanstate *cs;
453 	int bps;	/* bits per second */
454 {
455 	int tconst, real_bps;
456 
457 #if 0
458 	while (!(zs_read_csr(cs) & ZSRR0_TX_READY))
459 		{/*nop*/}
460 #endif
461 	/* Wait for transmit buffer to empty */
462 	if (bps == 0) {
463 		return (0);
464 	}
465 
466 #ifdef	DIAGNOSTIC
467 	if (cs->cs_brg_clk == 0)
468 		panic("zs_set_speed");
469 #endif
470 
471 	tconst = BPS_TO_TCONST(cs->cs_brg_clk, bps);
472 	if (tconst < 0)
473 		return (EINVAL);
474 
475 	/* Convert back to make sure we can do it. */
476 	real_bps = TCONST_TO_BPS(cs->cs_brg_clk, tconst);
477 
478 	/* XXX - Allow some tolerance here? */
479 #if 0
480 	if (real_bps != bps)
481 		return (EINVAL);
482 #endif
483 
484 	cs->cs_preg[12] = tconst;
485 	cs->cs_preg[13] = tconst >> 8;
486 
487 	/* Caller will stuff the pending registers. */
488 	return (0);
489 }
490 
491 int
492 zs_set_modes(cs, cflag)
493 	struct zs_chanstate *cs;
494 	int cflag;	/* bits per second */
495 {
496 	int s;
497 
498 	/*
499 	 * Output hardware flow control on the chip is horrendous:
500 	 * if carrier detect drops, the receiver is disabled, and if
501 	 * CTS drops, the transmitter is stoped IN MID CHARACTER!
502 	 * Therefore, NEVER set the HFC bit, and instead use the
503 	 * status interrupt to detect CTS changes.
504 	 */
505 	s = splzs();
506 	cs->cs_rr0_pps = 0;
507 	if ((cflag & (CLOCAL | MDMBUF)) != 0) {
508 		cs->cs_rr0_dcd = 0;
509 		if ((cflag & MDMBUF) == 0)
510 			cs->cs_rr0_pps = ZSRR0_DCD;
511 	} else
512 		cs->cs_rr0_dcd = ZSRR0_DCD;
513 	if ((cflag & CRTSCTS) != 0) {
514 		cs->cs_wr5_dtr = ZSWR5_DTR;
515 		cs->cs_wr5_rts = ZSWR5_RTS;
516 		cs->cs_rr0_cts = ZSRR0_CTS;
517 	} else if ((cflag & MDMBUF) != 0) {
518 		cs->cs_wr5_dtr = 0;
519 		cs->cs_wr5_rts = ZSWR5_DTR;
520 		cs->cs_rr0_cts = ZSRR0_DCD;
521 	} else {
522 		cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
523 		cs->cs_wr5_rts = 0;
524 		cs->cs_rr0_cts = 0;
525 	}
526 	splx(s);
527 
528 	/* Caller will stuff the pending registers. */
529 	return (0);
530 }
531 
532 
533 /*
534  * Read or write the chip with suitable delays.
535  */
536 
537 u_char
538 zs_read_reg(cs, reg)
539 	struct zs_chanstate *cs;
540 	u_char reg;
541 {
542 	u_char val;
543 	struct zs_channel *zsc = (struct zs_channel *)cs;
544 
545 	bus_space_write_1(zsc->cs_bustag, zsc->cs_regs, ZS_REG_CSR, reg);
546 	ZS_DELAY();
547 	val = bus_space_read_1(zsc->cs_bustag, zsc->cs_regs, ZS_REG_CSR);
548 	ZS_DELAY();
549 	return val;
550 }
551 
552 void
553 zs_write_reg(cs, reg, val)
554 	struct zs_chanstate *cs;
555 	u_char reg, val;
556 {
557 	struct zs_channel *zsc = (struct zs_channel *)cs;
558 
559 	bus_space_write_1(zsc->cs_bustag, zsc->cs_regs, ZS_REG_CSR, reg);
560 	ZS_DELAY();
561 	bus_space_write_1(zsc->cs_bustag, zsc->cs_regs, ZS_REG_CSR, val);
562 	ZS_DELAY();
563 }
564 
565 u_char
566 zs_read_csr(cs)
567 	struct zs_chanstate *cs;
568 {
569 	struct zs_channel *zsc = (struct zs_channel *)cs;
570 	register u_char val;
571 
572 	val = bus_space_read_1(zsc->cs_bustag, zsc->cs_regs, ZS_REG_CSR);
573 	ZS_DELAY();
574 	return val;
575 }
576 
577 void
578 zs_write_csr(cs, val)
579 	struct zs_chanstate *cs;
580 	u_char val;
581 {
582 	struct zs_channel *zsc = (struct zs_channel *)cs;
583 
584 	bus_space_write_1(zsc->cs_bustag, zsc->cs_regs, ZS_REG_CSR, val);
585 	ZS_DELAY();
586 }
587 
588 u_char
589 zs_read_data(cs)
590 	struct zs_chanstate *cs;
591 {
592 	struct zs_channel *zsc = (struct zs_channel *)cs;
593 	register u_char val;
594 
595 	val = bus_space_read_1(zsc->cs_bustag, zsc->cs_regs, ZS_REG_DATA);
596 	ZS_DELAY();
597 	return val;
598 }
599 
600 void
601 zs_write_data(cs, val)
602 	struct zs_chanstate *cs;
603 	u_char val;
604 {
605 	struct zs_channel *zsc = (struct zs_channel *)cs;
606 
607 	bus_space_write_1(zsc->cs_bustag, zsc->cs_regs, ZS_REG_DATA, val);
608 	ZS_DELAY();
609 }
610 
611 void
612 zs_abort(cs)
613 	struct zs_chanstate *cs;
614 {
615 #if defined(KGDB)
616 	zskgdb(cs);
617 #elif defined(DDB)
618 	Debugger();
619 #endif
620 }
621 
622 
623 /*********************************************************/
624 /*  Polled character I/O functions for console and KGDB  */
625 /*********************************************************/
626 
627 struct zschan *
628 zs_get_chan_addr(zs_unit, channel)
629 	int zs_unit, channel;
630 {
631 	static int dumped_addr = 0;
632 	struct zsdevice *addr;
633 	struct zschan *zc;
634 
635 	addr = (struct zsdevice *) MIPS_PHYS_TO_KSEG1(0x1fbd9830);
636 
637 	if (channel == 0) {
638 		zc = &addr->zs_chan_b;
639 	} else {
640 		zc = &addr->zs_chan_a;
641 	}
642 
643 	if (dumped_addr == 0) {
644 		dumped_addr++;
645 		printf("zs channel %d had address %p\n", channel, zc);
646 	}
647 
648 	return (zc);
649 }
650 
651 int
652 zs_getc(arg)
653 	void *arg;
654 {
655 	register volatile struct zschan *zc = arg;
656 	register int s, c, rr0;
657 
658 	s = splzs();
659 	/* Wait for a character to arrive. */
660 	do {
661 		rr0 = zc->zc_csr;
662 		ZS_DELAY();
663 	} while ((rr0 & ZSRR0_RX_READY) == 0);
664 
665 	c = zc->zc_data;
666 	ZS_DELAY();
667 	splx(s);
668 
669 	return (c);
670 }
671 
672 /*
673  * Polled output char.
674  */
675 void
676 zs_putc(arg, c)
677 	void *arg;
678 	int c;
679 {
680 	register volatile struct zschan *zc = arg;
681 	register int s, rr0;
682 
683 	s = splzs();
684 	/* Wait for transmitter to become ready. */
685 	do {
686 		rr0 = zc->zc_csr;
687 		ZS_DELAY();
688 	} while ((rr0 & ZSRR0_TX_READY) == 0);
689 
690 	zc->zc_data = c;
691 	wbflush();
692 	ZS_DELAY();
693 	splx(s);
694 }
695 
696 /***************************************************************/
697 void
698 zscnprobe(cn)
699 	struct consdev *cn;
700 {
701 }
702 
703 void
704 zscninit(cn)
705 	struct consdev *cn;
706 {
707 	extern const struct cdevsw zstty_cdevsw;
708 	char* consdev;
709 
710 	if ((consdev = ARCBIOS->GetEnvironmentVariable("ConsoleOut")) == NULL)
711 		panic("zscninit without valid ARCS ConsoleOut setting!");
712 
713 	if (strlen(consdev) != 9 ||
714 	    strncmp(consdev, "serial", 6) != 0)
715 		panic("zscninit with ARCS console not set to serial!");
716 
717 	cons_port = consdev[7] - '0';
718 
719 	cn->cn_dev = makedev(cdevsw_lookup_major(&zstty_cdevsw), cons_port);
720 	cn->cn_pri = CN_REMOTE;
721 
722 	/* Mark this unit as the console */
723 	zs_consunit = 0;
724 
725 	/* SGI hardware wires serial port 1 to channel B, port 2 to A */
726 	if (cons_port == 0)
727 		zs_conschan = 1;
728 	else
729 		zs_conschan = 0;
730 }
731 
732 int
733 zscngetc(dev)
734 	dev_t dev;
735 {
736 	struct zschan *zs;
737 
738 	zs = zs_get_chan_addr(0, cons_port);
739 	return zs_getc(zs);
740 }
741 
742 void
743 zscnputc(dev, c)
744 	dev_t dev;
745 	int c;
746 {
747 	struct zschan *zs;
748 
749 	zs = zs_get_chan_addr(0, cons_port);
750 	zs_putc(zs, c);
751 }
752 
753 void
754 zscnpollc(dev, on)
755 	dev_t dev;
756 	int on;
757 {
758 }
759