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