zs.c revision 1.3 1 /* $NetBSD: zs.c,v 1.3 1996/06/07 00:15:30 briggs Exp $ */
2
3 /*
4 * Copyright (c) 1995 Gordon W. Ross
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 * 4. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by Gordon Ross
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 /*
34 * Zilog Z8530 Dual UART driver (machine-dependent part)
35 *
36 * Runs two serial lines per chip using slave drivers.
37 * Plain tty/async lines use the zs_async slave.
38 * Sun keyboard/mouse uses the zs_kbd/zs_ms slaves.
39 */
40
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/proc.h>
44 #include <sys/device.h>
45 #include <sys/conf.h>
46 #include <sys/file.h>
47 #include <sys/ioctl.h>
48 #include <sys/tty.h>
49 #include <sys/time.h>
50 #include <sys/kernel.h>
51 #include <sys/syslog.h>
52
53 #include <dev/cons.h>
54 #include "z8530reg.h"
55 #include <machine/z8530var.h>
56
57 #include <machine/autoconf.h>
58 #include <machine/cpu.h>
59
60 /*
61 * XXX: Hard code this to make console init easier...
62 */
63 #define NZSC 1 /* XXX */
64
65 /*
66 * Define interrupt levels.
67 */
68 #define ZSHARD_PRI 6 /* Wired on the CPU board... */
69 #define ZSSOFT_PRI 3 /* Want tty pri (4) but this is OK. */
70
71 /* The layout of this is hardware-dependent (padding, order). */
72 struct zschan {
73 volatile u_char zc_csr; /* ctrl,status, and indirect access */
74 u_char zc_xxx0;
75 u_char zc_xxx1;
76 u_char zc_xxx2;
77 volatile u_char zc_data; /* data */
78 u_char zc_xxx3;
79 u_char zc_xxx4;
80 u_char zc_xxx5;
81 };
82 /*
83 * The zsdevice structure is not used on the mac68k port as the
84 * chip is wired up weird. Channel B & A are interspursed with
85 * the data & control bytes
86 struct zsdevice {
87 /! Yes, they are backwards. !/
88 struct zschan zs_chan_b;
89 struct zschan zs_chan_a;
90 };
91 */
92
93 /* Saved PROM mappings */
94 static char *zsaddr[NZSC]; /* See zs_init() */
95 /* Flags from cninit() */
96 static int zs_hwflags[NZSC][2];
97 /* Default speed for each channel */
98 static int zs_defspeed[NZSC][2] = {
99 { 9600, /* tty00 */
100 9600 }, /* tty01 */
101 };
102 /* console stuff */
103 void *zs_conschan = 0;
104 int zs_consunit;
105 /* device that the console is attached to--if serial. */
106 dev_t mac68k_zsdev;
107 /* Mac stuff, some vestages of old mac serial driver here */
108 volatile unsigned char *sccA = 0;
109
110 static struct zschan *zs_get_chan_addr __P((int zsc_unit, int channel));
111 void zs_init __P((void));
112
113 static struct zschan *
114 zs_get_chan_addr(zsc_unit, channel)
115 int zsc_unit, channel;
116 {
117 char *addr;
118 struct zschan *zc;
119
120 if (zsc_unit >= NZSC)
121 return NULL;
122 addr = zsaddr[zsc_unit];
123 if (addr == NULL)
124 return NULL;
125 if (channel == 0) {
126 zc = (struct zschan *)(addr +2);
127 /* handle the fact the ports are intertwined. */
128 } else {
129 zc = (struct zschan *)(addr);
130 }
131 return (zc);
132 }
133
134
135 /* Find PROM mappings (for console support). */
136 static int zsinited = 0; /* 0 = not, 1 = inited, not attached, 2= attached */
137
138 void
139 zs_init()
140 {
141 if ((zsinited == 2)&&(zsaddr[0] != (char *) sccA))
142 panic("Moved zs0 address after attached!");
143 zsaddr[0] = (char *) sccA;
144 zsinited = 1;
145 if (zs_conschan != 0){ /* we might have moved io under the console */
146 zs_conschan = zs_get_chan_addr(0, zs_consunit);
147 /* so recalc the console port */
148 }
149 }
150
151
152 /*
153 * Even though zsparam will set up the clock multiples, etc., we
154 * still set them here as: 1) mice & keyboards don't use zsparam,
155 * and 2) the console stuff uses these defaults before device
156 * attach.
157 */
158
159 static u_char zs_init_reg[16] = {
160 0, /* 0: CMD (reset, etc.) */
161 ZSWR1_RIE | ZSWR1_TIE | ZSWR1_SIE,
162 0x18 + ZSHARD_PRI, /* IVECT */
163 ZSWR3_RX_8 | ZSWR3_RX_ENABLE,
164 ZSWR4_CLK_X16 | ZSWR4_ONESB | ZSWR4_EVENP,
165 ZSWR5_TX_8 | ZSWR5_TX_ENABLE,
166 0, /* 6: TXSYNC/SYNCLO */
167 0, /* 7: RXSYNC/SYNCHI */
168 0, /* 8: alias for data port */
169 ZSWR9_MASTER_IE,
170 0, /*10: Misc. TX/RX control bits */
171 ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD,
172 14, /*12: BAUDLO (default=9600) */
173 0, /*13: BAUDHI (default=9600) */
174 ZSWR14_BAUD_ENA,
175 ZSWR15_BREAK_IE | ZSWR15_DCD_IE | ZSWR15_CTS_IE,
176 };
177
178
179 /****************************************************************
180 * Autoconfig
181 ****************************************************************/
182
183 /* Definition of the driver for autoconfig. */
184 static int zsc_match __P((struct device *, void *, void *));
185 static void zsc_attach __P((struct device *, struct device *, void *));
186 static int zsc_print __P((void *aux, char *name));
187
188 struct cfattach zsc_ca = {
189 sizeof(struct zsc_softc), zsc_match, zsc_attach
190 };
191
192 struct cfdriver zsc_cd = {
193 NULL, "zsc", DV_DULL
194 };
195
196 int zshard __P((void *));
197 int zssoft __P((void *));
198
199
200 /*
201 * Is the zs chip present?
202 */
203 static int
204 zsc_match(parent, vcf, aux)
205 struct device *parent;
206 void *vcf;
207 void *aux;
208 {
209 return 1;
210 }
211
212 static int
213 zsc_print(aux, name)
214 void *aux;
215 char *name;
216 {
217 struct zsc_attach_args *args = aux;
218
219 if (name != NULL)
220 printf("%s: ", name);
221
222 if (args->channel != -1)
223 printf(" channel %d", args->channel);
224
225 return UNCONF;
226 }
227
228 /*
229 * Attach a found zs.
230 *
231 * Match slave number to zs unit number, so that misconfiguration will
232 * not set up the keyboard as ttya, etc.
233 */
234 static void
235 zsc_attach(parent, self, aux)
236 struct device *parent;
237 struct device *self;
238 void *aux;
239 {
240 struct zsc_softc *zsc = (void *) self;
241 struct zsc_attach_args zsc_args;
242 volatile struct zschan *zc;
243 struct zs_chanstate *cs;
244 int zsc_unit, channel;
245 int reset, s, chip;
246
247 if (!zsinited) zs_init();
248 zsinited = 2;
249
250 zsc_unit = zsc->zsc_dev.dv_unit;
251
252 /* Make sure everything's inited ok. */
253 if (zsaddr[zsc_unit] == NULL)
254 panic("zs_attach: zs%d not mapped\n", zsc_unit);
255
256 /*
257 * Initialize software state for each channel.
258 */
259 for (channel = 0; channel < 2; channel++) {
260 cs = &zsc->zsc_cs[channel];
261
262 zc = zs_get_chan_addr(zsc_unit, channel);
263 cs->cs_reg_csr = &zc->zc_csr;
264 cs->cs_reg_data = &zc->zc_data;
265
266 cs->cs_channel = channel;
267 cs->cs_private = NULL;
268 cs->cs_ops = &zsops_null;
269
270 /* Define BAUD rate clock for the MI code. */
271 cs->cs_pclk_div16 = mac68k_machine.sccClkConst*2;
272 cs->cs_csource = 0;
273 cs->cs_psource = 0;
274
275 cs->cs_defspeed = zs_defspeed[zsc_unit][channel];
276
277 bcopy(zs_init_reg, cs->cs_creg, 16);
278 bcopy(zs_init_reg, cs->cs_preg, 16);
279
280 /*
281 * Clear the master interrupt enable.
282 * The INTENA is common to both channels,
283 * so just do it on the A channel.
284 */
285 if (channel == 0) {
286 zs_write_reg(cs, 9, 0);
287
288 chip = 0; /* We'll turn chip checking on post 1.2 */
289 printf(" chip type %d \n",chip);
290 }
291 cs->cs_chip = chip;
292
293 /*
294 * Look for a child driver for this channel.
295 * The child attach will setup the hardware.
296 */
297 zsc_args.channel = channel;
298 zsc_args.hwflags = zs_hwflags[zsc_unit][channel];
299 if (!config_found(self, (void *) &zsc_args, zsc_print)) {
300 /* No sub-driver. Just reset it. */
301 reset = (channel == 0) ?
302 ZSWR9_A_RESET : ZSWR9_B_RESET;
303 s = splzs();
304 zs_write_reg(cs, 9, reset);
305 splx(s);
306 }
307 }
308
309 /*
310 * Set the master interrupt enable and interrupt vector.
311 * (common to both channels, do it on A)
312 */
313 cs = &zsc->zsc_cs[0];
314 s = splzs();
315 /* interrupt vector */
316 zs_write_reg(cs, 2, zs_init_reg[2]);
317 /* master interrupt control (enable) */
318 zs_write_reg(cs, 9, zs_init_reg[9]);
319 splx(s);
320 }
321
322 void
323 zstty_mdattach(zsc, zst, cs, tp)
324 struct zsc_softc *zsc;
325 struct zstty_softc *zst;
326 struct zs_chanstate *cs;
327 struct tty *tp;
328 {
329 int theflags;
330
331 zst->zst_resetdef = 0;
332 cs->cs_clock_count = 3; /* internal + externals */
333 cs->cs_cclk_flag = 0; /* Not doing anything fancy by default */
334 cs->cs_pclk_flag = 0;
335 cs->cs_clocks[0].clk = mac68k_machine.sccClkConst*32;
336 cs->cs_clocks[0].flags = ZSC_RTXBRG; /* allowing divide by 16 will
337 melt the driver! */
338
339 cs->cs_clocks[1].flags = ZSC_RTXBRG | ZSC_RTXDIV | ZSC_VARIABLE | ZSC_EXTERN;
340 cs->cs_clocks[2].flags = ZSC_TRXDIV | ZSC_VARIABLE;
341 if (zst->zst_dev.dv_unit == 0) {
342 theflags = mac68k_machine.modem_flags;
343 cs->cs_clocks[1].clk = mac68k_machine.modem_dcd_clk;
344 cs->cs_clocks[2].clk = mac68k_machine.modem_cts_clk;
345 } else if (zst->zst_dev.dv_unit == 1) {
346 theflags = mac68k_machine.print_flags;
347 cs->cs_clocks[1].flags = ZSC_VARIABLE;
348 /*
349 * Yes, we aren't defining ANY clock source enables for the
350 * printer's DCD clock in. The hardware won't let us
351 * use it. But a clock will freak out the chip, so we
352 * let you set it, telling us to bar interrupts on the line.
353 */
354 cs->cs_clocks[1].clk = mac68k_machine.print_dcd_clk;
355 cs->cs_clocks[2].clk = mac68k_machine.print_cts_clk;
356 }
357
358 if (cs->cs_clocks[1].clk)
359 zst->zst_hwflags |= ZS_HWFLAG_IGDCD;
360 if (cs->cs_clocks[2].clk)
361 zst->zst_hwflags |= ZS_HWFLAG_IGCTS;
362
363 if (theflags & ZSMAC_RAW) {
364 zst->zst_cflag = ZSTTY_RAW_CFLAG;
365 zst->zst_iflag = ZSTTY_RAW_IFLAG;
366 zst->zst_lflag = ZSTTY_RAW_LFLAG;
367 zst->zst_oflag = ZSTTY_RAW_OFLAG;
368 printf(" (raw defaults)");
369 }
370 if (theflags & ZSMAC_LOCALTALK) {
371 printf(" shielding from LocalTalk");
372 zst->zst_ospeed = tp->t_ospeed = 1;
373 zst->zst_ispeed = tp->t_ispeed = 1;
374 cs->cs_defspeed = 1;
375 cs->cs_creg[ZSRR_BAUDLO] = cs->cs_preg[ZSRR_BAUDLO] = 0xff;
376 cs->cs_creg[ZSRR_BAUDHI] = cs->cs_preg[ZSRR_BAUDHI] = 0xff;
377 zs_write_reg(cs, ZSRR_BAUDLO, 0xff);
378 zs_write_reg(cs, ZSRR_BAUDHI, 0xff);
379 /*
380 * If we might have LocalTalk, then make sure we have the
381 * Baud rate low-enough to not do any damage.
382 */
383 }
384
385 /* For the mac, we have rtscts = check CTS for output control, no
386 * input control. mdmbuf means check DCD for output, and use DTR
387 * for input control. mdmbuf & rtscts means use CTS for output
388 * control, and DTR for input control. */
389
390 zst->zst_hwimasks[1] = 0;
391 zst->zst_hwimasks[2] = ZSWR5_DTR;
392 zst->zst_hwimasks[3] = ZSWR5_DTR;
393 }
394
395 int
396 zsmdioctl(tp, com, data, flag, p)
397 struct tty *tp;
398 u_long com;
399 caddr_t data;
400 int flag;
401 struct proc *p;
402 {
403 return (-1);
404 }
405
406 void
407 zsmd_setclock(cs)
408 struct zs_chanstate *cs;
409 {
410 if (cs->cs_pclk_flag & ZSC_EXTERN) {
411 /* XXX need to set the via! */
412 }
413 }
414
415 int
416 zshard(arg)
417 void *arg;
418 {
419 struct zsc_softc *zsc;
420 int unit, rval;
421 #ifdef ZSMACDEBUG
422 itecnputc(mac68k_zsdev, 'Z');
423 #endif
424
425 rval = 0;
426 unit = zsc_cd.cd_ndevs;
427 while (--unit >= 0) {
428 zsc = zsc_cd.cd_devs[unit];
429 if (zsc != NULL) {
430 rval |= zsc_intr_hard(zsc);
431 }
432 }
433 #ifdef ZSMACDEBUG
434 itecnputc(mac68k_zsdev, '\n');
435 #endif
436 return (rval);
437 }
438
439 int zssoftpending;
440
441 void
442 zsc_req_softint(zsc)
443 struct zsc_softc *zsc;
444 {
445 if (zssoftpending == 0) {
446 /* We are at splzs here, so no need to lock. */
447 zssoftpending = ZSSOFT_PRI;
448 /* isr_soft_request(ZSSOFT_PRI); */
449 setsoftserial();
450 }
451 }
452
453 int
454 zssoft(arg)
455 void *arg;
456 {
457 struct zsc_softc *zsc;
458 int unit;
459
460 /* This is not the only ISR on this IPL. */
461 if (zssoftpending == 0)
462 return (0);
463
464 /*
465 * The soft intr. bit will be set by zshard only if
466 * the variable zssoftpending is zero. The order of
467 * these next two statements prevents our clearing
468 * the soft intr bit just after zshard has set it.
469 */
470 /* isr_soft_clear(ZSSOFT_PRI); */
471 zssoftpending = 0;
472
473 /* Do ttya/ttyb first, because they go faster. */
474 unit = zsc_cd.cd_ndevs;
475 while (--unit >= 0) {
476 zsc = zsc_cd.cd_devs[unit];
477 if (zsc != NULL) {
478 (void) zsc_intr_soft(zsc);
479 }
480 }
481 return (1);
482 }
483
484
485 /*
486 * Read or write the chip with suitable delays.
487 */
488 #define ZS_DELAY()
489 /*
490 * MacII hardware has the delay built in. No need for extra delay. :-)
491 */
492
493 u_char
494 zs_read_reg(cs, reg)
495 struct zs_chanstate *cs;
496 u_char reg;
497 {
498 u_char val;
499
500 *cs->cs_reg_csr = reg;
501 ZS_DELAY();
502 val = *cs->cs_reg_csr;
503 ZS_DELAY();
504 return val;
505 }
506
507 void
508 zs_write_reg(cs, reg, val)
509 struct zs_chanstate *cs;
510 u_char reg, val;
511 {
512 *cs->cs_reg_csr = reg;
513 ZS_DELAY();
514 *cs->cs_reg_csr = val;
515 ZS_DELAY();
516 }
517
518 u_char zs_read_csr(cs)
519 struct zs_chanstate *cs;
520 {
521 register u_char v;
522
523 v = (*cs->cs_reg_csr) ^ ZSRR0_CTS;
524 /* make up for the fact CTS is wired backwards */
525 ZS_DELAY();
526 return v;
527 }
528
529 u_char zs_read_data(cs)
530 struct zs_chanstate *cs;
531 {
532 register u_char v;
533
534 v = *cs->cs_reg_data;
535 ZS_DELAY();
536 return v;
537 }
538
539 void zs_write_csr(cs, val)
540 struct zs_chanstate *cs;
541 u_char val;
542 {
543 *cs->cs_reg_csr = val;
544 ZS_DELAY();
545 }
546
547 void zs_write_data(cs, val)
548 struct zs_chanstate *cs;
549 u_char val;
550 {
551 *cs->cs_reg_data = val;
552 ZS_DELAY();
553 }
554
555 /****************************************************************
556 * Console support functions (Originally Sun3 specific!)
557 * Now works w/ just mac68k port!
558 ****************************************************************/
559
560 #define zscnpollc nullcnpollc
561 cons_decl(zs);
562
563 static void zs_putc __P((register volatile struct zschan *, int));
564 static int zs_getc __P((register volatile struct zschan *));
565 static void zscnsetup __P((void));
566 extern int zsopen __P(( dev_t dev, int flags, int mode, struct proc *p));
567
568 /*
569 * Console functions.
570 */
571
572 /*
573 * This code modled after the zs_setparam routine in zskgdb
574 * It sets the console unit to a known state so we can output
575 * correctly.
576 */
577 static void
578 zscnsetup()
579 {
580 struct zs_chanstate cs;
581 struct zschan *zc;
582 int tconst, s;
583
584 /* Setup temporary chanstate. */
585 bzero((caddr_t)&cs, sizeof(cs));
586 zc = zs_conschan;
587 cs.cs_reg_csr = &zc->zc_csr;
588 cs.cs_reg_data = &zc->zc_data;
589 cs.cs_channel = zs_consunit;
590
591 bcopy(zs_init_reg, cs.cs_preg, 16);
592 tconst = BPS_TO_TCONST(mac68k_machine.sccClkConst*2, zs_defspeed[0][zs_consunit]);
593 cs.cs_preg[5] |= ZSWR5_DTR | ZSWR5_RTS;
594 cs.cs_preg[1] = 0; /* don't enable interrupts */
595 cs.cs_preg[12] = tconst;
596 cs.cs_preg[13] = tconst >> 8;
597
598 s = splhigh();
599 zs_loadchannelregs(&cs);
600 splx(s);
601 }
602
603 /*
604 * zscnprobe is the routine which gets called as the kernel is trying to
605 * figure out where the console should be. Each io driver which might
606 * be the console (as defined in mac68k/conf.c) gets probed. The probe
607 * fills in the consdev structure. Important parts are the device #,
608 * and the console priority. Values are CN_DEAD (don't touch me),
609 * CN_NORMAL (I'm here, but elsewhere might be better), CN_INTERNAL
610 * (the video, better than CN_NORMAL), and CN_REMOTE (pick me!)
611 *
612 * As the mac's a bit different, we do extra work here. We mainly check
613 * to see if we have serial echo going on, and if the tty's are supposed
614 * to default to raw or not.
615 */
616 void
617 zscnprobe(struct consdev * cp)
618 {
619 extern u_long IOBase;
620 int maj, unit;
621
622 for (maj = 0; maj < nchrdev; maj++) {
623 if (cdevsw[maj].d_open == zsopen) {
624 break;
625 }
626 }
627 if (maj == nchrdev) {
628 /* no console entry for us */
629 if (mac68k_machine.serial_boot_echo) {
630 mac68k_set_io_offsets(IOBase);
631 zs_conschan = (struct zschan *) -1; /* dummy flag for zs_init() */
632 zs_consunit = 1;
633 zs_hwflags[0][zs_consunit] = ZS_HWFLAG_CONSOLE;
634 zs_init();
635 zscnsetup();
636 }
637 return;
638 }
639
640 cp->cn_pri = CN_NORMAL; /* Lower than CN_INTERNAL */
641 if (mac68k_machine.serial_console != 0) {
642 cp->cn_pri = CN_REMOTE; /* Higher than CN_INTERNAL */
643 mac68k_machine.serial_boot_echo =0;
644 }
645
646 unit = (mac68k_machine.serial_console == 1) ? 0 : 1;
647 zs_consunit = unit;
648
649 mac68k_zsdev = cp->cn_dev = makedev(maj, unit);
650
651 if (mac68k_machine.serial_boot_echo) {
652 /*
653 * at this point, we know that we don't have a serial
654 * console, but are doing echo
655 */
656 mac68k_set_io_offsets(IOBase);
657 zs_conschan = (struct zschan *) -1; /* dummy flag for zs_init() */
658 zs_consunit = 1;
659 zs_hwflags[0][zs_consunit] = ZS_HWFLAG_CONSOLE;
660 zs_init();
661 zscnsetup();
662 }
663 return;
664 }
665
666 void
667 zscninit(struct consdev * cp)
668 {
669 extern u_long IOBase;
670 int chan = minor(cp->cn_dev & 1);
671
672 mac68k_set_io_offsets(IOBase);
673 zs_conschan = (struct zschan *) -1;
674 zs_consunit = chan;
675 zs_hwflags[0][zs_consunit] = ZS_HWFLAG_CONSOLE | ZS_HWFLAG_CONABRT;
676 zs_init();
677 /*
678 * zsinit will set up the addresses of the scc. It will also, if
679 * zs_conschan != 0, calculate the new address of the conschan for
680 * unit zs_consunit. So zs_init implicitly sets zs_conschan to the right
681 * number. :-)
682 */
683 zscnsetup();
684 printf("\nNetBSD/mac68k console\n");
685 }
686
687
688 /*
689 * Polled input char.
690 */
691 static int
692 zs_getc(zc)
693 register volatile struct zschan *zc;
694 {
695 register int s, c, rr0;
696
697 s = splhigh();
698 /* Wait for a character to arrive. */
699 do {
700 rr0 = zc->zc_csr;
701 ZS_DELAY();
702 } while ((rr0 & ZSRR0_RX_READY) == 0);
703
704 c = zc->zc_data;
705 ZS_DELAY();
706 splx(s);
707
708 /*
709 * This is used by the kd driver to read scan codes,
710 * so don't translate '\r' ==> '\n' here...
711 */
712 return (c);
713 }
714
715 /*
716 * Polled output char.
717 */
718 static void
719 zs_putc(zc, c)
720 register volatile struct zschan *zc;
721 int c;
722 {
723 register int s, rr0;
724 register long wait = 0;
725
726 s = splhigh();
727 /* Wait for transmitter to become ready. */
728 do {
729 rr0 = zc->zc_csr;
730 ZS_DELAY();
731 } while (((rr0 & ZSRR0_TX_READY) == 0) && (wait++ < 1000000));
732
733 if ((rr0 & ZSRR0_TX_READY) != 0) {
734 zc->zc_data = c;
735 ZS_DELAY();
736 }
737 splx(s);
738 }
739
740
741 /*
742 * Polled console input putchar.
743 */
744 int
745 zscngetc(dev)
746 dev_t dev;
747 {
748 register volatile struct zschan *zc = zs_conschan;
749 register int c;
750
751 c = zs_getc(zc);
752 return (c);
753 }
754
755 /*
756 * Polled console output putchar.
757 */
758 void
759 zscnputc(dev, c)
760 dev_t dev;
761 int c;
762 {
763 register volatile struct zschan *zc = zs_conschan;
764
765 zs_putc(zc, c);
766 }
767
768
769
770 /*
771 * Handle user request to enter kernel debugger.
772 */
773 void
774 zs_abort(zst)
775 register struct zstty_softc *zst;
776 {
777 register volatile struct zschan *zc = zs_conschan;
778 int rr0;
779 register long wait = 0;
780
781 /* Wait for end of break to avoid PROM abort. */
782 /* XXX - Limit the wait? */
783 do {
784 rr0 = zc->zc_csr;
785 ZS_DELAY();
786 } while ((rr0 & ZSRR0_BREAK) && (wait++ < ZSABORT_DELAY));
787
788 if (wait > ZSABORT_DELAY) {
789 if (zst != NULL) zst->zst_hwflags &= ~ZS_HWFLAG_CONABRT;
790 /* If we time out, turn off the abort ability! */
791 }
792
793 /* XXX - Always available, but may be the PROM monitor. */
794 Debugger();
795 }
796