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