zs.c revision 1.9.4.1 1 /* $NetBSD: zs.c,v 1.9.4.1 1999/06/21 01:02:32 thorpej 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
73 #include <sparc64/sparc64/vaddrs.h>
74 #include <sparc64/sparc64/auxreg.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 /*
100 * Select software interrupt bit based on TTY ipl.
101 */
102 #if PIL_TTY == 1
103 # define IE_ZSSOFT IE_L1
104 #elif PIL_TTY == 4
105 # define IE_ZSSOFT IE_L4
106 #elif PIL_TTY == 6
107 # define IE_ZSSOFT IE_L6
108 #else
109 # error "no suitable software interrupt bit"
110 #endif
111
112 #define ZS_DELAY()
113
114 /* The layout of this is hardware-dependent (padding, order). */
115 struct zschan {
116 volatile u_char zc_csr; /* ctrl,status, and indirect access */
117 u_char zc_xxx0;
118 volatile u_char zc_data; /* data */
119 u_char zc_xxx1;
120 };
121 struct zsdevice {
122 /* Yes, they are backwards. */
123 struct zschan zs_chan_b;
124 struct zschan zs_chan_a;
125 };
126
127 /* Saved PROM mappings */
128 static struct zsdevice *zsaddr[NZS];
129
130 /* Flags from cninit() */
131 static int zs_hwflags[NZS][2];
132
133 /* Default speed for each channel */
134 static int zs_defspeed[NZS][2] = {
135 { 9600, /* ttya */
136 9600 }, /* ttyb */
137 { 1200, /* keyboard */
138 1200 }, /* mouse */
139 { 9600, /* ttyc */
140 9600 }, /* ttyd */
141 };
142
143 static u_char zs_init_reg[16] = {
144 0, /* 0: CMD (reset, etc.) */
145 0, /* 1: No interrupts yet. */
146 0, /* 2: IVECT */
147 ZSWR3_RX_8 | ZSWR3_RX_ENABLE,
148 ZSWR4_CLK_X16 | ZSWR4_ONESB | ZSWR4_EVENP,
149 ZSWR5_TX_8 | ZSWR5_TX_ENABLE,
150 0, /* 6: TXSYNC/SYNCLO */
151 0, /* 7: RXSYNC/SYNCHI */
152 0, /* 8: alias for data port */
153 ZSWR9_MASTER_IE | ZSWR9_NO_VECTOR,
154 0, /*10: Misc. TX/RX control bits */
155 ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD,
156 ((PCLK/32)/9600)-2, /*12: BAUDLO (default=9600) */
157 0, /*13: BAUDHI (default=9600) */
158 ZSWR14_BAUD_ENA | ZSWR14_BAUD_FROM_PCLK,
159 ZSWR15_BREAK_IE,
160 };
161
162 struct zschan *
163 zs_get_chan_addr(zs_unit, channel)
164 int zs_unit, channel;
165 {
166 struct zsdevice *addr;
167 struct zschan *zc;
168
169 if (zs_unit >= NZS)
170 return (NULL);
171 addr = zsaddr[zs_unit];
172 #ifdef DEBUG
173 if (addr == NULL) {
174 db_printf("zs_get_chan_addr(): unit %d channel %d not found\n", zs_unit, channel);
175 Debugger();
176 }
177 #endif
178 if (addr == NULL)
179 return (NULL);
180 if (channel == 0) {
181 zc = &addr->zs_chan_a;
182 } else {
183 zc = &addr->zs_chan_b;
184 }
185 return (zc);
186 }
187
188
189 /****************************************************************
190 * Autoconfig
191 ****************************************************************/
192
193 /* Definition of the driver for autoconfig. */
194 static int zs_match_sbus __P((struct device *, struct cfdata *, void *));
195 static int zs_match_mainbus __P((struct device *, struct cfdata *, void *));
196 static int zs_match_obio __P((struct device *, struct cfdata *, void *));
197 static void zs_attach_sbus __P((struct device *, struct device *, void *));
198 static void zs_attach_mainbus __P((struct device *, struct device *, void *));
199 static void zs_attach_obio __P((struct device *, struct device *, void *));
200
201 static void zs_attach __P((struct zsc_softc *, int));
202 static int zs_print __P((void *, const char *name));
203
204 struct cfattach zs_ca = {
205 sizeof(struct zsc_softc), zs_match_sbus, zs_attach_sbus
206 };
207
208 struct cfattach zs_mainbus_ca = {
209 sizeof(struct zsc_softc), zs_match_mainbus, zs_attach_mainbus
210 };
211
212 struct cfattach zs_obio_ca = {
213 sizeof(struct zsc_softc), zs_match_obio, zs_attach_obio
214 };
215
216 extern struct cfdriver zs_cd;
217 extern struct consdev consdev_kd;
218 extern struct consdev consdev_zs;
219 extern struct consdev *cn_hw;
220 extern int stdinnode;
221 extern int fbnode;
222
223 /* Interrupt handlers. */
224 static int zshard __P((void *));
225 static int zssoft __P((void *));
226 static struct intrhand levelsoft = { zssoft };
227
228 static int zs_get_speed __P((struct zs_chanstate *));
229
230
231 /*
232 * Is the zs chip present?
233 */
234 static int
235 zs_match_mainbus(parent, cf, aux)
236 struct device *parent;
237 struct cfdata *cf;
238 void *aux;
239 {
240 struct mainbus_attach_args *ma = aux;
241
242 if (strcmp(cf->cf_driver->cd_name, ma->ma_name) != 0)
243 return (0);
244
245 return (getpropint(ma->ma_node, "slave", -2) == cf->cf_unit);
246 }
247
248 static int
249 zs_match_sbus(parent, cf, aux)
250 struct device *parent;
251 struct cfdata *cf;
252 void *aux;
253 {
254 struct sbus_attach_args *sa = aux;
255
256 if (strcmp(cf->cf_driver->cd_name, sa->sa_name) != 0)
257 return (0);
258
259 return 1;
260 }
261
262 static int
263 zs_match_obio(parent, cf, aux)
264 struct device *parent;
265 struct cfdata *cf;
266 void *aux;
267 {
268 #ifdef SUN4U
269 return 0;
270 #else
271 union obio_attach_args *uoba = aux;
272 struct obio4_attach_args *oba;
273
274 if (uoba->uoba_isobio4 == 0) {
275 struct sbus_attach_args *sa = &uoba->uoba_sbus;
276
277 if (strcmp(cf->cf_driver->cd_name, sa->sa_name) != 0)
278 return (0);
279
280 return (getpropint(sa->sa_node, "slave", -2) == cf->cf_unit);
281 }
282
283 oba = &uoba->uoba_oba4;
284 return (bus_space_probe(oba->oba_bustag, 0, oba->oba_paddr,
285 1, 0, 0, NULL, NULL));
286 #endif
287 }
288
289 static void
290 zs_attach_mainbus(parent, self, aux)
291 struct device *parent;
292 struct device *self;
293 void *aux;
294 {
295 #ifdef SUN4U
296 return;
297 #else
298 struct zsc_softc *zsc = (void *) self;
299 struct mainbus_attach_args *ma = aux;
300 int zs_unit = zsc->zsc_dev.dv_unit;
301
302 zsc->zsc_bustag = ma->ma_bustag;
303 zsc->zsc_dmatag = ma->ma_dmatag;
304
305 /* Use the mapping setup by the Sun PROM. */
306 if (zsaddr[zs_unit] == NULL)
307 zsaddr[zs_unit] = findzs(zs_unit);
308 if ((void*)zsaddr[zs_unit] != (void*)(u_long)ma->ma_address[0])
309 panic("zsattach_mainbus");
310 zs_attach(zsc, ma->ma_pri);
311 #endif
312 }
313
314
315 static void
316 zs_attach_sbus(parent, self, aux)
317 struct device *parent;
318 struct device *self;
319 void *aux;
320 {
321 struct zsc_softc *zsc = (void *) self;
322 struct sbus_attach_args *sa = aux;
323 int zs_unit = zsc->zsc_dev.dv_unit;
324 struct consdev *cn = NULL;
325
326 zsc->zsc_bustag = sa->sa_bustag;
327 zsc->zsc_dmatag = sa->sa_dmatag;
328
329 /* Use the mapping setup by the Sun PROM. */
330 if (zsaddr[zs_unit] == NULL) {
331 if (sa->sa_npromvaddrs) {
332 /*
333 * We're converting from a 32-bit pointer to a 64-bit
334 * pointer. Since the 32-bit entity is negative, but
335 * the kernel is still mapped into the lower 4GB
336 * range, this needs to be zero-extended.
337 *
338 * XXXXX If we map the kernel and devices into the
339 * high 4GB range, this needs to be changed to
340 * sign-extend the address.
341 */
342 zsaddr[zs_unit] =
343 (struct zsdevice *)
344 (unsigned long)sa->sa_promvaddrs[0];
345 } else {
346 bus_space_handle_t kvaddr;
347
348 if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
349 sa->sa_offset,
350 sa->sa_size,
351 BUS_SPACE_MAP_LINEAR,
352 0, &kvaddr) != 0) {
353 printf("%s @ sbus: cannot map registers\n",
354 self->dv_xname);
355 return;
356 }
357 zsaddr[zs_unit] = (struct zsdevice *)
358 (long)kvaddr;
359 }
360 }
361 /*
362 * Check to see if we're the console. We presume the input comes from
363 * the same location as the output, although that may not be true.
364 * To support input from the serial line but output to a display we
365 * would need to generate some really weird consdev vectors.
366 */
367 if (sa->sa_node == stdinnode) {
368 char buf[256];
369 int chan = 0;
370 int len;
371
372 if ((len = OF_instance_to_path(sa->sa_node, buf, sizeof(buf))) > 0) {
373 /* With zs nodes, the last :a or :b selects the channel */
374 if (buf[len] == 0) len--;
375 if (buf[len] == 'b') chan = 1;
376 /* But keyboards don't have a :a or :b */
377 }
378 zs_hwflags[zs_unit][chan] = ZS_HWFLAG_CONSOLE;
379 zs_conschan = zs_get_chan_addr(zs_unit, chan);
380 if (OF_getproplen(sa->sa_node, "keyboard") >= 0) {
381 cn_hw = &consdev_zs;
382 cn = &consdev_kd;
383 } else {
384 cn = &consdev_zs;
385 }
386 }
387 zs_attach(zsc, sa->sa_pri);
388 if (cn) {
389 cn_tab = cn;
390 (*cn->cn_init)(cn);
391 #ifdef KGDB
392 zs_kgdb_init();
393 #endif
394 }
395 }
396
397 static void
398 zs_attach_obio(parent, self, aux)
399 struct device *parent;
400 struct device *self;
401 void *aux;
402 {
403 #ifndef SUN4U
404 struct zsc_softc *zsc = (void *) self;
405 union obio_attach_args *uoba = aux;
406 int zs_unit = zsc->zsc_dev.dv_unit;
407
408 /* Use the mapping setup by the Sun PROM. */
409 if (zsaddr[zs_unit] == NULL)
410 zsaddr[zs_unit] = findzs(zs_unit);
411
412 if (uoba->uoba_isobio4 == 0) {
413 struct sbus_attach_args *sa = &uoba->uoba_sbus;
414 zsc->zsc_bustag = sa->sa_bustag;
415 zsc->zsc_dmatag = sa->sa_dmatag;
416 zs_attach(zsc, sa->sa_pri);
417 } else {
418 struct obio4_attach_args *oba = &uoba->uoba_oba4;
419 zsc->zsc_bustag = oba->oba_bustag;
420 zsc->zsc_dmatag = oba->oba_dmatag;
421 zs_attach(zsc, oba->oba_pri);
422 }
423 #endif
424 }
425 /*
426 * Attach a found zs.
427 *
428 * USE ROM PROPERTIES port-a-ignore-cd AND port-b-ignore-cd FOR
429 * SOFT CARRIER, AND keyboard PROPERTY FOR KEYBOARD/MOUSE?
430 */
431 static void
432 zs_attach(zsc, pri)
433 struct zsc_softc *zsc;
434 int pri;
435 {
436 struct zsc_attach_args zsc_args;
437 volatile struct zschan *zc;
438 struct zs_chanstate *cs;
439 int s, zs_unit, channel;
440 static int didintr, prevpri;
441
442 printf(" softpri %d\n", PIL_TTY);
443
444 /*
445 * Initialize software state for each channel.
446 */
447 zs_unit = zsc->zsc_dev.dv_unit;
448 for (channel = 0; channel < 2; channel++) {
449 zsc_args.channel = channel;
450 zsc_args.hwflags = zs_hwflags[zs_unit][channel];
451 cs = &zsc->zsc_cs_store[channel];
452 zsc->zsc_cs[channel] = cs;
453
454 cs->cs_channel = channel;
455 cs->cs_private = NULL;
456 cs->cs_ops = &zsops_null;
457 cs->cs_brg_clk = PCLK / 16;
458
459 zc = zs_get_chan_addr(zs_unit, channel);
460 if (zs_hwflags[zs_unit][channel] == ZS_HWFLAG_CONSOLE) {
461 zs_conschan = (struct zschan *)zc;
462 }
463 cs->cs_reg_csr = &zc->zc_csr;
464 cs->cs_reg_data = &zc->zc_data;
465
466 bcopy(zs_init_reg, cs->cs_creg, 16);
467 bcopy(zs_init_reg, cs->cs_preg, 16);
468
469 /* XXX: Get these from the PROM properties! */
470 /* XXX: See the mvme167 code. Better. */
471 if (zsc_args.hwflags & ZS_HWFLAG_CONSOLE)
472 cs->cs_defspeed = zs_get_speed(cs);
473 else
474 cs->cs_defspeed = zs_defspeed[zs_unit][channel];
475 cs->cs_defcflag = zs_def_cflag;
476
477 /* Make these correspond to cs_defcflag (-crtscts) */
478 cs->cs_rr0_dcd = ZSRR0_DCD;
479 cs->cs_rr0_cts = 0;
480 cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
481 cs->cs_wr5_rts = 0;
482
483 /*
484 * Clear the master interrupt enable.
485 * The INTENA is common to both channels,
486 * so just do it on the A channel.
487 */
488 if (channel == 0) {
489 zs_write_reg(cs, 9, 0);
490 }
491
492 /*
493 * Look for a child driver for this channel.
494 * The child attach will setup the hardware.
495 */
496 if (!config_found(&zsc->zsc_dev, (void *)&zsc_args, zs_print)) {
497 /* No sub-driver. Just reset it. */
498 u_char reset = (channel == 0) ?
499 ZSWR9_A_RESET : ZSWR9_B_RESET;
500 s = splzs();
501 zs_write_reg(cs, 9, reset);
502 splx(s);
503 }
504 }
505
506 /*
507 * Now safe to install interrupt handlers. Note the arguments
508 * to the interrupt handlers aren't used. Note, we only do this
509 * once since both SCCs interrupt at the same level and vector.
510 */
511 if (!didintr) {
512 didintr = 1;
513 prevpri = pri;
514 bus_intr_establish(zsc->zsc_bustag, pri, 0, zshard, NULL);
515 intr_establish(PIL_TTY, &levelsoft);
516 } else if (pri != prevpri)
517 panic("broken zs interrupt scheme");
518
519 evcnt_attach(&zsc->zsc_dev, "intr", &zsc->zsc_intrcnt);
520
521 /*
522 * Set the master interrupt enable and interrupt vector.
523 * (common to both channels, do it on A)
524 */
525 cs = zsc->zsc_cs[0];
526 s = splhigh();
527 /* interrupt vector */
528 zs_write_reg(cs, 2, zs_init_reg[2]);
529 /* master interrupt control (enable) */
530 zs_write_reg(cs, 9, zs_init_reg[9]);
531 splx(s);
532
533 #if 0
534 /*
535 * XXX: L1A hack - We would like to be able to break into
536 * the debugger during the rest of autoconfiguration, so
537 * lower interrupts just enough to let zs interrupts in.
538 * This is done after both zs devices are attached.
539 */
540 if (zs_unit == 1) {
541 printf("zs1: enabling zs interrupts\n");
542 (void)splfd(); /* XXX: splzs - 1 */
543 }
544 #endif
545 }
546
547 static int
548 zs_print(aux, name)
549 void *aux;
550 const char *name;
551 {
552 struct zsc_attach_args *args = aux;
553
554 if (name != NULL)
555 printf("%s: ", name);
556
557 if (args->channel != -1)
558 printf(" channel %d", args->channel);
559
560 return (UNCONF);
561 }
562
563 static volatile int zssoftpending;
564
565 /*
566 * Our ZS chips all share a common, autovectored interrupt,
567 * so we have to look at all of them on each interrupt.
568 */
569 static int
570 zshard(arg)
571 void *arg;
572 {
573 register struct zsc_softc *zsc;
574 register int unit, rr3, rval, softreq;
575
576 rval = softreq = 0;
577 for (unit = 0; unit < zs_cd.cd_ndevs; unit++) {
578 zsc = zs_cd.cd_devs[unit];
579 if (zsc == NULL)
580 continue;
581 rr3 = zsc_intr_hard(zsc);
582 /* Count up the interrupts. */
583 if (rr3) {
584 rval |= rr3;
585 zsc->zsc_intrcnt.ev_count++;
586 }
587 softreq |= zsc->zsc_cs[0]->cs_softreq;
588 softreq |= zsc->zsc_cs[1]->cs_softreq;
589 }
590
591 /* We are at splzs here, so no need to lock. */
592 if (softreq && (zssoftpending == 0)) {
593 zssoftpending = IE_ZSSOFT;
594 #if defined(SUN4M)
595 if (CPU_ISSUN4M)
596 raise(0, PIL_TTY);
597 else
598 #endif
599 ienab_bis(IE_ZSSOFT);
600 }
601 return (rval);
602 }
603
604 /*
605 * Similar scheme as for zshard (look at all of them)
606 */
607 static int
608 zssoft(arg)
609 void *arg;
610 {
611 register struct zsc_softc *zsc;
612 register int s, unit;
613
614 /* This is not the only ISR on this IPL. */
615 if (zssoftpending == 0)
616 return (0);
617
618 /*
619 * The soft intr. bit will be set by zshard only if
620 * the variable zssoftpending is zero. The order of
621 * these next two statements prevents our clearing
622 * the soft intr bit just after zshard has set it.
623 */
624 /* ienab_bic(IE_ZSSOFT); */
625 zssoftpending = 0;
626
627 /* Make sure we call the tty layer at spltty. */
628 s = spltty();
629 for (unit = 0; unit < zs_cd.cd_ndevs; unit++) {
630 zsc = zs_cd.cd_devs[unit];
631 if (zsc == NULL)
632 continue;
633 (void)zsc_intr_soft(zsc);
634 }
635 splx(s);
636 return (1);
637 }
638
639
640 /*
641 * Compute the current baud rate given a ZS channel.
642 */
643 static int
644 zs_get_speed(cs)
645 struct zs_chanstate *cs;
646 {
647 int tconst;
648
649 tconst = zs_read_reg(cs, 12);
650 tconst |= zs_read_reg(cs, 13) << 8;
651 return (TCONST_TO_BPS(cs->cs_brg_clk, tconst));
652 }
653
654 /*
655 * MD functions for setting the baud rate and control modes.
656 */
657 int
658 zs_set_speed(cs, bps)
659 struct zs_chanstate *cs;
660 int bps; /* bits per second */
661 {
662 int tconst, real_bps;
663
664 if (bps == 0)
665 return (0);
666
667 #ifdef DIAGNOSTIC
668 if (cs->cs_brg_clk == 0)
669 panic("zs_set_speed");
670 #endif
671
672 tconst = BPS_TO_TCONST(cs->cs_brg_clk, bps);
673 if (tconst < 0)
674 return (EINVAL);
675
676 /* Convert back to make sure we can do it. */
677 real_bps = TCONST_TO_BPS(cs->cs_brg_clk, tconst);
678
679 /* XXX - Allow some tolerance here? */
680 if (real_bps != bps)
681 return (EINVAL);
682
683 cs->cs_preg[12] = tconst;
684 cs->cs_preg[13] = tconst >> 8;
685
686 /* Caller will stuff the pending registers. */
687 return (0);
688 }
689
690 int
691 zs_set_modes(cs, cflag)
692 struct zs_chanstate *cs;
693 int cflag; /* bits per second */
694 {
695 int s;
696
697 /*
698 * Output hardware flow control on the chip is horrendous:
699 * if carrier detect drops, the receiver is disabled, and if
700 * CTS drops, the transmitter is stoped IN MID CHARACTER!
701 * Therefore, NEVER set the HFC bit, and instead use the
702 * status interrupt to detect CTS changes.
703 */
704 s = splzs();
705 cs->cs_rr0_pps = 0;
706 if ((cflag & (CLOCAL | MDMBUF)) != 0) {
707 cs->cs_rr0_dcd = 0;
708 if ((cflag & MDMBUF) == 0)
709 cs->cs_rr0_pps = ZSRR0_DCD;
710 } else
711 cs->cs_rr0_dcd = ZSRR0_DCD;
712 if ((cflag & CRTSCTS) != 0) {
713 cs->cs_wr5_dtr = ZSWR5_DTR;
714 cs->cs_wr5_rts = ZSWR5_RTS;
715 cs->cs_rr0_cts = ZSRR0_CTS;
716 } else if ((cflag & CDTRCTS) != 0) {
717 cs->cs_wr5_dtr = 0;
718 cs->cs_wr5_rts = ZSWR5_DTR;
719 cs->cs_rr0_cts = ZSRR0_CTS;
720 } else if ((cflag & MDMBUF) != 0) {
721 cs->cs_wr5_dtr = 0;
722 cs->cs_wr5_rts = ZSWR5_DTR;
723 cs->cs_rr0_cts = ZSRR0_DCD;
724 } else {
725 cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
726 cs->cs_wr5_rts = 0;
727 cs->cs_rr0_cts = 0;
728 }
729 splx(s);
730
731 /* Caller will stuff the pending registers. */
732 return (0);
733 }
734
735
736 /*
737 * Read or write the chip with suitable delays.
738 */
739
740 u_char
741 zs_read_reg(cs, reg)
742 struct zs_chanstate *cs;
743 u_char reg;
744 {
745 u_char val;
746
747 *cs->cs_reg_csr = reg;
748 ZS_DELAY();
749 val = *cs->cs_reg_csr;
750 ZS_DELAY();
751 return (val);
752 }
753
754 void
755 zs_write_reg(cs, reg, val)
756 struct zs_chanstate *cs;
757 u_char reg, val;
758 {
759 *cs->cs_reg_csr = reg;
760 ZS_DELAY();
761 *cs->cs_reg_csr = val;
762 ZS_DELAY();
763 }
764
765 u_char
766 zs_read_csr(cs)
767 struct zs_chanstate *cs;
768 {
769 register u_char val;
770
771 val = *cs->cs_reg_csr;
772 ZS_DELAY();
773 return (val);
774 }
775
776 void zs_write_csr(cs, val)
777 struct zs_chanstate *cs;
778 u_char val;
779 {
780 *cs->cs_reg_csr = val;
781 ZS_DELAY();
782 }
783
784 u_char zs_read_data(cs)
785 struct zs_chanstate *cs;
786 {
787 register u_char val;
788
789 val = *cs->cs_reg_data;
790 ZS_DELAY();
791 return (val);
792 }
793
794 void zs_write_data(cs, val)
795 struct zs_chanstate *cs;
796 u_char val;
797 {
798 *cs->cs_reg_data = val;
799 ZS_DELAY();
800 }
801
802 /****************************************************************
803 * Console support functions (Sun specific!)
804 * Note: this code is allowed to know about the layout of
805 * the chip registers, and uses that to keep things simple.
806 * XXX - I think I like the mvme167 code better. -gwr
807 ****************************************************************/
808
809 extern void Debugger __P((void));
810 void *zs_conschan;
811
812 /*
813 * Handle user request to enter kernel debugger.
814 */
815 void
816 zs_abort(cs)
817 struct zs_chanstate *cs;
818 {
819 register volatile struct zschan *zc = zs_conschan;
820 int rr0;
821
822 /* Wait for end of break to avoid PROM abort. */
823 /* XXX - Limit the wait? */
824 do {
825 rr0 = zc->zc_csr;
826 ZS_DELAY();
827 } while (rr0 & ZSRR0_BREAK);
828
829 #if defined(KGDB)
830 zskgdb(cs);
831 #elif defined(DDB)
832 {
833 extern int db_active;
834
835 if (!db_active)
836 Debugger();
837 else
838 /* Debugger is probably hozed */
839 callrom();
840 }
841 #else
842 printf("stopping on keyboard abort\n");
843 callrom();
844 #endif
845 }
846
847 /*
848 * Polled input char.
849 */
850 int
851 zs_getc(arg)
852 void *arg;
853 {
854 register volatile struct zschan *zc = arg;
855 register int s, c, rr0;
856
857 s = splhigh();
858 /* Wait for a character to arrive. */
859 do {
860 rr0 = zc->zc_csr;
861 ZS_DELAY();
862 } while ((rr0 & ZSRR0_RX_READY) == 0);
863
864 c = zc->zc_data;
865 ZS_DELAY();
866 splx(s);
867
868 /*
869 * This is used by the kd driver to read scan codes,
870 * so don't translate '\r' ==> '\n' here...
871 */
872 return (c);
873 }
874
875 /*
876 * Polled output char.
877 */
878 void
879 zs_putc(arg, c)
880 void *arg;
881 int c;
882 {
883 register volatile struct zschan *zc = arg;
884 register int s, rr0;
885
886 s = splhigh();
887
888 /* Wait for transmitter to become ready. */
889 do {
890 rr0 = zc->zc_csr;
891 ZS_DELAY();
892 } while ((rr0 & ZSRR0_TX_READY) == 0);
893
894 /*
895 * Send the next character.
896 * Now you'd think that this could be followed by a ZS_DELAY()
897 * just like all the other chip accesses, but it turns out that
898 * the `transmit-ready' interrupt isn't de-asserted until
899 * some period of time after the register write completes
900 * (more than a couple instructions). So to avoid stray
901 * interrupts we put in the 2us delay regardless of cpu model.
902 */
903 zc->zc_data = c;
904 delay(2);
905
906 splx(s);
907 }
908
909 /*****************************************************************/
910
911 static void zscninit __P((struct consdev *));
912 static int zscngetc __P((dev_t));
913 static void zscnputc __P((dev_t, int));
914 static void zscnpollc __P((dev_t, int));
915 /*
916 * Console table shared by ttya, ttyb
917 */
918 struct consdev consdev_zs = {
919 nullcnprobe,
920 zscninit,
921 zscngetc,
922 zscnputc,
923 zscnpollc,
924 };
925
926 static void
927 zscninit(cn)
928 struct consdev *cn;
929 {
930 }
931
932 /*
933 * Polled console input putchar.
934 */
935 static int
936 zscngetc(dev)
937 dev_t dev;
938 {
939 return (zs_getc(zs_conschan));
940 }
941
942 /*
943 * Polled console output putchar.
944 */
945 static void
946 zscnputc(dev, c)
947 dev_t dev;
948 int c;
949 {
950 zs_putc(zs_conschan, c);
951 }
952
953 int swallow_zsintrs;
954
955 static void
956 zscnpollc(dev, on)
957 dev_t dev;
958 int on;
959 {
960 /*
961 * Need to tell zs driver to acknowledge all interrupts or we get
962 * annoying spurious interrupt messages. This is because mucking
963 * with spl() levels during polling does not prevent interrupts from
964 * being generated.
965 */
966
967 if (on) swallow_zsintrs++;
968 else swallow_zsintrs--;
969 }
970