zs_ioasic.c revision 1.1 1 /* $NetBSD: zs_ioasic.c,v 1.1 2000/07/05 02:48:50 nisimura 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 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
41
42 __KERNEL_RCSID(0, "$NetBSD: zs_ioasic.c,v 1.1 2000/07/05 02:48:50 nisimura Exp $");
43
44 /*
45 * Zilog Z8530 Dual UART driver (machine-dependent part). This driver
46 * handles Z8530 chips attached to the Alpha IOASIC. Modified for
47 * NetBSD/alpha by Ken Hornstein and Jason R. Thorpe.
48 *
49 * Runs two serial lines per chip using slave drivers.
50 * Plain tty/async lines use the zstty slave.
51 */
52
53 #include "opt_ddb.h"
54 #include "opt_dec_3000_300.h"
55 #include "opt_zs_ioasic_dma.h"
56 #include "zskbd.h"
57
58 #include <sys/param.h>
59 #include <sys/systm.h>
60 #include <sys/conf.h>
61 #include <sys/device.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 1
84 #define SPARSE
85 #endif
86
87 /*
88 * Helpers for console support.
89 */
90
91 int zs_ioasic_cngetc __P((dev_t));
92 void zs_ioasic_cnputc __P((dev_t, int));
93 void zs_ioasic_cnpollc __P((dev_t, int));
94
95 struct consdev zs_ioasic_cons = {
96 NULL, NULL, zs_ioasic_cngetc, zs_ioasic_cnputc,
97 zs_ioasic_cnpollc, NULL, NODEV, CN_NORMAL,
98 };
99
100 tc_offset_t zs_ioasic_console_offset;
101 int zs_ioasic_console_channel;
102 int zs_ioasic_console;
103
104 int zs_ioasic_isconsole __P((tc_offset_t, int));
105
106 struct zs_chanstate zs_ioasic_conschanstate_store;
107 struct zs_chanstate *zs_ioasic_conschanstate;
108
109 int zs_getc __P((struct zs_chanstate *));
110 void zs_putc __P((struct zs_chanstate *, int));
111 void zs_ioasic_cninit __P((tc_addr_t, tc_offset_t, int));
112
113 /*
114 * Some warts needed by z8530tty.c
115 */
116 int zs_def_cflag = (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8;
117 int zs_major = 15;
118
119 /*
120 * The Alpha provides a 7.372 MHz clock to the ZS chips.
121 */
122 #define PCLK (9600 * 768) /* PCLK pin input clock rate */
123
124 /* The layout of this is hardware-dependent (padding, order). */
125 struct zshan {
126 volatile u_int zc_csr; /* ctrl,status, and indirect access */
127 #ifdef SPARSE
128 u_int zc_pad0;
129 #endif
130 volatile u_int zc_data; /* data */
131 #ifdef SPARSE
132 u_int sc_pad1;
133 #endif
134 };
135
136 struct zsdevice {
137 /* Yes, they are backwards. */
138 struct zshan zs_chan_b;
139 struct zshan zs_chan_a;
140 };
141
142 static u_char zs_ioasic_init_reg[16] = {
143 0, /* 0: CMD (reset, etc.) */
144 0, /* 1: No interrupts yet. */
145 0xf0, /* 2: IVECT */
146 ZSWR3_RX_8 | ZSWR3_RX_ENABLE,
147 ZSWR4_CLK_X16 | ZSWR4_ONESB,
148 ZSWR5_TX_8 | ZSWR5_TX_ENABLE,
149 0, /* 6: TXSYNC/SYNCLO */
150 0, /* 7: RXSYNC/SYNCHI */
151 0, /* 8: alias for data port */
152 ZSWR9_MASTER_IE | ZSWR9_VECTOR_INCL_STAT,
153 0, /*10: Misc. TX/RX control bits */
154 ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD,
155 22, /*12: BAUDLO (default=9600) */
156 0, /*13: BAUDHI (default=9600) */
157 ZSWR14_BAUD_ENA | ZSWR14_BAUD_FROM_PCLK,
158 ZSWR15_BREAK_IE,
159 };
160
161 struct zshan *zs_ioasic_get_chan_addr __P((tc_addr_t, int));
162
163 struct zshan *
164 zs_ioasic_get_chan_addr(zsaddr, channel)
165 tc_addr_t zsaddr;
166 int channel;
167 {
168 struct zsdevice *addr;
169 struct zshan *zc;
170
171 addr = (struct zsdevice *) zsaddr;
172 #ifdef SPARSE
173 addr = (struct zsdevice *) TC_DENSE_TO_SPARSE((tc_addr_t) addr);
174 #endif
175
176 if (channel == 0)
177 zc = &addr->zs_chan_a;
178 else
179 zc = &addr->zs_chan_b;
180
181 return (zc);
182 }
183
184
185 /****************************************************************
186 * Autoconfig
187 ****************************************************************/
188
189 /* Definition of the driver for autoconfig. */
190 int zs_ioasic_match __P((struct device *, struct cfdata *, void *));
191 void zs_ioasic_attach __P((struct device *, struct device *, void *));
192 int zs_ioasic_print __P((void *, const char *name));
193
194 struct cfattach zsc_ioasic_ca = {
195 sizeof(struct zsc_softc), zs_ioasic_match, zs_ioasic_attach
196 };
197
198 /* Interrupt handlers. */
199 int zs_ioasic_hardintr __P((void *));
200 void zs_ioasic_softintr __P((void *));
201
202 /* Misc. */
203 void zs_ioasic_enable __P((int));
204
205 extern struct cfdriver ioasic_cd;
206 extern struct cfdriver zsc_cd;
207
208 /*
209 * Is the zs chip present?
210 */
211 int
212 zs_ioasic_match(parent, cf, aux)
213 struct device *parent;
214 struct cfdata *cf;
215 void *aux;
216 {
217 struct ioasicdev_attach_args *d = aux;
218 void *zs_addr;
219
220 if (parent->dv_cfdata->cf_driver != &ioasic_cd)
221 return (0);
222
223 /*
224 * Make sure that we're looking for the right kind of device.
225 */
226 if (strncmp(d->iada_modname, "z8530 ", TC_ROM_LLEN) != 0 &&
227 strncmp(d->iada_modname, "scc", TC_ROM_LLEN) != 0)
228 return (0);
229
230 /*
231 * Check user-specified offset against the ioasic offset.
232 * Allow it to be wildcarded.
233 */
234 if (cf->cf_loc[IOASICCF_OFFSET] != IOASICCF_OFFSET_DEFAULT &&
235 cf->cf_loc[IOASICCF_OFFSET] != d->iada_offset)
236 return (0);
237
238 /*
239 * Find out the device address, and check it for validity.
240 */
241 zs_addr = (void *) d->iada_addr;
242 #ifdef SPARSE
243 zs_addr = (void *) TC_DENSE_TO_SPARSE((tc_addr_t) zs_addr);
244 #endif
245 if (tc_badaddr(zs_addr))
246 return (0);
247
248 return (1);
249 }
250
251 /*
252 * Attach a found zs.
253 */
254 void
255 zs_ioasic_attach(parent, self, aux)
256 struct device *parent;
257 struct device *self;
258 void *aux;
259 {
260 struct zsc_softc *zs = (void *) self;
261 struct zsc_attach_args zs_args;
262 struct zs_chanstate *cs;
263 struct ioasicdev_attach_args *d = aux;
264 volatile struct zshan *zc;
265 tc_addr_t zs_addr;
266 int s, channel;
267
268 printf("\n");
269
270 /*
271 * Initialize software state for each channel.
272 */
273 for (channel = 0; channel < 2; channel++) {
274 zs_args.channel = channel;
275 zs_args.hwflags = 0;
276
277 cs = &zs->zsc_cs_store[channel];
278 zs->zsc_cs[channel] = cs;
279
280 /*
281 * If we're the console, copy the channel state, and
282 * adjust the console channel pointer.
283 */
284 if (zs_ioasic_isconsole(d->iada_offset, channel)) {
285 bcopy(zs_ioasic_conschanstate, cs,
286 sizeof(struct zs_chanstate));
287 zs_ioasic_conschanstate = cs;
288 zs_args.hwflags |= ZS_HWFLAG_CONSOLE;
289 } else {
290 zs_addr = d->iada_addr;
291 zc = zs_ioasic_get_chan_addr(zs_addr, channel);
292 cs->cs_reg_csr = (volatile u_char *)&zc->zc_csr;
293 cs->cs_reg_data = (volatile u_char *)&zc->zc_data;
294
295 bcopy(zs_ioasic_init_reg, cs->cs_creg, 16);
296 bcopy(zs_ioasic_init_reg, cs->cs_preg, 16);
297
298 cs->cs_defcflag = zs_def_cflag;
299 cs->cs_defspeed = 9600; /* XXX */
300 (void) zs_set_modes(cs, cs->cs_defcflag);
301 }
302
303 cs->cs_channel = channel;
304 cs->cs_ops = &zsops_null;
305 cs->cs_brg_clk = PCLK / 16;
306
307 /*
308 * DCD and CTS interrupts are only meaningful on
309 * SCC 0/B.
310 *
311 * XXX This is sorta gross.
312 */
313 if (d->iada_offset == 0x00100000 && channel == 1)
314 (u_long)cs->cs_private = ZIP_FLAGS_DCDCTS;
315 else
316 cs->cs_private = NULL;
317
318 /*
319 * Clear the master interrupt enable.
320 * The INTENA is common to both channels,
321 * so just do it on the A channel.
322 */
323 if (channel == 0) {
324 zs_write_reg(cs, 9, 0);
325 }
326
327 #ifdef notyet /* XXX thorpej */
328 /*
329 * Set up the flow/modem control channel pointer to
330 * deal with the weird wiring on the TC Alpha and
331 * DECstation.
332 */
333 if (channel == 1)
334 cs->cs_ctl_chan = zs->zsc_cs[0];
335 else
336 cs->cs_ctl_chan = NULL;
337 #endif
338
339 /*
340 * Look for a child driver for this channel.
341 * The child attach will setup the hardware.
342 */
343 if (config_found(self, (void *)&zs_args, zs_ioasic_print)
344 == NULL) {
345 /* No sub-driver. Just reset it. */
346 u_char reset = (channel == 0) ?
347 ZSWR9_A_RESET : ZSWR9_B_RESET;
348 s = splhigh();
349 zs_write_reg(cs, 9, reset);
350 splx(s);
351 }
352 }
353
354 /*
355 * Set up the ioasic interrupt handler.
356 */
357 ioasic_intr_establish(parent, d->iada_cookie, TC_IPL_TTY,
358 zs_ioasic_hardintr, zs);
359 zs->zsc_sih = softintr_establish(IPL_SOFTSERIAL,
360 zs_ioasic_softintr, zs);
361 if (zs->zsc_sih == NULL)
362 panic("zs_ioasic_attach: unable to register softintr");
363
364 /*
365 * Set the master interrupt enable and interrupt vector. The
366 * Sun does this only on one channel. The old Alpha SCC driver
367 * did it on both. We'll do it on both.
368 */
369 s = splhigh();
370 /* interrupt vector */
371 zs_write_reg(zs->zsc_cs[0], 2, zs_ioasic_init_reg[2]);
372 zs_write_reg(zs->zsc_cs[1], 2, zs_ioasic_init_reg[2]);
373
374 /* master interrupt control (enable) */
375 zs_write_reg(zs->zsc_cs[0], 9, zs_ioasic_init_reg[9]);
376 zs_write_reg(zs->zsc_cs[1], 9, zs_ioasic_init_reg[9]);
377
378 /* ioasic interrupt enable */
379 zs_ioasic_enable(1);
380 splx(s);
381 }
382
383 int
384 zs_ioasic_print(aux, name)
385 void *aux;
386 const char *name;
387 {
388 struct zsc_attach_args *args = aux;
389
390 if (name != NULL)
391 printf("%s:", name);
392
393 if (args->channel != -1)
394 printf(" channel %d", args->channel);
395
396 return (UNCONF);
397 }
398
399 /*
400 * Enable the SCC interrupts in the ioasic.
401 */
402 void
403 zs_ioasic_enable(onoff)
404 int onoff;
405 {
406
407 if (onoff) {
408 *(volatile u_int *)(ioasic_base + IOASIC_IMSK) |=
409 IOASIC_INTR_SCC_1 | IOASIC_INTR_SCC_0;
410 #if !defined(DEC_3000_300) && defined(ZS_IOASIC_DMA)
411 *(volatile u_int *)(ioasic_base + IOASIC_CSR) |=
412 IOASIC_CSR_DMAEN_T1 | IOASIC_CSR_DMAEN_R1 |
413 IOASIC_CSR_DMAEN_T2 | IOASIC_CSR_DMAEN_R2;
414 #endif
415 } else {
416 *(volatile u_int *)(ioasic_base + IOASIC_IMSK) &=
417 ~(IOASIC_INTR_SCC_1 | IOASIC_INTR_SCC_0);
418 #if !defined(DEC_3000_300) && defined(ZS_IOASIC_DMA)
419 *(volatile u_int *)(ioasic_base + IOASIC_CSR) &=
420 ~(IOASIC_CSR_DMAEN_T1 | IOASIC_CSR_DMAEN_R1 |
421 IOASIC_CSR_DMAEN_T2 | IOASIC_CSR_DMAEN_R2);
422 #endif
423 }
424 tc_mb();
425 }
426
427 /*
428 * Hardware interrupt handler.
429 */
430 int
431 zs_ioasic_hardintr(arg)
432 void *arg;
433 {
434 struct zsc_softc *zsc = arg;
435
436 /*
437 * Call the upper-level MI hardware interrupt handler.
438 */
439 zsc_intr_hard(zsc);
440
441 /*
442 * Check to see if we need to schedule any software-level
443 * processing interrupts.
444 */
445 if (zsc->zsc_cs[0]->cs_softreq | zsc->zsc_cs[1]->cs_softreq)
446 softintr_schedule(zsc->zsc_sih);
447
448 return (1);
449 }
450
451 /*
452 * Software-level interrupt (character processing, lower priority).
453 */
454 void
455 zs_ioasic_softintr(arg)
456 void *arg;
457 {
458 struct zsc_softc *zsc = arg;
459 int s;
460
461 s = spltty();
462 (void) zsc_intr_soft(zsc);
463 splx(s);
464 }
465
466 /*
467 * MD functions for setting the baud rate and control modes.
468 */
469 int
470 zs_set_speed(cs, bps)
471 struct zs_chanstate *cs;
472 int bps; /* bits per second */
473 {
474 int tconst, real_bps;
475
476 if (bps == 0)
477 return (0);
478
479 #ifdef DIAGNOSTIC
480 if (cs->cs_brg_clk == 0)
481 panic("zs_set_speed");
482 #endif
483
484 tconst = BPS_TO_TCONST(cs->cs_brg_clk, bps);
485 if (tconst < 0)
486 return (EINVAL);
487
488 /* Convert back to make sure we can do it. */
489 real_bps = TCONST_TO_BPS(cs->cs_brg_clk, tconst);
490
491 /* XXX - Allow some tolerance here? */
492 if (real_bps != bps)
493 return (EINVAL);
494
495 cs->cs_preg[12] = tconst;
496 cs->cs_preg[13] = tconst >> 8;
497
498 /* Caller will stuff the pending registers. */
499 return (0);
500 }
501
502 int
503 zs_set_modes(cs, cflag)
504 struct zs_chanstate *cs;
505 int cflag; /* bits per second */
506 {
507 u_long privflags = (u_long)cs->cs_private;
508 int s;
509
510 /*
511 * Output hardware flow control on the chip is horrendous:
512 * if carrier detect drops, the receiver is disabled, and if
513 * CTS drops, the transmitter is stoped IN MID CHARACTER!
514 * Therefore, NEVER set the HFC bit, and instead use the
515 * status interrupt to detect CTS changes.
516 */
517 s = splzs();
518 if ((cflag & (CLOCAL | MDMBUF)) != 0)
519 cs->cs_rr0_dcd = 0;
520 else
521 cs->cs_rr0_dcd = ZSRR0_DCD;
522 if ((cflag & CRTSCTS) != 0) {
523 cs->cs_wr5_dtr = ZSWR5_DTR;
524 cs->cs_wr5_rts = ZSWR5_RTS;
525 cs->cs_rr0_cts = ZSRR0_CTS;
526 } else if ((cflag & CDTRCTS) != 0) {
527 cs->cs_wr5_dtr = 0;
528 cs->cs_wr5_rts = ZSWR5_DTR;
529 cs->cs_rr0_cts = ZSRR0_CTS;
530 } else if ((cflag & MDMBUF) != 0) {
531 cs->cs_wr5_dtr = 0;
532 cs->cs_wr5_rts = ZSWR5_DTR;
533 cs->cs_rr0_cts = ZSRR0_DCD;
534 } else {
535 cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
536 cs->cs_wr5_rts = 0;
537 cs->cs_rr0_cts = 0;
538 }
539
540 if ((privflags & ZIP_FLAGS_DCDCTS) == 0) {
541 cs->cs_rr0_dcd &= ~(ZSRR0_CTS|ZSRR0_DCD);
542 cs->cs_rr0_cts &= ~(ZSRR0_CTS|ZSRR0_DCD);
543 }
544 splx(s);
545
546 /* Caller will stuff the pending registers. */
547 return (0);
548 }
549
550 /*
551 * Read or write the chip with suitable delays.
552 */
553 u_char
554 zs_read_reg(cs, reg)
555 struct zs_chanstate *cs;
556 u_char reg;
557 {
558 u_char val;
559
560 *((volatile unsigned int *) cs->cs_reg_csr) =
561 ((volatile unsigned int) reg) << 8;
562 tc_mb();
563 DELAY(5);
564
565 val = ((*(volatile unsigned int *) cs->cs_reg_csr) >> 8) & 0xff;
566 tc_mb();
567 DELAY(5);
568
569 return (val);
570 }
571
572 void
573 zs_write_reg(cs, reg, val)
574 struct zs_chanstate *cs;
575 u_char reg, val;
576 {
577
578 *((volatile unsigned int *) cs->cs_reg_csr) =
579 ((volatile unsigned int) reg) << 8;
580 tc_mb();
581 DELAY(5);
582
583 *((volatile unsigned int *) cs->cs_reg_csr) =
584 ((volatile unsigned int) val) << 8;
585 tc_mb();
586 DELAY(5);
587 }
588
589 u_char
590 zs_read_csr(cs)
591 struct zs_chanstate *cs;
592 {
593 register u_char val;
594
595 val = (*((volatile unsigned int *) cs->cs_reg_csr) >> 8) & 0xff;
596 tc_mb();
597 DELAY(5);
598
599 return (val);
600 }
601
602 void
603 zs_write_csr(cs, val)
604 struct zs_chanstate *cs;
605 u_char val;
606 {
607
608 *((volatile unsigned int *) cs->cs_reg_csr) =
609 ((volatile unsigned int) val) << 8;
610 tc_mb();
611 DELAY(5);
612 }
613
614 u_char
615 zs_read_data(cs)
616 struct zs_chanstate *cs;
617 {
618 register u_char val;
619
620 val = (*((volatile unsigned int *) cs->cs_reg_data) >> 8) & 0xff;
621 tc_mb();
622 DELAY(5);
623
624 return (val);
625 }
626
627 void
628 zs_write_data(cs, val)
629 struct zs_chanstate *cs;
630 u_char val;
631 {
632
633 *((volatile unsigned int *) cs->cs_reg_data) =
634 ((volatile unsigned int) val) << 8;
635 tc_mb();
636 DELAY(5);
637 }
638
639 /****************************************************************
640 * Console support functions (Alpha TC specific!)
641 ****************************************************************/
642
643 /*
644 * Handle user request to enter kernel debugger.
645 */
646 void
647 zs_abort(cs)
648 struct zs_chanstate *cs;
649 {
650 int rr0;
651
652 /* Wait for end of break. */
653 /* XXX - Limit the wait? */
654 do {
655 rr0 = zs_read_csr(cs);
656 } while (rr0 & ZSRR0_BREAK);
657
658 #if defined(KGDB)
659 zskgdb(cs);
660 #elif defined(DDB)
661 Debugger();
662 #else
663 printf("zs_abort: ignoring break on console\n");
664 #endif
665 }
666
667 /*
668 * Polled input char.
669 */
670 int
671 zs_getc(cs)
672 struct zs_chanstate *cs;
673 {
674 int s, c, rr0;
675
676 s = splhigh();
677 /* Wait for a character to arrive. */
678 do {
679 rr0 = zs_read_csr(cs);
680 } while ((rr0 & ZSRR0_RX_READY) == 0);
681
682 c = zs_read_data(cs);
683 splx(s);
684
685 /*
686 * This is used by the kd driver to read scan codes,
687 * so don't translate '\r' ==> '\n' here...
688 */
689 return (c);
690 }
691
692 /*
693 * Polled output char.
694 */
695 void
696 zs_putc(cs, c)
697 struct zs_chanstate *cs;
698 int c;
699 {
700 register int s, rr0;
701
702 s = splhigh();
703 /* Wait for transmitter to become ready. */
704 do {
705 rr0 = zs_read_csr(cs);
706 } while ((rr0 & ZSRR0_TX_READY) == 0);
707
708 zs_write_data(cs, c);
709
710 /* Wait for the character to be transmitted. */
711 do {
712 rr0 = zs_read_csr(cs);
713 } while ((rr0 & ZSRR0_TX_READY) == 0);
714 splx(s);
715 }
716
717 /*****************************************************************/
718
719 /*
720 * zs_ioasic_cninit --
721 * Initialize the serial channel for console use--either the
722 * primary keyboard or as the serial console.
723 */
724 void
725 zs_ioasic_cninit(ioasic_addr, zs_offset, channel)
726 tc_addr_t ioasic_addr;
727 tc_offset_t zs_offset;
728 int channel;
729 {
730 struct zs_chanstate *cs;
731 tc_addr_t zs_addr;
732 struct zshan *zc;
733
734 /*
735 * Initialize the console finder helpers.
736 */
737 zs_ioasic_console_offset = zs_offset;
738 zs_ioasic_console_channel = channel;
739 zs_ioasic_console = 1;
740
741 /*
742 * Pointer to channel state. Later, the console channel
743 * state is copied into the softc, and the console channel
744 * pointer adjusted to point to the new copy.
745 */
746 zs_ioasic_conschanstate = cs = &zs_ioasic_conschanstate_store;
747
748 /*
749 * Compute the physical address of the chip, "map" it via
750 * K0SEG, and then get the address of the actual channel.
751 */
752 zs_addr = ALPHA_PHYS_TO_K0SEG(ioasic_addr + zs_offset);
753 zc = zs_ioasic_get_chan_addr(zs_addr, channel);
754
755 /* Setup temporary chanstate. */
756 cs->cs_reg_csr = (volatile u_char *)&zc->zc_csr;
757 cs->cs_reg_data = (volatile u_char *)&zc->zc_data;
758
759 /* Initialize the pending registers. */
760 bcopy(zs_ioasic_init_reg, cs->cs_preg, 16);
761 cs->cs_preg[5] |= (ZSWR5_DTR | ZSWR5_RTS);
762
763 /*
764 * DCD and CTS interrupts are only meaningful on
765 * SCC 0/B.
766 *
767 * XXX This is sorta gross.
768 */
769 if (zs_offset == 0x00100000 && channel == 1)
770 (u_long)cs->cs_private = ZIP_FLAGS_DCDCTS;
771 else
772 cs->cs_private = NULL;
773
774 /* Clear the master interrupt enable. */
775 zs_write_reg(cs, 9, 0);
776
777 /* Reset the whole SCC chip. */
778 zs_write_reg(cs, 9, ZSWR9_HARD_RESET);
779
780 /* Copy "pending" to "current" and H/W. */
781 zs_loadchannelregs(cs);
782 }
783
784 /*
785 * zs_ioasic_cnattach --
786 * Initialize and attach a serial console.
787 */
788 int
789 zs_ioasic_cnattach(ioasic_addr, zs_offset, channel, rate, cflag)
790 tc_addr_t ioasic_addr;
791 tc_offset_t zs_offset;
792 int channel, rate, cflag;
793 {
794 zs_ioasic_cninit(ioasic_addr, zs_offset, channel);
795
796 zs_ioasic_conschanstate->cs_defspeed = rate;
797 zs_ioasic_conschanstate->cs_defcflag = cflag;
798
799 /* Point the console at the SCC. */
800 cn_tab = &zs_ioasic_cons;
801
802 return (0);
803 }
804
805 /*
806 * zs_ioasic_lk201_cnattach --
807 * Initialize and attach the primary keyboard.
808 */
809 int
810 zs_ioasic_lk201_cnattach(ioasic_addr, zs_offset, channel)
811 tc_addr_t ioasic_addr;
812 tc_offset_t zs_offset;
813 int channel;
814 {
815 #if (NZSKBD > 0)
816 zs_ioasic_cninit(ioasic_addr, zs_offset, channel);
817 zs_ioasic_conschanstate->cs_defspeed = 4800;
818 zs_ioasic_conschanstate->cs_defcflag =
819 (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8;
820 zs_ioasic_conschanstate->cs_brg_clk = PCLK / 16;
821 return (zskbd_cnattach(zs_ioasic_conschanstate));
822 #else
823 return (ENXIO);
824 #endif
825 }
826
827 int
828 zs_ioasic_isconsole(offset, channel)
829 tc_offset_t offset;
830 int channel;
831 {
832
833 if (zs_ioasic_console &&
834 offset == zs_ioasic_console_offset &&
835 channel == zs_ioasic_console_channel)
836 return (1);
837
838 return (0);
839 }
840
841 /*
842 * Polled console input putchar.
843 */
844 int
845 zs_ioasic_cngetc(dev)
846 dev_t dev;
847 {
848
849 return (zs_getc(zs_ioasic_conschanstate));
850 }
851
852 /*
853 * Polled console output putchar.
854 */
855 void
856 zs_ioasic_cnputc(dev, c)
857 dev_t dev;
858 int c;
859 {
860
861 zs_putc(zs_ioasic_conschanstate, c);
862 }
863
864 /*
865 * Set polling/no polling on console.
866 */
867 void
868 zs_ioasic_cnpollc(dev, onoff)
869 dev_t dev;
870 int onoff;
871 {
872
873 /* XXX ??? */
874 }
875