zs_ioasic.c revision 1.13 1 /* $NetBSD: zs_ioasic.c,v 1.13 2002/09/26 18:30:54 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.13 2002/09/26 18:30:54 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 extern struct cfdriver ioasic_cd;
208
209 /*
210 * Is the zs chip present?
211 */
212 int
213 zs_ioasic_match(parent, cf, aux)
214 struct device *parent;
215 struct cfdata *cf;
216 void *aux;
217 {
218 struct ioasicdev_attach_args *d = aux;
219 tc_addr_t zs_addr;
220
221 /*
222 * Make sure that we're looking for the right kind of device.
223 */
224 if (strncmp(d->iada_modname, "z8530 ", TC_ROM_LLEN) != 0 &&
225 strncmp(d->iada_modname, "scc", TC_ROM_LLEN) != 0)
226 return (0);
227
228 /*
229 * Check user-specified offset against the ioasic offset.
230 * Allow it to be wildcarded.
231 */
232 if (cf->cf_loc[IOASICCF_OFFSET] != IOASICCF_OFFSET_DEFAULT &&
233 cf->cf_loc[IOASICCF_OFFSET] != d->iada_offset)
234 return (0);
235
236 /*
237 * Find out the device address, and check it for validity.
238 */
239 zs_addr = TC_DENSE_TO_SPARSE((tc_addr_t)d->iada_addr);
240 if (tc_badaddr(zs_addr))
241 return (0);
242
243 return (1);
244 }
245
246 /*
247 * Attach a found zs.
248 */
249 void
250 zs_ioasic_attach(parent, self, aux)
251 struct device *parent;
252 struct device *self;
253 void *aux;
254 {
255 struct zsc_softc *zs = (void *) self;
256 struct zsc_attach_args zs_args;
257 struct zs_chanstate *cs;
258 struct ioasicdev_attach_args *d = aux;
259 struct zshan *zc;
260 int s, channel;
261 u_long zflg;
262
263 printf("\n");
264
265 /*
266 * Initialize software state for each channel.
267 */
268 for (channel = 0; channel < 2; channel++) {
269 zs_args.channel = channel;
270 zs_args.hwflags = 0;
271
272 if (zs_ioasic_isconsole(d->iada_offset, channel)) {
273 cs = &zs_ioasic_conschanstate_store;
274 zs_args.hwflags |= ZS_HWFLAG_CONSOLE;
275 } else {
276 cs = malloc(sizeof(struct zs_chanstate),
277 M_DEVBUF, M_NOWAIT|M_ZERO);
278 zc = zs_ioasic_get_chan_addr(d->iada_addr, channel);
279 cs->cs_reg_csr = (void *)&zc->zc_csr;
280
281 bcopy(zs_ioasic_init_reg, cs->cs_creg, 16);
282 bcopy(zs_ioasic_init_reg, cs->cs_preg, 16);
283
284 cs->cs_defcflag = zs_def_cflag;
285 cs->cs_defspeed = 9600; /* XXX */
286 (void) zs_set_modes(cs, cs->cs_defcflag);
287 }
288
289 zs->zsc_cs[channel] = cs;
290 zs->zsc_addroffset = d->iada_offset; /* cookie only */
291 cs->cs_channel = channel;
292 cs->cs_ops = &zsops_null;
293 cs->cs_brg_clk = PCLK / 16;
294
295 /*
296 * DCD and CTS interrupts are only meaningful on
297 * SCC 0/B, and RTS and DTR only on B of SCC 0 & 1.
298 *
299 * XXX This is sorta gross.
300 */
301 if (d->iada_offset == 0x00100000 && channel == 1) {
302 cs->cs_creg[15] |= ZSWR15_DCD_IE;
303 cs->cs_preg[15] |= ZSWR15_DCD_IE;
304 zflg = ZIP_FLAGS_DCDCTS;
305 } else
306 zflg = 0;
307 if (channel == 1)
308 zflg |= ZIP_FLAGS_DTRRTS;
309 (u_long)cs->cs_private = zflg;
310
311 /*
312 * Clear the master interrupt enable.
313 * The INTENA is common to both channels,
314 * so just do it on the A channel.
315 */
316 if (channel == 0) {
317 zs_write_reg(cs, 9, 0);
318 }
319
320 /*
321 * Set up the flow/modem control channel pointer to
322 * deal with the weird wiring on the TC Alpha and
323 * DECstation.
324 */
325 if (channel == 1)
326 cs->cs_ctl_chan = zs->zsc_cs[0];
327 else
328 cs->cs_ctl_chan = NULL;
329
330 /*
331 * Look for a child driver for this channel.
332 * The child attach will setup the hardware.
333 */
334 if (config_found_sm(self, (void *)&zs_args,
335 zs_ioasic_print, zs_ioasic_submatch) == NULL) {
336 /* No sub-driver. Just reset it. */
337 u_char reset = (channel == 0) ?
338 ZSWR9_A_RESET : ZSWR9_B_RESET;
339 s = splhigh();
340 zs_write_reg(cs, 9, reset);
341 splx(s);
342 }
343 }
344
345 /*
346 * Set up the ioasic interrupt handler.
347 */
348 ioasic_intr_establish(parent, d->iada_cookie, TC_IPL_TTY,
349 zs_ioasic_hardintr, zs);
350 zs->zsc_sih = softintr_establish(IPL_SOFTSERIAL,
351 zs_ioasic_softintr, zs);
352 if (zs->zsc_sih == NULL)
353 panic("zs_ioasic_attach: unable to register softintr");
354
355 /*
356 * Set the master interrupt enable and interrupt vector. The
357 * Sun does this only on one channel. The old Alpha SCC driver
358 * did it on both. We'll do it on both.
359 */
360 s = splhigh();
361 /* interrupt vector */
362 zs_write_reg(zs->zsc_cs[0], 2, zs_ioasic_init_reg[2]);
363 zs_write_reg(zs->zsc_cs[1], 2, zs_ioasic_init_reg[2]);
364
365 /* master interrupt control (enable) */
366 zs_write_reg(zs->zsc_cs[0], 9, zs_ioasic_init_reg[9]);
367 zs_write_reg(zs->zsc_cs[1], 9, zs_ioasic_init_reg[9]);
368 #if defined(__alpha__) || defined(alpha)
369 /* ioasic interrupt enable */
370 *(volatile u_int *)(ioasic_base + IOASIC_IMSK) |=
371 IOASIC_INTR_SCC_1 | IOASIC_INTR_SCC_0;
372 tc_mb();
373 #endif
374 splx(s);
375 }
376
377 int
378 zs_ioasic_print(aux, name)
379 void *aux;
380 const char *name;
381 {
382 struct zsc_attach_args *args = aux;
383
384 if (name != NULL)
385 printf("%s:", name);
386
387 if (args->channel != -1)
388 printf(" channel %d", args->channel);
389
390 return (UNCONF);
391 }
392
393 int
394 zs_ioasic_submatch(parent, cf, aux)
395 struct device *parent;
396 struct cfdata *cf;
397 void *aux;
398 {
399 struct zsc_softc *zs = (void *)parent;
400 struct zsc_attach_args *pa = aux;
401 char *defname = "";
402
403 if (cf->cf_loc[ZSCCF_CHANNEL] != ZSCCF_CHANNEL_DEFAULT &&
404 cf->cf_loc[ZSCCF_CHANNEL] != pa->channel)
405 return (0);
406 if (cf->cf_loc[ZSCCF_CHANNEL] == ZSCCF_CHANNEL_DEFAULT) {
407 if (pa->channel == 0) {
408 #if defined(pmax)
409 if (systype == DS_MAXINE)
410 return (0);
411 #endif
412 if (zs->zsc_addroffset == 0x100000)
413 defname = "vsms";
414 else
415 defname = "lkkbd";
416 }
417 else if (zs->zsc_addroffset == 0x100000)
418 defname = "zstty";
419 #if defined(pmax)
420 else if (systype == DS_MAXINE)
421 return (0);
422 #endif
423 #if defined(__alpha__) || defined(alpha)
424 else if (cputype == ST_DEC_3000_300)
425 return (0);
426 #endif
427 else
428 defname = "zstty"; /* 3min/3max+, DEC3000/500 */
429
430 if (strcmp(cf->cf_driver->cd_name, defname))
431 return (0);
432 }
433 return ((*cf->cf_attach->ca_match)(parent, cf, aux));
434 }
435
436 /*
437 * Hardware interrupt handler.
438 */
439 int
440 zs_ioasic_hardintr(arg)
441 void *arg;
442 {
443 struct zsc_softc *zsc = arg;
444
445 /*
446 * Call the upper-level MI hardware interrupt handler.
447 */
448 zsc_intr_hard(zsc);
449
450 /*
451 * Check to see if we need to schedule any software-level
452 * processing interrupts.
453 */
454 if (zsc->zsc_cs[0]->cs_softreq | zsc->zsc_cs[1]->cs_softreq)
455 softintr_schedule(zsc->zsc_sih);
456
457 return (1);
458 }
459
460 /*
461 * Software-level interrupt (character processing, lower priority).
462 */
463 void
464 zs_ioasic_softintr(arg)
465 void *arg;
466 {
467 struct zsc_softc *zsc = arg;
468 int s;
469
470 s = spltty();
471 (void) zsc_intr_soft(zsc);
472 splx(s);
473 }
474
475 /*
476 * MD functions for setting the baud rate and control modes.
477 */
478 int
479 zs_set_speed(cs, bps)
480 struct zs_chanstate *cs;
481 int bps; /* bits per second */
482 {
483 int tconst, real_bps;
484
485 if (bps == 0)
486 return (0);
487
488 #ifdef DIAGNOSTIC
489 if (cs->cs_brg_clk == 0)
490 panic("zs_set_speed");
491 #endif
492
493 tconst = BPS_TO_TCONST(cs->cs_brg_clk, bps);
494 if (tconst < 0)
495 return (EINVAL);
496
497 /* Convert back to make sure we can do it. */
498 real_bps = TCONST_TO_BPS(cs->cs_brg_clk, tconst);
499
500 /* XXX - Allow some tolerance here? */
501 if (real_bps != bps)
502 return (EINVAL);
503
504 cs->cs_preg[12] = tconst;
505 cs->cs_preg[13] = tconst >> 8;
506
507 /* Caller will stuff the pending registers. */
508 return (0);
509 }
510
511 int
512 zs_set_modes(cs, cflag)
513 struct zs_chanstate *cs;
514 int cflag; /* bits per second */
515 {
516 u_long privflags = (u_long)cs->cs_private;
517 int s;
518
519 /*
520 * Output hardware flow control on the chip is horrendous:
521 * if carrier detect drops, the receiver is disabled, and if
522 * CTS drops, the transmitter is stoped IN MID CHARACTER!
523 * Therefore, NEVER set the HFC bit, and instead use the
524 * status interrupt to detect CTS changes.
525 */
526 s = splzs();
527 if ((cflag & (CLOCAL | MDMBUF)) != 0)
528 cs->cs_rr0_dcd = 0;
529 else
530 cs->cs_rr0_dcd = ZSRR0_DCD;
531 if ((cflag & CRTSCTS) != 0) {
532 cs->cs_wr5_dtr = ZSWR5_DTR;
533 cs->cs_wr5_rts = ZSWR5_RTS;
534 cs->cs_rr0_cts = ZSRR0_CTS;
535 } else if ((cflag & CDTRCTS) != 0) {
536 cs->cs_wr5_dtr = 0;
537 cs->cs_wr5_rts = ZSWR5_DTR;
538 cs->cs_rr0_cts = ZSRR0_CTS;
539 } else if ((cflag & MDMBUF) != 0) {
540 cs->cs_wr5_dtr = 0;
541 cs->cs_wr5_rts = ZSWR5_DTR;
542 cs->cs_rr0_cts = ZSRR0_DCD;
543 } else {
544 cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
545 cs->cs_wr5_rts = 0;
546 cs->cs_rr0_cts = 0;
547 }
548
549 if ((privflags & ZIP_FLAGS_DCDCTS) == 0) {
550 cs->cs_rr0_dcd &= ~(ZSRR0_CTS|ZSRR0_DCD);
551 cs->cs_rr0_cts &= ~(ZSRR0_CTS|ZSRR0_DCD);
552 }
553 if ((privflags & ZIP_FLAGS_DTRRTS) == 0) {
554 cs->cs_wr5_dtr &= ~(ZSWR5_RTS|ZSWR5_DTR);
555 cs->cs_wr5_rts &= ~(ZSWR5_RTS|ZSWR5_DTR);
556 }
557 splx(s);
558
559 /* Caller will stuff the pending registers. */
560 return (0);
561 }
562
563 /*
564 * Functions to read and write individual registers in a channel.
565 * The ZS chip requires a 1.6 uSec. recovery time between accesses,
566 * and the Alpha TC hardware does NOT take care of this for you.
567 * The delay is now handled inside the chip access functions.
568 * These could be inlines, but with the delay, speed is moot.
569 */
570 #if defined(pmax)
571 #undef DELAY
572 #define DELAY(x)
573 #endif
574
575 u_int
576 zs_read_reg(cs, reg)
577 struct zs_chanstate *cs;
578 u_int reg;
579 {
580 struct zshan *zc = (void *)cs->cs_reg_csr;
581 unsigned val;
582
583 zc->zc_csr = reg << 8;
584 tc_wmb();
585 DELAY(5);
586 val = (zc->zc_csr >> 8) & 0xff;
587 /* tc_mb(); */
588 DELAY(5);
589 return (val);
590 }
591
592 void
593 zs_write_reg(cs, reg, val)
594 struct zs_chanstate *cs;
595 u_int reg, val;
596 {
597 struct zshan *zc = (void *)cs->cs_reg_csr;
598
599 zc->zc_csr = reg << 8;
600 tc_wmb();
601 DELAY(5);
602 zc->zc_csr = val << 8;
603 tc_wmb();
604 DELAY(5);
605 }
606
607 u_int
608 zs_read_csr(cs)
609 struct zs_chanstate *cs;
610 {
611 struct zshan *zc = (void *)cs->cs_reg_csr;
612 unsigned val;
613
614 val = (zc->zc_csr >> 8) & 0xff;
615 /* tc_mb(); */
616 DELAY(5);
617 return (val);
618 }
619
620 void
621 zs_write_csr(cs, val)
622 struct zs_chanstate *cs;
623 u_int val;
624 {
625 struct zshan *zc = (void *)cs->cs_reg_csr;
626
627 zc->zc_csr = val << 8;
628 tc_wmb();
629 DELAY(5);
630 }
631
632 u_int
633 zs_read_data(cs)
634 struct zs_chanstate *cs;
635 {
636 struct zshan *zc = (void *)cs->cs_reg_csr;
637 unsigned val;
638
639 val = (zc->zc_data) >> 8 & 0xff;
640 /* tc_mb(); */
641 DELAY(5);
642 return (val);
643 }
644
645 void
646 zs_write_data(cs, val)
647 struct zs_chanstate *cs;
648 u_int val;
649 {
650 struct zshan *zc = (void *)cs->cs_reg_csr;
651
652 zc->zc_data = val << 8;
653 tc_wmb();
654 DELAY(5);
655 }
656
657 /****************************************************************
658 * Console support functions
659 ****************************************************************/
660
661 /*
662 * Handle user request to enter kernel debugger.
663 */
664 void
665 zs_abort(cs)
666 struct zs_chanstate *cs;
667 {
668 int rr0;
669
670 /* Wait for end of break. */
671 /* XXX - Limit the wait? */
672 do {
673 rr0 = zs_read_csr(cs);
674 } while (rr0 & ZSRR0_BREAK);
675
676 #if defined(KGDB)
677 zskgdb(cs);
678 #elif defined(DDB)
679 Debugger();
680 #else
681 printf("zs_abort: ignoring break on console\n");
682 #endif
683 }
684
685 /*
686 * Polled input char.
687 */
688 int
689 zs_getc(cs)
690 struct zs_chanstate *cs;
691 {
692 int s, c, rr0;
693
694 s = splhigh();
695 /* Wait for a character to arrive. */
696 do {
697 rr0 = zs_read_csr(cs);
698 } while ((rr0 & ZSRR0_RX_READY) == 0);
699
700 c = zs_read_data(cs);
701 splx(s);
702
703 /*
704 * This is used by the kd driver to read scan codes,
705 * so don't translate '\r' ==> '\n' here...
706 */
707 return (c);
708 }
709
710 /*
711 * Polled output char.
712 */
713 void
714 zs_putc(cs, c)
715 struct zs_chanstate *cs;
716 int c;
717 {
718 register int s, rr0;
719
720 s = splhigh();
721 /* Wait for transmitter to become ready. */
722 do {
723 rr0 = zs_read_csr(cs);
724 } while ((rr0 & ZSRR0_TX_READY) == 0);
725
726 zs_write_data(cs, c);
727
728 /* Wait for the character to be transmitted. */
729 do {
730 rr0 = zs_read_csr(cs);
731 } while ((rr0 & ZSRR0_TX_READY) == 0);
732 splx(s);
733 }
734
735 /*****************************************************************/
736
737 /*
738 * zs_ioasic_cninit --
739 * Initialize the serial channel for either a keyboard or
740 * a serial console.
741 */
742 void
743 zs_ioasic_cninit(ioasic_addr, zs_offset, channel)
744 tc_addr_t ioasic_addr;
745 tc_offset_t zs_offset;
746 int channel;
747 {
748 struct zs_chanstate *cs;
749 tc_addr_t zs_addr;
750 struct zshan *zc;
751 u_long zflg;
752
753 /*
754 * Initialize the console finder helpers.
755 */
756 zs_ioasic_console_offset = zs_offset;
757 zs_ioasic_console_channel = channel;
758 zs_ioasic_console = 1;
759
760 /*
761 * Pointer to channel state.
762 */
763 cs = &zs_ioasic_conschanstate_store;
764
765 /*
766 * Compute the physical address of the chip, "map" it via
767 * K0SEG, and then get the address of the actual channel.
768 */
769 #if defined(__alpha__) || defined(alpha)
770 zs_addr = ALPHA_PHYS_TO_K0SEG(ioasic_addr + zs_offset);
771 #endif
772 #if defined(pmax)
773 zs_addr = MIPS_PHYS_TO_KSEG1(ioasic_addr + zs_offset);
774 #endif
775 zc = zs_ioasic_get_chan_addr(zs_addr, channel);
776
777 /* Setup temporary chanstate. */
778 cs->cs_reg_csr = (void *)&zc->zc_csr;
779
780 cs->cs_channel = channel;
781 cs->cs_ops = &zsops_null;
782 cs->cs_brg_clk = PCLK / 16;
783
784 /* Initialize the pending registers. */
785 bcopy(zs_ioasic_init_reg, cs->cs_preg, 16);
786 /* cs->cs_preg[5] |= (ZSWR5_DTR | ZSWR5_RTS); */
787
788 /*
789 * DCD and CTS interrupts are only meaningful on
790 * SCC 0/B, and RTS and DTR only on B of SCC 0 & 1.
791 *
792 * XXX This is sorta gross.
793 */
794 if (zs_offset == 0x00100000 && channel == 1)
795 zflg = ZIP_FLAGS_DCDCTS;
796 else
797 zflg = 0;
798 if (channel == 1)
799 zflg |= ZIP_FLAGS_DTRRTS;
800 (u_long)cs->cs_private = zflg;
801
802 /* Clear the master interrupt enable. */
803 zs_write_reg(cs, 9, 0);
804
805 /* Reset the whole SCC chip. */
806 zs_write_reg(cs, 9, ZSWR9_HARD_RESET);
807
808 /* Copy "pending" to "current" and H/W. */
809 zs_loadchannelregs(cs);
810 }
811
812 /*
813 * zs_ioasic_cnattach --
814 * Initialize and attach a serial console.
815 */
816 void
817 zs_ioasic_cnattach(ioasic_addr, zs_offset, channel)
818 tc_addr_t ioasic_addr;
819 tc_offset_t zs_offset;
820 int channel;
821 {
822 struct zs_chanstate *cs = &zs_ioasic_conschanstate_store;
823 extern const struct cdevsw zstty_cdevsw;
824
825 zs_ioasic_cninit(ioasic_addr, zs_offset, channel);
826 cs->cs_defspeed = 9600;
827 cs->cs_defcflag = (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8;
828
829 /* Point the console at the SCC. */
830 cn_tab = &zs_ioasic_cons;
831 cn_tab->cn_pri = CN_REMOTE;
832 cn_tab->cn_dev = makedev(cdevsw_lookup_major(&zstty_cdevsw),
833 (zs_offset == 0x100000) ? 0 : 1);
834 }
835
836 /*
837 * zs_ioasic_lk201_cnattach --
838 * Initialize and attach a keyboard.
839 */
840 int
841 zs_ioasic_lk201_cnattach(ioasic_addr, zs_offset, channel)
842 tc_addr_t ioasic_addr;
843 tc_offset_t zs_offset;
844 int channel;
845 {
846 #if (NZSKBD > 0)
847 struct zs_chanstate *cs = &zs_ioasic_conschanstate_store;
848
849 zs_ioasic_cninit(ioasic_addr, zs_offset, channel);
850 cs->cs_defspeed = 4800;
851 cs->cs_defcflag = (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8;
852 return (zskbd_cnattach(cs));
853 #else
854 return (ENXIO);
855 #endif
856 }
857
858 int
859 zs_ioasic_isconsole(offset, channel)
860 tc_offset_t offset;
861 int channel;
862 {
863
864 if (zs_ioasic_console &&
865 offset == zs_ioasic_console_offset &&
866 channel == zs_ioasic_console_channel)
867 return (1);
868
869 return (0);
870 }
871
872 /*
873 * Polled console input putchar.
874 */
875 int
876 zs_ioasic_cngetc(dev)
877 dev_t dev;
878 {
879
880 return (zs_getc(&zs_ioasic_conschanstate_store));
881 }
882
883 /*
884 * Polled console output putchar.
885 */
886 void
887 zs_ioasic_cnputc(dev, c)
888 dev_t dev;
889 int c;
890 {
891
892 zs_putc(&zs_ioasic_conschanstate_store, c);
893 }
894
895 /*
896 * Set polling/no polling on console.
897 */
898 void
899 zs_ioasic_cnpollc(dev, onoff)
900 dev_t dev;
901 int onoff;
902 {
903
904 /* XXX ??? */
905 }
906