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