zs_ioasic.c revision 1.15 1 /* $NetBSD: zs_ioasic.c,v 1.15 2002/09/27 02:24:33 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 1996, 1998 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, Ken Hornstein, and by Jason R. Thorpe of the
9 * Numerical Aerospace Simulation Facility, NASA Ames Research Center.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 /*
41 * Zilog Z8530 Dual UART driver (machine-dependent part). This driver
42 * handles Z8530 chips attached to the DECstation/Alpha IOASIC. Modified
43 * for NetBSD/alpha by Ken Hornstein and Jason R. Thorpe. NetBSD/pmax
44 * adaption by Mattias Drochner. Merge work by Tohru Nishimura.
45 *
46 * Runs two serial lines per chip using slave drivers.
47 * Plain tty/async lines use the zstty slave.
48 */
49
50 #include <sys/cdefs.h>
51 __KERNEL_RCSID(0, "$NetBSD: zs_ioasic.c,v 1.15 2002/09/27 02:24:33 thorpej Exp $");
52
53 #include "opt_ddb.h"
54 #include "opt_kgdb.h"
55 #include "zskbd.h"
56
57 #include <sys/param.h>
58 #include <sys/systm.h>
59 #include <sys/conf.h>
60 #include <sys/device.h>
61 #include <sys/malloc.h>
62 #include <sys/file.h>
63 #include <sys/ioctl.h>
64 #include <sys/kernel.h>
65 #include <sys/proc.h>
66 #include <sys/tty.h>
67 #include <sys/time.h>
68 #include <sys/syslog.h>
69
70 #include <machine/autoconf.h>
71 #include <machine/intr.h>
72 #include <machine/z8530var.h>
73
74 #include <dev/cons.h>
75 #include <dev/ic/z8530reg.h>
76
77 #include <dev/tc/tcvar.h>
78 #include <dev/tc/ioasicreg.h>
79 #include <dev/tc/ioasicvar.h>
80
81 #include <dev/tc/zs_ioasicvar.h>
82
83 #if defined(__alpha__) || defined(alpha)
84 #include <machine/rpb.h>
85 #endif
86 #if defined(pmax)
87 #include <pmax/pmax/pmaxtype.h>
88 #endif
89
90 /*
91 * Helpers for console support.
92 */
93 void zs_ioasic_cninit __P((tc_addr_t, tc_offset_t, int));
94 int zs_ioasic_cngetc __P((dev_t));
95 void zs_ioasic_cnputc __P((dev_t, int));
96 void zs_ioasic_cnpollc __P((dev_t, int));
97
98 struct consdev zs_ioasic_cons = {
99 NULL, NULL, zs_ioasic_cngetc, zs_ioasic_cnputc,
100 zs_ioasic_cnpollc, NULL, NODEV, CN_NORMAL,
101 };
102
103 tc_offset_t zs_ioasic_console_offset;
104 int zs_ioasic_console_channel;
105 int zs_ioasic_console;
106 struct zs_chanstate zs_ioasic_conschanstate_store;
107
108 int zs_ioasic_isconsole __P((tc_offset_t, int));
109 int zs_getc __P((struct zs_chanstate *));
110 void zs_putc __P((struct zs_chanstate *, int));
111
112 /*
113 * Some warts needed by z8530tty.c
114 */
115 int zs_def_cflag = (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8;
116
117 /*
118 * ZS chips are feeded a 7.372 MHz clock.
119 */
120 #define PCLK (9600 * 768) /* PCLK pin input clock rate */
121
122 /* The layout of this is hardware-dependent (padding, order). */
123 struct zshan {
124 #if defined(__alpha__) || defined(alpha)
125 volatile u_int zc_csr; /* ctrl,status, and indirect access */
126 u_int zc_pad0;
127 volatile u_int zc_data; /* data */
128 u_int sc_pad1;
129 #endif
130 #if defined(pmax)
131 volatile u_int16_t zc_csr; /* ctrl,status, and indirect access */
132 unsigned : 16;
133 volatile u_int16_t zc_data; /* data */
134 unsigned : 16;
135 #endif
136 };
137
138 struct zsdevice {
139 /* Yes, they are backwards. */
140 struct zshan zs_chan_b;
141 struct zshan zs_chan_a;
142 };
143
144 static u_char zs_ioasic_init_reg[16] = {
145 0, /* 0: CMD (reset, etc.) */
146 0, /* 1: No interrupts yet. */
147 0xf0, /* 2: IVECT */
148 ZSWR3_RX_8 | ZSWR3_RX_ENABLE,
149 ZSWR4_CLK_X16 | ZSWR4_ONESB,
150 ZSWR5_TX_8 | ZSWR5_TX_ENABLE,
151 0, /* 6: TXSYNC/SYNCLO */
152 0, /* 7: RXSYNC/SYNCHI */
153 0, /* 8: alias for data port */
154 ZSWR9_MASTER_IE | ZSWR9_VECTOR_INCL_STAT,
155 0, /*10: Misc. TX/RX control bits */
156 ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD,
157 22, /*12: BAUDLO (default=9600) */
158 0, /*13: BAUDHI (default=9600) */
159 ZSWR14_BAUD_ENA | ZSWR14_BAUD_FROM_PCLK,
160 ZSWR15_BREAK_IE,
161 };
162
163 struct zshan *zs_ioasic_get_chan_addr __P((tc_addr_t, int));
164
165 struct zshan *
166 zs_ioasic_get_chan_addr(zsaddr, channel)
167 tc_addr_t zsaddr;
168 int channel;
169 {
170 struct zsdevice *addr;
171 struct zshan *zc;
172
173 #if defined(__alpha__) || defined(alpha)
174 addr = (struct zsdevice *)TC_DENSE_TO_SPARSE(zsaddr);
175 #endif
176 #if defined(pmax)
177 addr = (struct zsdevice *)MIPS_PHYS_TO_KSEG1(zsaddr);
178 #endif
179
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 int zs_ioasic_match __P((struct device *, struct cfdata *, void *));
195 void zs_ioasic_attach __P((struct device *, struct device *, void *));
196 int zs_ioasic_print __P((void *, const char *name));
197 int zs_ioasic_submatch __P((struct device *, struct cfdata *, void *));
198
199 struct cfattach zsc_ioasic_ca = {
200 sizeof(struct zsc_softc), zs_ioasic_match, zs_ioasic_attach
201 };
202
203 /* Interrupt handlers. */
204 int zs_ioasic_hardintr __P((void *));
205 void zs_ioasic_softintr __P((void *));
206
207 /*
208 * Is the zs chip present?
209 */
210 int
211 zs_ioasic_match(parent, cf, aux)
212 struct device *parent;
213 struct cfdata *cf;
214 void *aux;
215 {
216 struct ioasicdev_attach_args *d = aux;
217 tc_addr_t zs_addr;
218
219 /*
220 * Make sure that we're looking for the right kind of device.
221 */
222 if (strncmp(d->iada_modname, "z8530 ", TC_ROM_LLEN) != 0 &&
223 strncmp(d->iada_modname, "scc", TC_ROM_LLEN) != 0)
224 return (0);
225
226 /*
227 * Check user-specified offset against the ioasic offset.
228 * Allow it to be wildcarded.
229 */
230 if (cf->cf_loc[IOASICCF_OFFSET] != IOASICCF_OFFSET_DEFAULT &&
231 cf->cf_loc[IOASICCF_OFFSET] != d->iada_offset)
232 return (0);
233
234 /*
235 * Find out the device address, and check it for validity.
236 */
237 zs_addr = TC_DENSE_TO_SPARSE((tc_addr_t)d->iada_addr);
238 if (tc_badaddr(zs_addr))
239 return (0);
240
241 return (1);
242 }
243
244 /*
245 * Attach a found zs.
246 */
247 void
248 zs_ioasic_attach(parent, self, aux)
249 struct device *parent;
250 struct device *self;
251 void *aux;
252 {
253 struct zsc_softc *zs = (void *) self;
254 struct zsc_attach_args zs_args;
255 struct zs_chanstate *cs;
256 struct ioasicdev_attach_args *d = aux;
257 struct zshan *zc;
258 int s, channel;
259 u_long zflg;
260
261 printf("\n");
262
263 /*
264 * Initialize software state for each channel.
265 */
266 for (channel = 0; channel < 2; channel++) {
267 zs_args.channel = channel;
268 zs_args.hwflags = 0;
269
270 if (zs_ioasic_isconsole(d->iada_offset, channel)) {
271 cs = &zs_ioasic_conschanstate_store;
272 zs_args.hwflags |= ZS_HWFLAG_CONSOLE;
273 } else {
274 cs = malloc(sizeof(struct zs_chanstate),
275 M_DEVBUF, M_NOWAIT|M_ZERO);
276 zc = zs_ioasic_get_chan_addr(d->iada_addr, channel);
277 cs->cs_reg_csr = (void *)&zc->zc_csr;
278
279 bcopy(zs_ioasic_init_reg, cs->cs_creg, 16);
280 bcopy(zs_ioasic_init_reg, cs->cs_preg, 16);
281
282 cs->cs_defcflag = zs_def_cflag;
283 cs->cs_defspeed = 9600; /* XXX */
284 (void) zs_set_modes(cs, cs->cs_defcflag);
285 }
286
287 zs->zsc_cs[channel] = cs;
288 zs->zsc_addroffset = d->iada_offset; /* cookie only */
289 cs->cs_channel = channel;
290 cs->cs_ops = &zsops_null;
291 cs->cs_brg_clk = PCLK / 16;
292
293 /*
294 * DCD and CTS interrupts are only meaningful on
295 * SCC 0/B, and RTS and DTR only on B of SCC 0 & 1.
296 *
297 * XXX This is sorta gross.
298 */
299 if (d->iada_offset == 0x00100000 && channel == 1) {
300 cs->cs_creg[15] |= ZSWR15_DCD_IE;
301 cs->cs_preg[15] |= ZSWR15_DCD_IE;
302 zflg = ZIP_FLAGS_DCDCTS;
303 } else
304 zflg = 0;
305 if (channel == 1)
306 zflg |= ZIP_FLAGS_DTRRTS;
307 (u_long)cs->cs_private = zflg;
308
309 /*
310 * Clear the master interrupt enable.
311 * The INTENA is common to both channels,
312 * so just do it on the A channel.
313 */
314 if (channel == 0) {
315 zs_write_reg(cs, 9, 0);
316 }
317
318 /*
319 * Set up the flow/modem control channel pointer to
320 * deal with the weird wiring on the TC Alpha and
321 * DECstation.
322 */
323 if (channel == 1)
324 cs->cs_ctl_chan = zs->zsc_cs[0];
325 else
326 cs->cs_ctl_chan = NULL;
327
328 /*
329 * Look for a child driver for this channel.
330 * The child attach will setup the hardware.
331 */
332 if (config_found_sm(self, (void *)&zs_args,
333 zs_ioasic_print, zs_ioasic_submatch) == NULL) {
334 /* No sub-driver. Just reset it. */
335 u_char reset = (channel == 0) ?
336 ZSWR9_A_RESET : ZSWR9_B_RESET;
337 s = splhigh();
338 zs_write_reg(cs, 9, reset);
339 splx(s);
340 }
341 }
342
343 /*
344 * Set up the ioasic interrupt handler.
345 */
346 ioasic_intr_establish(parent, d->iada_cookie, TC_IPL_TTY,
347 zs_ioasic_hardintr, zs);
348 zs->zsc_sih = softintr_establish(IPL_SOFTSERIAL,
349 zs_ioasic_softintr, zs);
350 if (zs->zsc_sih == NULL)
351 panic("zs_ioasic_attach: unable to register softintr");
352
353 /*
354 * Set the master interrupt enable and interrupt vector. The
355 * Sun does this only on one channel. The old Alpha SCC driver
356 * did it on both. We'll do it on both.
357 */
358 s = splhigh();
359 /* interrupt vector */
360 zs_write_reg(zs->zsc_cs[0], 2, zs_ioasic_init_reg[2]);
361 zs_write_reg(zs->zsc_cs[1], 2, zs_ioasic_init_reg[2]);
362
363 /* master interrupt control (enable) */
364 zs_write_reg(zs->zsc_cs[0], 9, zs_ioasic_init_reg[9]);
365 zs_write_reg(zs->zsc_cs[1], 9, zs_ioasic_init_reg[9]);
366 #if defined(__alpha__) || defined(alpha)
367 /* ioasic interrupt enable */
368 *(volatile u_int *)(ioasic_base + IOASIC_IMSK) |=
369 IOASIC_INTR_SCC_1 | IOASIC_INTR_SCC_0;
370 tc_mb();
371 #endif
372 splx(s);
373 }
374
375 int
376 zs_ioasic_print(aux, name)
377 void *aux;
378 const char *name;
379 {
380 struct zsc_attach_args *args = aux;
381
382 if (name != NULL)
383 printf("%s:", name);
384
385 if (args->channel != -1)
386 printf(" channel %d", args->channel);
387
388 return (UNCONF);
389 }
390
391 int
392 zs_ioasic_submatch(parent, cf, aux)
393 struct device *parent;
394 struct cfdata *cf;
395 void *aux;
396 {
397 struct zsc_softc *zs = (void *)parent;
398 struct zsc_attach_args *pa = aux;
399 char *defname = "";
400
401 if (cf->cf_loc[ZSCCF_CHANNEL] != ZSCCF_CHANNEL_DEFAULT &&
402 cf->cf_loc[ZSCCF_CHANNEL] != pa->channel)
403 return (0);
404 if (cf->cf_loc[ZSCCF_CHANNEL] == ZSCCF_CHANNEL_DEFAULT) {
405 if (pa->channel == 0) {
406 #if defined(pmax)
407 if (systype == DS_MAXINE)
408 return (0);
409 #endif
410 if (zs->zsc_addroffset == 0x100000)
411 defname = "vsms";
412 else
413 defname = "lkkbd";
414 }
415 else if (zs->zsc_addroffset == 0x100000)
416 defname = "zstty";
417 #if defined(pmax)
418 else if (systype == DS_MAXINE)
419 return (0);
420 #endif
421 #if defined(__alpha__) || defined(alpha)
422 else if (cputype == ST_DEC_3000_300)
423 return (0);
424 #endif
425 else
426 defname = "zstty"; /* 3min/3max+, DEC3000/500 */
427
428 if (strcmp(cf->cf_name, defname))
429 return (0);
430 }
431 return ((*cf->cf_attach->ca_match)(parent, cf, aux));
432 }
433
434 /*
435 * Hardware interrupt handler.
436 */
437 int
438 zs_ioasic_hardintr(arg)
439 void *arg;
440 {
441 struct zsc_softc *zsc = arg;
442
443 /*
444 * Call the upper-level MI hardware interrupt handler.
445 */
446 zsc_intr_hard(zsc);
447
448 /*
449 * Check to see if we need to schedule any software-level
450 * processing interrupts.
451 */
452 if (zsc->zsc_cs[0]->cs_softreq | zsc->zsc_cs[1]->cs_softreq)
453 softintr_schedule(zsc->zsc_sih);
454
455 return (1);
456 }
457
458 /*
459 * Software-level interrupt (character processing, lower priority).
460 */
461 void
462 zs_ioasic_softintr(arg)
463 void *arg;
464 {
465 struct zsc_softc *zsc = arg;
466 int s;
467
468 s = spltty();
469 (void) zsc_intr_soft(zsc);
470 splx(s);
471 }
472
473 /*
474 * MD functions for setting the baud rate and control modes.
475 */
476 int
477 zs_set_speed(cs, bps)
478 struct zs_chanstate *cs;
479 int bps; /* bits per second */
480 {
481 int tconst, real_bps;
482
483 if (bps == 0)
484 return (0);
485
486 #ifdef DIAGNOSTIC
487 if (cs->cs_brg_clk == 0)
488 panic("zs_set_speed");
489 #endif
490
491 tconst = BPS_TO_TCONST(cs->cs_brg_clk, bps);
492 if (tconst < 0)
493 return (EINVAL);
494
495 /* Convert back to make sure we can do it. */
496 real_bps = TCONST_TO_BPS(cs->cs_brg_clk, tconst);
497
498 /* XXX - Allow some tolerance here? */
499 if (real_bps != bps)
500 return (EINVAL);
501
502 cs->cs_preg[12] = tconst;
503 cs->cs_preg[13] = tconst >> 8;
504
505 /* Caller will stuff the pending registers. */
506 return (0);
507 }
508
509 int
510 zs_set_modes(cs, cflag)
511 struct zs_chanstate *cs;
512 int cflag; /* bits per second */
513 {
514 u_long privflags = (u_long)cs->cs_private;
515 int s;
516
517 /*
518 * Output hardware flow control on the chip is horrendous:
519 * if carrier detect drops, the receiver is disabled, and if
520 * CTS drops, the transmitter is stoped IN MID CHARACTER!
521 * Therefore, NEVER set the HFC bit, and instead use the
522 * status interrupt to detect CTS changes.
523 */
524 s = splzs();
525 if ((cflag & (CLOCAL | MDMBUF)) != 0)
526 cs->cs_rr0_dcd = 0;
527 else
528 cs->cs_rr0_dcd = ZSRR0_DCD;
529 if ((cflag & CRTSCTS) != 0) {
530 cs->cs_wr5_dtr = ZSWR5_DTR;
531 cs->cs_wr5_rts = ZSWR5_RTS;
532 cs->cs_rr0_cts = ZSRR0_CTS;
533 } else if ((cflag & CDTRCTS) != 0) {
534 cs->cs_wr5_dtr = 0;
535 cs->cs_wr5_rts = ZSWR5_DTR;
536 cs->cs_rr0_cts = ZSRR0_CTS;
537 } else if ((cflag & MDMBUF) != 0) {
538 cs->cs_wr5_dtr = 0;
539 cs->cs_wr5_rts = ZSWR5_DTR;
540 cs->cs_rr0_cts = ZSRR0_DCD;
541 } else {
542 cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
543 cs->cs_wr5_rts = 0;
544 cs->cs_rr0_cts = 0;
545 }
546
547 if ((privflags & ZIP_FLAGS_DCDCTS) == 0) {
548 cs->cs_rr0_dcd &= ~(ZSRR0_CTS|ZSRR0_DCD);
549 cs->cs_rr0_cts &= ~(ZSRR0_CTS|ZSRR0_DCD);
550 }
551 if ((privflags & ZIP_FLAGS_DTRRTS) == 0) {
552 cs->cs_wr5_dtr &= ~(ZSWR5_RTS|ZSWR5_DTR);
553 cs->cs_wr5_rts &= ~(ZSWR5_RTS|ZSWR5_DTR);
554 }
555 splx(s);
556
557 /* Caller will stuff the pending registers. */
558 return (0);
559 }
560
561 /*
562 * Functions to read and write individual registers in a channel.
563 * The ZS chip requires a 1.6 uSec. recovery time between accesses,
564 * and the Alpha TC hardware does NOT take care of this for you.
565 * The delay is now handled inside the chip access functions.
566 * These could be inlines, but with the delay, speed is moot.
567 */
568 #if defined(pmax)
569 #undef DELAY
570 #define DELAY(x)
571 #endif
572
573 u_int
574 zs_read_reg(cs, reg)
575 struct zs_chanstate *cs;
576 u_int reg;
577 {
578 struct zshan *zc = (void *)cs->cs_reg_csr;
579 unsigned val;
580
581 zc->zc_csr = reg << 8;
582 tc_wmb();
583 DELAY(5);
584 val = (zc->zc_csr >> 8) & 0xff;
585 /* tc_mb(); */
586 DELAY(5);
587 return (val);
588 }
589
590 void
591 zs_write_reg(cs, reg, val)
592 struct zs_chanstate *cs;
593 u_int reg, val;
594 {
595 struct zshan *zc = (void *)cs->cs_reg_csr;
596
597 zc->zc_csr = reg << 8;
598 tc_wmb();
599 DELAY(5);
600 zc->zc_csr = val << 8;
601 tc_wmb();
602 DELAY(5);
603 }
604
605 u_int
606 zs_read_csr(cs)
607 struct zs_chanstate *cs;
608 {
609 struct zshan *zc = (void *)cs->cs_reg_csr;
610 unsigned val;
611
612 val = (zc->zc_csr >> 8) & 0xff;
613 /* tc_mb(); */
614 DELAY(5);
615 return (val);
616 }
617
618 void
619 zs_write_csr(cs, val)
620 struct zs_chanstate *cs;
621 u_int val;
622 {
623 struct zshan *zc = (void *)cs->cs_reg_csr;
624
625 zc->zc_csr = val << 8;
626 tc_wmb();
627 DELAY(5);
628 }
629
630 u_int
631 zs_read_data(cs)
632 struct zs_chanstate *cs;
633 {
634 struct zshan *zc = (void *)cs->cs_reg_csr;
635 unsigned val;
636
637 val = (zc->zc_data) >> 8 & 0xff;
638 /* tc_mb(); */
639 DELAY(5);
640 return (val);
641 }
642
643 void
644 zs_write_data(cs, val)
645 struct zs_chanstate *cs;
646 u_int val;
647 {
648 struct zshan *zc = (void *)cs->cs_reg_csr;
649
650 zc->zc_data = val << 8;
651 tc_wmb();
652 DELAY(5);
653 }
654
655 /****************************************************************
656 * Console support functions
657 ****************************************************************/
658
659 /*
660 * Handle user request to enter kernel debugger.
661 */
662 void
663 zs_abort(cs)
664 struct zs_chanstate *cs;
665 {
666 int rr0;
667
668 /* Wait for end of break. */
669 /* XXX - Limit the wait? */
670 do {
671 rr0 = zs_read_csr(cs);
672 } while (rr0 & ZSRR0_BREAK);
673
674 #if defined(KGDB)
675 zskgdb(cs);
676 #elif defined(DDB)
677 Debugger();
678 #else
679 printf("zs_abort: ignoring break on console\n");
680 #endif
681 }
682
683 /*
684 * Polled input char.
685 */
686 int
687 zs_getc(cs)
688 struct zs_chanstate *cs;
689 {
690 int s, c, rr0;
691
692 s = splhigh();
693 /* Wait for a character to arrive. */
694 do {
695 rr0 = zs_read_csr(cs);
696 } while ((rr0 & ZSRR0_RX_READY) == 0);
697
698 c = zs_read_data(cs);
699 splx(s);
700
701 /*
702 * This is used by the kd driver to read scan codes,
703 * so don't translate '\r' ==> '\n' here...
704 */
705 return (c);
706 }
707
708 /*
709 * Polled output char.
710 */
711 void
712 zs_putc(cs, c)
713 struct zs_chanstate *cs;
714 int c;
715 {
716 register int s, rr0;
717
718 s = splhigh();
719 /* Wait for transmitter to become ready. */
720 do {
721 rr0 = zs_read_csr(cs);
722 } while ((rr0 & ZSRR0_TX_READY) == 0);
723
724 zs_write_data(cs, c);
725
726 /* Wait for the character to be transmitted. */
727 do {
728 rr0 = zs_read_csr(cs);
729 } while ((rr0 & ZSRR0_TX_READY) == 0);
730 splx(s);
731 }
732
733 /*****************************************************************/
734
735 /*
736 * zs_ioasic_cninit --
737 * Initialize the serial channel for either a keyboard or
738 * a serial console.
739 */
740 void
741 zs_ioasic_cninit(ioasic_addr, zs_offset, channel)
742 tc_addr_t ioasic_addr;
743 tc_offset_t zs_offset;
744 int channel;
745 {
746 struct zs_chanstate *cs;
747 tc_addr_t zs_addr;
748 struct zshan *zc;
749 u_long zflg;
750
751 /*
752 * Initialize the console finder helpers.
753 */
754 zs_ioasic_console_offset = zs_offset;
755 zs_ioasic_console_channel = channel;
756 zs_ioasic_console = 1;
757
758 /*
759 * Pointer to channel state.
760 */
761 cs = &zs_ioasic_conschanstate_store;
762
763 /*
764 * Compute the physical address of the chip, "map" it via
765 * K0SEG, and then get the address of the actual channel.
766 */
767 #if defined(__alpha__) || defined(alpha)
768 zs_addr = ALPHA_PHYS_TO_K0SEG(ioasic_addr + zs_offset);
769 #endif
770 #if defined(pmax)
771 zs_addr = MIPS_PHYS_TO_KSEG1(ioasic_addr + zs_offset);
772 #endif
773 zc = zs_ioasic_get_chan_addr(zs_addr, channel);
774
775 /* Setup temporary chanstate. */
776 cs->cs_reg_csr = (void *)&zc->zc_csr;
777
778 cs->cs_channel = channel;
779 cs->cs_ops = &zsops_null;
780 cs->cs_brg_clk = PCLK / 16;
781
782 /* Initialize the pending registers. */
783 bcopy(zs_ioasic_init_reg, cs->cs_preg, 16);
784 /* cs->cs_preg[5] |= (ZSWR5_DTR | ZSWR5_RTS); */
785
786 /*
787 * DCD and CTS interrupts are only meaningful on
788 * SCC 0/B, and RTS and DTR only on B of SCC 0 & 1.
789 *
790 * XXX This is sorta gross.
791 */
792 if (zs_offset == 0x00100000 && channel == 1)
793 zflg = ZIP_FLAGS_DCDCTS;
794 else
795 zflg = 0;
796 if (channel == 1)
797 zflg |= ZIP_FLAGS_DTRRTS;
798 (u_long)cs->cs_private = zflg;
799
800 /* Clear the master interrupt enable. */
801 zs_write_reg(cs, 9, 0);
802
803 /* Reset the whole SCC chip. */
804 zs_write_reg(cs, 9, ZSWR9_HARD_RESET);
805
806 /* Copy "pending" to "current" and H/W. */
807 zs_loadchannelregs(cs);
808 }
809
810 /*
811 * zs_ioasic_cnattach --
812 * Initialize and attach a serial console.
813 */
814 void
815 zs_ioasic_cnattach(ioasic_addr, zs_offset, channel)
816 tc_addr_t ioasic_addr;
817 tc_offset_t zs_offset;
818 int channel;
819 {
820 struct zs_chanstate *cs = &zs_ioasic_conschanstate_store;
821 extern const struct cdevsw zstty_cdevsw;
822
823 zs_ioasic_cninit(ioasic_addr, zs_offset, channel);
824 cs->cs_defspeed = 9600;
825 cs->cs_defcflag = (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8;
826
827 /* Point the console at the SCC. */
828 cn_tab = &zs_ioasic_cons;
829 cn_tab->cn_pri = CN_REMOTE;
830 cn_tab->cn_dev = makedev(cdevsw_lookup_major(&zstty_cdevsw),
831 (zs_offset == 0x100000) ? 0 : 1);
832 }
833
834 /*
835 * zs_ioasic_lk201_cnattach --
836 * Initialize and attach a keyboard.
837 */
838 int
839 zs_ioasic_lk201_cnattach(ioasic_addr, zs_offset, channel)
840 tc_addr_t ioasic_addr;
841 tc_offset_t zs_offset;
842 int channel;
843 {
844 #if (NZSKBD > 0)
845 struct zs_chanstate *cs = &zs_ioasic_conschanstate_store;
846
847 zs_ioasic_cninit(ioasic_addr, zs_offset, channel);
848 cs->cs_defspeed = 4800;
849 cs->cs_defcflag = (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8;
850 return (zskbd_cnattach(cs));
851 #else
852 return (ENXIO);
853 #endif
854 }
855
856 int
857 zs_ioasic_isconsole(offset, channel)
858 tc_offset_t offset;
859 int channel;
860 {
861
862 if (zs_ioasic_console &&
863 offset == zs_ioasic_console_offset &&
864 channel == zs_ioasic_console_channel)
865 return (1);
866
867 return (0);
868 }
869
870 /*
871 * Polled console input putchar.
872 */
873 int
874 zs_ioasic_cngetc(dev)
875 dev_t dev;
876 {
877
878 return (zs_getc(&zs_ioasic_conschanstate_store));
879 }
880
881 /*
882 * Polled console output putchar.
883 */
884 void
885 zs_ioasic_cnputc(dev, c)
886 dev_t dev;
887 int c;
888 {
889
890 zs_putc(&zs_ioasic_conschanstate_store, c);
891 }
892
893 /*
894 * Set polling/no polling on console.
895 */
896 void
897 zs_ioasic_cnpollc(dev, onoff)
898 dev_t dev;
899 int onoff;
900 {
901
902 /* XXX ??? */
903 }
904