zs.c revision 1.34.6.1 1 /* $NetBSD: zs.c,v 1.34.6.1 2002/12/07 21:28:05 he 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 "opt_ddb.h"
48 #include "opt_kgdb.h"
49
50 #include <sys/param.h>
51 #include <sys/systm.h>
52 #include <sys/conf.h>
53 #include <sys/device.h>
54 #include <sys/file.h>
55 #include <sys/ioctl.h>
56 #include <sys/kernel.h>
57 #include <sys/proc.h>
58 #include <sys/tty.h>
59 #include <sys/time.h>
60 #include <sys/syslog.h>
61
62 #include <machine/autoconf.h>
63 #include <machine/openfirm.h>
64 #include <machine/conf.h>
65 #include <machine/cpu.h>
66 #include <machine/eeprom.h>
67 #include <machine/psl.h>
68 #include <machine/z8530var.h>
69
70 #include <dev/cons.h>
71 #include <dev/ic/z8530reg.h>
72 #include <dev/sun/kbd_ms_ttyvar.h>
73 #include <ddb/db_output.h>
74
75 #include <sparc64/dev/cons.h>
76
77 #include "kbd.h" /* NKBD */
78 #include "ms.h" /* NMS */
79 #include "zs.h" /* NZS */
80
81 /* Make life easier for the initialized arrays here. */
82 #if NZS < 3
83 #undef NZS
84 #define NZS 3
85 #endif
86
87 /*
88 * Some warts needed by z8530tty.c -
89 * The default parity REALLY needs to be the same as the PROM uses,
90 * or you can not see messages done with printf during boot-up...
91 */
92 int zs_def_cflag = (CREAD | CS8 | HUPCL);
93 int zs_major = 12;
94
95 /*
96 * The Sun provides a 4.9152 MHz clock to the ZS chips.
97 */
98 #define PCLK (9600 * 512) /* PCLK pin input clock rate */
99
100 #define ZS_DELAY()
101
102 /* The layout of this is hardware-dependent (padding, order). */
103 struct zschan {
104 volatile u_char zc_csr; /* ctrl,status, and indirect access */
105 u_char zc_xxx0;
106 volatile u_char zc_data; /* data */
107 u_char zc_xxx1;
108 };
109 struct zsdevice {
110 /* Yes, they are backwards. */
111 struct zschan zs_chan_b;
112 struct zschan zs_chan_a;
113 };
114
115 /* ZS channel used as the console device (if any) */
116 void *zs_conschan_get, *zs_conschan_put;
117
118 /* Saved PROM mappings */
119 static struct zsdevice *zsaddr[NZS];
120
121 static u_char zs_init_reg[16] = {
122 0, /* 0: CMD (reset, etc.) */
123 0, /* 1: No interrupts yet. */
124 0, /* 2: IVECT */
125 ZSWR3_RX_8 | ZSWR3_RX_ENABLE,
126 ZSWR4_CLK_X16 | ZSWR4_ONESB | ZSWR4_EVENP,
127 ZSWR5_TX_8 | ZSWR5_TX_ENABLE,
128 0, /* 6: TXSYNC/SYNCLO */
129 0, /* 7: RXSYNC/SYNCHI */
130 0, /* 8: alias for data port */
131 ZSWR9_MASTER_IE | ZSWR9_NO_VECTOR,
132 0, /*10: Misc. TX/RX control bits */
133 ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD,
134 ((PCLK/32)/9600)-2, /*12: BAUDLO (default=9600) */
135 0, /*13: BAUDHI (default=9600) */
136 ZSWR14_BAUD_ENA | ZSWR14_BAUD_FROM_PCLK,
137 ZSWR15_BREAK_IE,
138 };
139
140 /* Console ops */
141 static int zscngetc __P((dev_t));
142 static void zscnputc __P((dev_t, int));
143 static void zscnpollc __P((dev_t, int));
144
145 struct consdev zs_consdev = {
146 NULL,
147 NULL,
148 zscngetc,
149 zscnputc,
150 zscnpollc,
151 NULL,
152 };
153
154
155 /****************************************************************
156 * Autoconfig
157 ****************************************************************/
158
159 /* Definition of the driver for autoconfig. */
160 static int zs_match_mainbus __P((struct device *, struct cfdata *, void *));
161 static void zs_attach_mainbus __P((struct device *, struct device *, void *));
162
163 static void zs_attach __P((struct zsc_softc *, struct zsdevice *, int));
164 static int zs_print __P((void *, const char *name));
165
166 /* Do we really need this ? */
167 struct cfattach zs_ca = {
168 sizeof(struct zsc_softc), zs_match_mainbus, zs_attach_mainbus
169 };
170
171 struct cfattach zs_mainbus_ca = {
172 sizeof(struct zsc_softc), zs_match_mainbus, zs_attach_mainbus
173 };
174
175 extern struct cfdriver zs_cd;
176 extern int stdinnode;
177 extern int fbnode;
178
179 /* Interrupt handlers. */
180 int zscheckintr __P((void *));
181 static int zshard __P((void *));
182 static void zssoft __P((void *));
183
184 static int zs_get_speed __P((struct zs_chanstate *));
185
186 /* Console device support */
187 static int zs_console_flags __P((int, int, int));
188
189 /* Power management hooks */
190 int zs_enable __P((struct zs_chanstate *));
191 void zs_disable __P((struct zs_chanstate *));
192
193 /*
194 * Is the zs chip present?
195 */
196 static int
197 zs_match_mainbus(parent, cf, aux)
198 struct device *parent;
199 struct cfdata *cf;
200 void *aux;
201 {
202 struct sbus_attach_args *sa = aux;
203
204 if (strcmp(cf->cf_driver->cd_name, sa->sa_name) != 0)
205 return (0);
206
207 return (1);
208 }
209
210 static void
211 zs_attach_mainbus(parent, self, aux)
212 struct device *parent;
213 struct device *self;
214 void *aux;
215 {
216 struct zsc_softc *zsc = (void *) self;
217 struct sbus_attach_args *sa = aux;
218 bus_space_handle_t bh;
219 int zs_unit = zsc->zsc_dev.dv_unit;
220
221 if (sa->sa_nintr == 0) {
222 printf(" no interrupt lines\n");
223 return;
224 }
225
226 /* Use the mapping setup by the Sun PROM if possible. */
227 if (zsaddr[zs_unit] == NULL) {
228 /* Only map registers once. */
229 if (sa->sa_npromvaddrs) {
230 /*
231 * We're converting from a 32-bit pointer to a 64-bit
232 * pointer. Since the 32-bit entity is negative, but
233 * the kernel is still mapped into the lower 4GB
234 * range, this needs to be zero-extended.
235 *
236 * XXXXX If we map the kernel and devices into the
237 * high 4GB range, this needs to be changed to
238 * sign-extend the address.
239 */
240 sparc_promaddr_to_handle(sa->sa_bustag,
241 sa->sa_promvaddrs[0], &bh);
242
243 } else {
244
245 if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
246 sa->sa_offset,
247 sa->sa_size,
248 BUS_SPACE_MAP_LINEAR,
249 &bh) != 0) {
250 printf("%s @ sbus: cannot map registers\n",
251 self->dv_xname);
252 return;
253 }
254 }
255 zsaddr[zs_unit] = (struct zsdevice *)
256 bus_space_vaddr(sa->sa_bustag, bh);
257 }
258 zsc->zsc_bustag = sa->sa_bustag;
259 zsc->zsc_dmatag = sa->sa_dmatag;
260 zsc->zsc_promunit = PROM_getpropint(sa->sa_node, "slave", -2);
261 zsc->zsc_node = sa->sa_node;
262 zs_attach(zsc, zsaddr[zs_unit], sa->sa_pri);
263 }
264
265 /*
266 * Attach a found zs.
267 *
268 * USE ROM PROPERTIES port-a-ignore-cd AND port-b-ignore-cd FOR
269 * SOFT CARRIER, AND keyboard PROPERTY FOR KEYBOARD/MOUSE?
270 */
271 static void
272 zs_attach(zsc, zsd, pri)
273 struct zsc_softc *zsc;
274 struct zsdevice *zsd;
275 int pri;
276 {
277 struct zsc_attach_args zsc_args;
278 struct zs_chanstate *cs;
279 int s, channel, softpri = PIL_TTY;
280
281 if (zsd == NULL) {
282 printf("configuration incomplete\n");
283 return;
284 }
285
286 printf(" softpri %d\n", softpri);
287
288 /*
289 * Initialize software state for each channel.
290 */
291 for (channel = 0; channel < 2; channel++) {
292 struct zschan *zc;
293 struct device *child;
294 #if (NKBD > 0) || (NMS > 0)
295 extern struct cfdriver zstty_cd; /* in ioconf.c */
296 #endif
297
298 zsc_args.channel = channel;
299 cs = &zsc->zsc_cs_store[channel];
300 zsc->zsc_cs[channel] = cs;
301
302 cs->cs_channel = channel;
303 cs->cs_private = NULL;
304 cs->cs_ops = &zsops_null;
305 cs->cs_brg_clk = PCLK / 16;
306
307 zc = (channel == 0) ? &zsd->zs_chan_a : &zsd->zs_chan_b;
308
309 zsc_args.consdev = NULL;
310 zsc_args.hwflags = zs_console_flags(zsc->zsc_promunit,
311 zsc->zsc_node,
312 channel);
313
314 if (zsc_args.hwflags & ZS_HWFLAG_CONSOLE) {
315 zsc_args.hwflags |= ZS_HWFLAG_USE_CONSDEV;
316 zsc_args.consdev = &zs_consdev;
317 }
318
319 if ((zsc_args.hwflags & ZS_HWFLAG_CONSOLE_INPUT) != 0) {
320 zs_conschan_get = zc;
321 }
322 if ((zsc_args.hwflags & ZS_HWFLAG_CONSOLE_OUTPUT) != 0) {
323 zs_conschan_put = zc;
324 }
325
326 /* Children need to set cn_dev, etc */
327 cs->cs_reg_csr = &zc->zc_csr;
328 cs->cs_reg_data = &zc->zc_data;
329
330 bcopy(zs_init_reg, cs->cs_creg, 16);
331 bcopy(zs_init_reg, cs->cs_preg, 16);
332
333 /* XXX: Consult PROM properties for this?! */
334 cs->cs_defspeed = zs_get_speed(cs);
335 cs->cs_defcflag = zs_def_cflag;
336
337 /* Make these correspond to cs_defcflag (-crtscts) */
338 cs->cs_rr0_dcd = ZSRR0_DCD;
339 cs->cs_rr0_cts = 0;
340 cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
341 cs->cs_wr5_rts = 0;
342
343 /*
344 * Clear the master interrupt enable.
345 * The INTENA is common to both channels,
346 * so just do it on the A channel.
347 */
348 if (channel == 0) {
349 zs_write_reg(cs, 9, 0);
350 }
351
352 /*
353 * Look for a child driver for this channel.
354 * The child attach will setup the hardware.
355 */
356 if (!(child =
357 config_found(&zsc->zsc_dev, (void *)&zsc_args, zs_print))) {
358 /* No sub-driver. Just reset it. */
359 u_char reset = (channel == 0) ?
360 ZSWR9_A_RESET : ZSWR9_B_RESET;
361 s = splzs();
362 zs_write_reg(cs, 9, reset);
363 splx(s);
364 }
365 #if (NKBD > 0) || (NMS > 0)
366 /*
367 * If this was a zstty it has a keyboard
368 * property on it we need to attach the
369 * sunkbd and sunms line disciplines.
370 */
371 if (child
372 && (child->dv_cfdata->cf_driver == &zstty_cd)
373 && (PROM_getproplen(zsc->zsc_node, "keyboard") == 0)) {
374 struct kbd_ms_tty_attach_args kma;
375 struct zstty_softc {
376 /* The following are the only fields we need here */
377 struct device zst_dev;
378 struct tty *zst_tty;
379 struct zs_chanstate *zst_cs;
380 } *zst = (struct zstty_softc *)child;
381 struct tty *tp;
382
383 kma.kmta_tp = tp = zst->zst_tty;
384 kma.kmta_dev = tp->t_dev;
385 kma.kmta_consdev = zsc_args.consdev;
386
387 /* Attach 'em if we got 'em. */
388 #if (NKBD > 0)
389 if (channel == 0) {
390 kma.kmta_name = "keyboard";
391 config_found(child, (void *)&kma, NULL);
392 }
393 #endif
394 #if (NMS > 0)
395 if (channel == 1) {
396 kma.kmta_name = "mouse";
397 config_found(child, (void *)&kma, NULL);
398 }
399 #endif
400 }
401 #endif
402 }
403
404 /*
405 * Now safe to install interrupt handlers. Note the arguments
406 * to the interrupt handlers aren't used. Note, we only do this
407 * once since both SCCs interrupt at the same level and vector.
408 */
409 bus_intr_establish(zsc->zsc_bustag, pri, IPL_SERIAL, 0, zshard, zsc);
410 if (!(zsc->zsc_softintr = softintr_establish(softpri, zssoft, zsc)))
411 panic("zsattach: could not establish soft interrupt\n");
412
413 evcnt_attach_dynamic(&zsc->zsc_intrcnt, EVCNT_TYPE_INTR, NULL,
414 zsc->zsc_dev.dv_xname, "intr");
415
416
417 /*
418 * Set the master interrupt enable and interrupt vector.
419 * (common to both channels, do it on A)
420 */
421 cs = zsc->zsc_cs[0];
422 s = splhigh();
423 /* interrupt vector */
424 zs_write_reg(cs, 2, zs_init_reg[2]);
425 /* master interrupt control (enable) */
426 zs_write_reg(cs, 9, zs_init_reg[9]);
427 splx(s);
428
429 }
430
431 static int
432 zs_print(aux, name)
433 void *aux;
434 const char *name;
435 {
436 struct zsc_attach_args *args = aux;
437
438 if (name != NULL)
439 printf("%s: ", name);
440
441 if (args->channel != -1)
442 printf(" channel %d", args->channel);
443
444 return (UNCONF);
445 }
446
447 /* Deprecate this? */
448 static volatile int zssoftpending;
449
450 static int
451 zshard(arg)
452 void *arg;
453 {
454 struct zsc_softc *zsc = (struct zsc_softc *)arg;
455 int rr3, rval;
456
457 rval = 0;
458 while ((rr3 = zsc_intr_hard(zsc))) {
459 /* Count up the interrupts. */
460 rval |= rr3;
461 zsc->zsc_intrcnt.ev_count++;
462 }
463 if (((zsc->zsc_cs[0] && zsc->zsc_cs[0]->cs_softreq) ||
464 (zsc->zsc_cs[1] && zsc->zsc_cs[1]->cs_softreq)) &&
465 zsc->zsc_softintr) {
466 zssoftpending = PIL_TTY;
467 softintr_schedule(zsc->zsc_softintr);
468 }
469 return (rval);
470 }
471
472 int
473 zscheckintr(arg)
474 void *arg;
475 {
476 struct zsc_softc *zsc;
477 int unit, rval;
478
479 rval = 0;
480 for (unit = 0; unit < zs_cd.cd_ndevs; unit++) {
481
482 zsc = zs_cd.cd_devs[unit];
483 if (zsc == NULL)
484 continue;
485 rval = (zshard((void *)zsc) || rval);
486 }
487 return (rval);
488 }
489
490
491 /*
492 * We need this only for TTY_DEBUG purposes.
493 */
494 static void
495 zssoft(arg)
496 void *arg;
497 {
498 struct zsc_softc *zsc = (struct zsc_softc *)arg;
499 int s;
500
501 /* Make sure we call the tty layer at spltty. */
502 s = spltty();
503 zssoftpending = 0;
504 (void)zsc_intr_soft(zsc);
505 #ifdef TTY_DEBUG
506 {
507 struct zstty_softc *zst0 = zsc->zsc_cs[0]->cs_private;
508 struct zstty_softc *zst1 = zsc->zsc_cs[1]->cs_private;
509 if (zst0->zst_overflows || zst1->zst_overflows ) {
510 struct trapframe *frame = (struct trapframe *)arg;
511
512 printf("zs silo overflow from %p\n",
513 (long)frame->tf_pc);
514 }
515 }
516 #endif
517 splx(s);
518 }
519
520
521 /*
522 * Compute the current baud rate given a ZS channel.
523 */
524 static int
525 zs_get_speed(cs)
526 struct zs_chanstate *cs;
527 {
528 int tconst;
529
530 tconst = zs_read_reg(cs, 12);
531 tconst |= zs_read_reg(cs, 13) << 8;
532 return (TCONST_TO_BPS(cs->cs_brg_clk, tconst));
533 }
534
535 /*
536 * MD functions for setting the baud rate and control modes.
537 */
538 int
539 zs_set_speed(cs, bps)
540 struct zs_chanstate *cs;
541 int bps; /* bits per second */
542 {
543 int tconst, real_bps;
544
545 if (bps == 0)
546 return (0);
547
548 #ifdef DIAGNOSTIC
549 if (cs->cs_brg_clk == 0)
550 panic("zs_set_speed");
551 #endif
552
553 tconst = BPS_TO_TCONST(cs->cs_brg_clk, bps);
554 if (tconst < 0)
555 return (EINVAL);
556
557 /* Convert back to make sure we can do it. */
558 real_bps = TCONST_TO_BPS(cs->cs_brg_clk, tconst);
559
560 /* XXX - Allow some tolerance here? */
561 if (real_bps != bps)
562 return (EINVAL);
563
564 cs->cs_preg[12] = tconst;
565 cs->cs_preg[13] = tconst >> 8;
566
567 /* Caller will stuff the pending registers. */
568 return (0);
569 }
570
571 int
572 zs_set_modes(cs, cflag)
573 struct zs_chanstate *cs;
574 int cflag; /* bits per second */
575 {
576 int s;
577
578 /*
579 * Output hardware flow control on the chip is horrendous:
580 * if carrier detect drops, the receiver is disabled, and if
581 * CTS drops, the transmitter is stoped IN MID CHARACTER!
582 * Therefore, NEVER set the HFC bit, and instead use the
583 * status interrupt to detect CTS changes.
584 */
585 s = splzs();
586 cs->cs_rr0_pps = 0;
587 if ((cflag & (CLOCAL | MDMBUF)) != 0) {
588 cs->cs_rr0_dcd = 0;
589 if ((cflag & MDMBUF) == 0)
590 cs->cs_rr0_pps = ZSRR0_DCD;
591 } else
592 cs->cs_rr0_dcd = ZSRR0_DCD;
593 if ((cflag & CRTSCTS) != 0) {
594 cs->cs_wr5_dtr = ZSWR5_DTR;
595 cs->cs_wr5_rts = ZSWR5_RTS;
596 cs->cs_rr0_cts = ZSRR0_CTS;
597 } else if ((cflag & CDTRCTS) != 0) {
598 cs->cs_wr5_dtr = 0;
599 cs->cs_wr5_rts = ZSWR5_DTR;
600 cs->cs_rr0_cts = ZSRR0_CTS;
601 } else if ((cflag & MDMBUF) != 0) {
602 cs->cs_wr5_dtr = 0;
603 cs->cs_wr5_rts = ZSWR5_DTR;
604 cs->cs_rr0_cts = ZSRR0_DCD;
605 } else {
606 cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
607 cs->cs_wr5_rts = 0;
608 cs->cs_rr0_cts = 0;
609 }
610 splx(s);
611
612 /* Caller will stuff the pending registers. */
613 return (0);
614 }
615
616
617 /*
618 * Read or write the chip with suitable delays.
619 */
620
621 u_char
622 zs_read_reg(cs, reg)
623 struct zs_chanstate *cs;
624 u_char reg;
625 {
626 u_char val;
627
628 *cs->cs_reg_csr = reg;
629 ZS_DELAY();
630 val = *cs->cs_reg_csr;
631 ZS_DELAY();
632 return (val);
633 }
634
635 void
636 zs_write_reg(cs, reg, val)
637 struct zs_chanstate *cs;
638 u_char reg, val;
639 {
640 *cs->cs_reg_csr = reg;
641 ZS_DELAY();
642 *cs->cs_reg_csr = val;
643 ZS_DELAY();
644 }
645
646 u_char
647 zs_read_csr(cs)
648 struct zs_chanstate *cs;
649 {
650 u_char val;
651
652 val = *cs->cs_reg_csr;
653 ZS_DELAY();
654 return (val);
655 }
656
657 void zs_write_csr(cs, val)
658 struct zs_chanstate *cs;
659 u_char val;
660 {
661 *cs->cs_reg_csr = val;
662 ZS_DELAY();
663 }
664
665 u_char zs_read_data(cs)
666 struct zs_chanstate *cs;
667 {
668 u_char val;
669
670 val = *cs->cs_reg_data;
671 ZS_DELAY();
672 return (val);
673 }
674
675 void zs_write_data(cs, val)
676 struct zs_chanstate *cs;
677 u_char val;
678 {
679 *cs->cs_reg_data = val;
680 ZS_DELAY();
681 }
682
683 /****************************************************************
684 * Console support functions (Sun specific!)
685 * Note: this code is allowed to know about the layout of
686 * the chip registers, and uses that to keep things simple.
687 * XXX - I think I like the mvme167 code better. -gwr
688 ****************************************************************/
689
690 extern void Debugger __P((void));
691
692 /*
693 * Handle user request to enter kernel debugger.
694 */
695 void
696 zs_abort(cs)
697 struct zs_chanstate *cs;
698 {
699 volatile struct zschan *zc = zs_conschan_get;
700 int rr0;
701
702 /* Wait for end of break to avoid PROM abort. */
703 /* XXX - Limit the wait? */
704 do {
705 rr0 = zc->zc_csr;
706 ZS_DELAY();
707 } while (rr0 & ZSRR0_BREAK);
708
709 #if defined(KGDB)
710 zskgdb(cs);
711 #elif defined(DDB)
712 {
713 extern int db_active;
714
715 if (!db_active)
716 Debugger();
717 else
718 /* Debugger is probably hozed */
719 callrom();
720 }
721 #else
722 printf("stopping on keyboard abort\n");
723 callrom();
724 #endif
725 }
726
727
728 /*
729 * Polled input char.
730 */
731 int
732 zs_getc(arg)
733 void *arg;
734 {
735 volatile struct zschan *zc = arg;
736 int s, c, rr0;
737
738 s = splhigh();
739 /* Wait for a character to arrive. */
740 do {
741 rr0 = zc->zc_csr;
742 ZS_DELAY();
743 } while ((rr0 & ZSRR0_RX_READY) == 0);
744
745 c = zc->zc_data;
746 ZS_DELAY();
747 splx(s);
748
749 /*
750 * This is used by the kd driver to read scan codes,
751 * so don't translate '\r' ==> '\n' here...
752 */
753 return (c);
754 }
755
756 /*
757 * Polled output char.
758 */
759 void
760 zs_putc(arg, c)
761 void *arg;
762 int c;
763 {
764 volatile struct zschan *zc = arg;
765 int s, rr0;
766
767 s = splhigh();
768
769 /* Wait for transmitter to become ready. */
770 do {
771 rr0 = zc->zc_csr;
772 ZS_DELAY();
773 } while ((rr0 & ZSRR0_TX_READY) == 0);
774
775 /*
776 * Send the next character.
777 * Now you'd think that this could be followed by a ZS_DELAY()
778 * just like all the other chip accesses, but it turns out that
779 * the `transmit-ready' interrupt isn't de-asserted until
780 * some period of time after the register write completes
781 * (more than a couple instructions). So to avoid stray
782 * interrupts we put in the 2us delay regardless of cpu model.
783 */
784 zc->zc_data = c;
785 delay(2);
786
787 splx(s);
788 }
789
790 /*****************************************************************/
791
792
793
794
795 /*
796 * Polled console input putchar.
797 */
798 static int
799 zscngetc(dev)
800 dev_t dev;
801 {
802 return (zs_getc(zs_conschan_get));
803 }
804
805 /*
806 * Polled console output putchar.
807 */
808 static void
809 zscnputc(dev, c)
810 dev_t dev;
811 int c;
812 {
813 zs_putc(zs_conschan_put, c);
814 }
815
816 int swallow_zsintrs;
817
818 static void
819 zscnpollc(dev, on)
820 dev_t dev;
821 int on;
822 {
823 /*
824 * Need to tell zs driver to acknowledge all interrupts or we get
825 * annoying spurious interrupt messages. This is because mucking
826 * with spl() levels during polling does not prevent interrupts from
827 * being generated.
828 */
829
830 if (on) swallow_zsintrs++;
831 else swallow_zsintrs--;
832 }
833
834 int
835 zs_console_flags(promunit, node, channel)
836 int promunit;
837 int node;
838 int channel;
839 {
840 int cookie, flags = 0;
841 u_int chosen;
842 char buf[255];
843
844 /*
845 * We'll just to the OBP grovelling down here since that's
846 * the only type of firmware we support.
847 */
848 chosen = OF_finddevice("/chosen");
849
850 /* Default to channel 0 if there are no explicit prom args */
851 cookie = 0;
852 if (node == OF_instance_to_package(OF_stdin())) {
853 if (OF_getprop(chosen, "input-device", buf, sizeof(buf)) != -1) {
854
855 if (!strcmp("ttyb", buf))
856 cookie = 1;
857 }
858
859 if (channel == cookie)
860 flags |= ZS_HWFLAG_CONSOLE_INPUT;
861 }
862
863 if (node == OF_instance_to_package(OF_stdout())) {
864 if (OF_getprop(chosen, "output-device", buf, sizeof(buf)) != -1) {
865
866 if (!strcmp("ttyb", buf))
867 cookie = 1;
868 }
869
870 if (channel == cookie)
871 flags |= ZS_HWFLAG_CONSOLE_OUTPUT;
872 }
873
874 return (flags);
875 }
876
877