1 /* $NetBSD: zs.c,v 1.57 2009/03/18 10:22:31 cegger Exp $ */
4 * Copyright (c) 1996-1998 Bill Studenmund
5 * Copyright (c) 1995 Gordon W. Ross
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * Zilog Z8530 Dual UART driver (machine-dependent part)
32 * Runs two serial lines per chip using slave drivers.
33 * Plain tty/async lines use the zs_async slave.
34 * Sun keyboard/mouse uses the zs_kbd/zs_ms slaves.
35 * Other ports use their own mice & keyboard slaves.
39 * With NetBSD 1.1, port-mac68k started using a port of the port-sparc
40 * (port-sun3?) zs.c driver (which was in turn based on code in the
41 * Berkeley 4.4 Lite release). Bill Studenmund did the port, with
42 * help from Allen Briggs and Gordon Ross <gwr@NetBSD.org>. Noud de
43 * Brouwer field-tested the driver at a local ISP.
45 * Bill Studenmund and Gordon Ross then ported the machine-independent
46 * z8530 driver to work with port-mac68k. NetBSD 1.2 contained an
47 * intermediate version (mac68k using a local, patched version of
48 * the m.i. drivers), with NetBSD 1.3 containing a full version.
51 #include <sys/cdefs.h>
52 __KERNEL_RCSID(0, "$NetBSD: zs.c,v 1.57 2009/03/18 10:22:31 cegger Exp $");
55 #include "opt_mac68k.h"
57 #include <sys/param.h>
58 #include <sys/systm.h>
60 #include <sys/device.h>
63 #include <sys/ioctl.h>
66 #include <sys/kernel.h>
67 #include <sys/syslog.h>
71 #include <machine/autoconf.h>
72 #include <machine/psc.h>
73 #include <machine/viareg.h>
76 #include <dev/ic/z8530reg.h>
77 #include <machine/z8530var.h>
78 #include <mac68k/dev/zs_cons.h>
80 /* Are these in a header file anywhere? */
81 /* Booter flags interface */
82 #define ZSMAC_RAW 0x01
83 #define ZSMAC_LOCALTALK 0x02
85 #define PCLK (9600 * 384)
88 * Some warts needed by z8530tty.c -
90 int zs_def_cflag
= (CREAD
| CS8
| HUPCL
);
93 * abort detection on console will now timeout after iterating on a loop
94 * the following # of times. Cheep hack. Also, abort detection is turned
95 * off after a timeout (i.e. maybe there's not a terminal hooked up).
97 #define ZSABORT_DELAY 3000000
100 * Define interrupt levels.
102 #define ZSHARD_PRI 4 /* Wired on the CPU board... */
104 * Serial port cards with zs chips on them are actually at the
105 * NuBus interrupt level, which is lower than 4. But blocking
106 * level 4 interrupts will block those interrupts too, so level
110 /* The layout of this is hardware-dependent (padding, order). */
112 volatile uint8_t zc_csr
; /* ctrl,status, and indirect access */
114 uint8_t zc_xxx1
; /* part of the other channel lives here! */
115 uint8_t zc_xxx2
; /* Yea Apple! */
116 volatile uint8_t zc_data
; /* data */
122 /* Flags from cninit() */
123 static int zs_hwflags
[2];
124 /* Default speed for each channel */
125 static int zs_defspeed
[2] = {
132 #ifdef ZS_CONSOLE_ABORT
133 int zs_cons_canabort
= 1;
135 int zs_cons_canabort
= 0;
136 #endif /* ZS_CONSOLE_ABORT*/
137 /* device to which the console is attached--if serial. */
140 extern volatile unsigned char *sccA
;
142 int zs_cn_check_speed(int);
145 * Even though zsparam will set up the clock multiples, etc., we
146 * still set them here as: 1) mice & keyboards don't use zsparam,
147 * and 2) the console stuff uses these defaults before device
151 static uint8_t zs_init_reg
[16] = {
152 0, /* 0: CMD (reset, etc.) */
153 0, /* 1: No interrupts yet. */
154 0x18 + ZSHARD_PRI
, /* IVECT */
155 ZSWR3_RX_8
| ZSWR3_RX_ENABLE
,
156 ZSWR4_CLK_X16
| ZSWR4_ONESB
| ZSWR4_EVENP
,
157 ZSWR5_TX_8
| ZSWR5_TX_ENABLE
,
158 0, /* 6: TXSYNC/SYNCLO */
159 0, /* 7: RXSYNC/SYNCHI */
160 0, /* 8: alias for data port */
162 0, /*10: Misc. TX/RX control bits */
163 ZSWR11_TXCLK_BAUD
| ZSWR11_RXCLK_BAUD
,
164 ((PCLK
/32)/9600)-2, /*12: BAUDLO (default=9600) */
165 0, /*13: BAUDHI (default=9600) */
171 zs_get_chan_addr(int channel
)
176 addr
= (char *)__UNVOLATILE(sccA
);
178 zc
= (struct zschan
*)(addr
+ 2);
179 /* handle the fact the ports are intertwined. */
181 zc
= (struct zschan
*)(addr
);
187 /* Find PROM mappings (for console support). */
188 int zsinited
= 0; /* 0 = not, 1 = inited, not attached, 2= attached */
194 if (zs_conschan
!= 0){ /* we might have moved io under the console */
195 zs_conschan
= zs_get_chan_addr(zs_consunit
);
196 /* so recalc the console port */
201 /****************************************************************
203 ****************************************************************/
205 /* Definition of the driver for autoconfig. */
206 static int zsc_match(device_t
, cfdata_t
, void *);
207 static void zsc_attach(device_t
, device_t
, void *);
208 static int zsc_print(void *, const char *);
210 CFATTACH_DECL_NEW(zsc
, sizeof(struct zsc_softc
),
211 zsc_match
, zsc_attach
, NULL
, NULL
);
213 extern struct cfdriver zsc_cd
;
218 * Is the zs chip present?
221 zsc_match(device_t parent
, cfdata_t cf
, void *aux
)
232 * Match slave number to zs unit number, so that misconfiguration will
233 * not set up the keyboard as ttya, etc.
236 zsc_attach(device_t parent
, device_t self
, void *aux
)
238 struct zsc_softc
*zsc
= device_private(self
);
239 struct zsc_attach_args zsc_args
;
240 volatile struct zschan
*zc
;
241 struct xzs_chanstate
*xcs
;
242 struct zs_chanstate
*cs
;
243 int s
, chip
, theflags
, channel
;
250 chip
= 0; /* We'll deal with chip types post 1.2 */
251 aprint_normal(" chip type %d \n",chip
);
254 * Initialize software state for each channel.
256 for (channel
= 0; channel
< 2; channel
++) {
257 zsc_args
.channel
= channel
;
258 zsc_args
.hwflags
= zs_hwflags
[channel
];
259 xcs
= &zsc
->xzsc_xcs_store
[channel
];
261 zsc
->zsc_cs
[channel
] = cs
;
264 cs
->cs_channel
= channel
;
265 cs
->cs_private
= NULL
;
266 cs
->cs_ops
= &zsops_null
;
268 zc
= zs_get_chan_addr(channel
);
269 cs
->cs_reg_csr
= &zc
->zc_csr
;
270 cs
->cs_reg_data
= &zc
->zc_data
;
272 memcpy(cs
->cs_creg
, zs_init_reg
, 16);
273 memcpy(cs
->cs_preg
, zs_init_reg
, 16);
275 /* Current BAUD rate generator clock. */
276 cs
->cs_brg_clk
= PCLK
/ 16; /* RTxC is 230400*16, so use 230400 */
277 cs
->cs_defspeed
= zs_defspeed
[channel
];
278 cs
->cs_defcflag
= zs_def_cflag
;
280 /* Make these correspond to cs_defcflag (-crtscts) */
281 cs
->cs_rr0_dcd
= ZSRR0_DCD
;
283 cs
->cs_wr5_dtr
= ZSWR5_DTR
;
287 cs
->cs_slave_type
= ZS_SLAVE_NONE
;
290 /* Define BAUD rate stuff. */
291 xcs
->cs_clocks
[0].clk
= PCLK
;
292 xcs
->cs_clocks
[0].flags
= ZSC_RTXBRG
| ZSC_RTXDIV
;
293 xcs
->cs_clocks
[1].flags
=
294 ZSC_RTXBRG
| ZSC_RTXDIV
| ZSC_VARIABLE
| ZSC_EXTERN
;
295 xcs
->cs_clocks
[2].flags
= ZSC_TRXDIV
| ZSC_VARIABLE
;
296 xcs
->cs_clock_count
= 3;
298 theflags
= mac68k_machine
.modem_flags
;
299 xcs
->cs_clocks
[1].clk
= mac68k_machine
.modem_dcd_clk
;
300 xcs
->cs_clocks
[2].clk
= mac68k_machine
.modem_cts_clk
;
302 theflags
= mac68k_machine
.print_flags
;
303 xcs
->cs_clocks
[1].flags
= ZSC_VARIABLE
;
305 * Yes, we aren't defining ANY clock source enables for the
306 * printer's DCD clock in. The hardware won't let us
307 * use it. But a clock will freak out the chip, so we
308 * let you set it, telling us to bar interrupts on the line.
310 xcs
->cs_clocks
[1].clk
= mac68k_machine
.print_dcd_clk
;
311 xcs
->cs_clocks
[2].clk
= mac68k_machine
.print_cts_clk
;
313 if (xcs
->cs_clocks
[1].clk
)
314 zsc_args
.hwflags
|= ZS_HWFLAG_NO_DCD
;
315 if (xcs
->cs_clocks
[2].clk
)
316 zsc_args
.hwflags
|= ZS_HWFLAG_NO_CTS
;
318 printf("zsc%d channel %d: d_speed %6d DCD clk %ld CTS clk %ld",
319 device_unit(self
), channel
, cs
->cs_defspeed
,
320 xcs
->cs_clocks
[1].clk
, xcs
->cs_clocks
[2].clk
);
322 /* Set defaults in our "extended" chanstate. */
325 xcs
->cs_cclk_flag
= 0; /* Nothing fancy by default */
326 xcs
->cs_pclk_flag
= 0;
328 if (theflags
& ZSMAC_RAW
) {
329 zsc_args
.hwflags
|= ZS_HWFLAG_RAW
;
330 printf(" (raw defaults)");
334 * XXX - This might be better done with a "stub" driver
335 * (to replace zstty) that ignores LocalTalk for now.
337 if (theflags
& ZSMAC_LOCALTALK
) {
338 printf(" shielding from LocalTalk");
340 cs
->cs_creg
[ZSRR_BAUDLO
] = cs
->cs_preg
[ZSRR_BAUDLO
] = 0xff;
341 cs
->cs_creg
[ZSRR_BAUDHI
] = cs
->cs_preg
[ZSRR_BAUDHI
] = 0xff;
342 zs_write_reg(cs
, ZSRR_BAUDLO
, 0xff);
343 zs_write_reg(cs
, ZSRR_BAUDHI
, 0xff);
345 * If we might have LocalTalk, then make sure we have the
346 * Baud rate low-enough to not do any damage.
351 * We used to disable chip interrupts here, but we now
352 * do that in zscnprobe, just in case MacOS left the chip on.
357 /* Stash away a copy of the final H/W flags. */
358 xcs
->cs_hwflags
= zsc_args
.hwflags
;
363 * Look for a child driver for this channel.
364 * The child attach will setup the hardware.
366 if (!config_found(self
, (void *)&zsc_args
, zsc_print
)) {
367 /* No sub-driver. Just reset it. */
368 uint8_t reset
= (channel
== 0) ?
369 ZSWR9_A_RESET
: ZSWR9_B_RESET
;
371 zs_write_reg(cs
, 9, reset
);
376 if (current_mac_model
->class == MACH_CLASSAV
) {
377 add_psc_lev4_intr(PSCINTR_SCCA
, zshard
, zsc
);
378 add_psc_lev4_intr(PSCINTR_SCCB
, zshard
, zsc
);
380 intr_establish(zshard
, zsc
, ZSHARD_PRI
);
382 zsc
->zsc_softintr_cookie
= softint_establish(SOFTINT_SERIAL
,
383 (void (*)(void *))zsc_intr_soft
, zsc
);
385 /* Now safe to enable interrupts. */
388 * Set the master interrupt enable and interrupt vector.
389 * (common to both channels, do it on A)
393 /* interrupt vector */
394 zs_write_reg(cs
, 2, zs_init_reg
[2]);
395 /* master interrupt control (enable) */
396 zs_write_reg(cs
, 9, zs_init_reg
[9]);
401 zsc_print(void *aux
, const char *name
)
403 struct zsc_attach_args
*args
= aux
;
406 aprint_normal("%s: ", name
);
408 if (args
->channel
!= -1)
409 aprint_normal(" channel %d", args
->channel
);
415 zsmdioctl(struct zs_chanstate
*cs
, u_long cmd
, void *data
)
419 return (EPASSTHROUGH
);
425 zsmd_setclock(struct zs_chanstate
*cs
)
427 struct xzs_chanstate
*xcs
= (void *)cs
;
429 if (cs
->cs_channel
!= 0)
433 * If the new clock has the external bit set, then select the
436 via_set_modem((xcs
->cs_pclk_flag
& ZSC_EXTERN
) ? 1 : 0);
440 * Do the minimum work to pull data off of the chip and queue it up
441 * for later processing.
446 struct zsc_softc
*zsc
= arg
;
452 rval
= zsc_intr_hard(zsc
);
453 if ((zsc
->zsc_cs
[0]->cs_softreq
) || (zsc
->zsc_cs
[1]->cs_softreq
)) {
454 softint_schedule(zsc
->zsc_softintr_cookie
);
460 #define ZS_TOLERANCE 51
461 /* 5% in tenths of a %, plus 1 so that exactly 5% will be ok. */
465 * check out a rate for acceptability from the internal clock
466 * source. Used in console config to validate a requested
467 * default speed. Placed here so that all the speed checking code is
473 zs_cn_check_speed(int bps
)
477 tc
= BPS_TO_TCONST(PCLK
/ 16, bps
);
480 rate
= TCONST_TO_BPS(PCLK
/ 16, tc
);
481 if (ZS_TOLERANCE
> abs(((rate
- bps
)*1000)/bps
))
488 * Search through the signal sources in the channel, and
489 * pick the best one for the baud rate requested. Return
490 * a -1 if not achievable in tolerance. Otherwise return 0
491 * and fill in the values.
493 * This routine draws inspiration from the Atari port's zs.c
494 * driver in NetBSD 1.1 which did the same type of source switching.
495 * Tolerance code inspired by comspeed routine in isa/com.c.
497 * By Bill Studenmund, 1996-05-12
500 zs_set_speed(struct zs_chanstate
*cs
, int bps
)
502 struct xzs_chanstate
*xcs
= (void *) cs
;
503 int i
, tc
, tc0
= 0, tc1
, s
, sf
= 0;
504 int src
, rate0
, rate1
, err
, tol
;
509 src
= -1; /* no valid source yet */
513 * Step through all the sources and see which one matches
514 * the best. A source has to match BETTER than tol to be chosen.
515 * Thus if two sources give the same error, the first one will be
516 * chosen. Also, allow for the possability that one source might run
517 * both the BRG and the direct divider (i.e. RTxC).
519 for (i
=0; i
< xcs
->cs_clock_count
; i
++) {
520 if (xcs
->cs_clocks
[i
].clk
<= 0)
521 continue; /* skip non-existent or bad clocks */
522 if (xcs
->cs_clocks
[i
].flags
& ZSC_BRG
) {
523 /* check out BRG at /16 */
524 tc1
= BPS_TO_TCONST(xcs
->cs_clocks
[i
].clk
>> 4, bps
);
526 rate1
= TCONST_TO_BPS(xcs
->cs_clocks
[i
].clk
>> 4, tc1
);
527 err
= abs(((rate1
- bps
)*1000)/bps
);
531 sf
= xcs
->cs_clocks
[i
].flags
& ~ZSC_DIV
;
537 if (xcs
->cs_clocks
[i
].flags
& ZSC_DIV
) {
539 * Check out either /1, /16, /32, or /64
540 * Note: for /1, you'd better be using a synchronized
543 int b0
= xcs
->cs_clocks
[i
].clk
, e0
= abs(b0
-bps
);
544 int b1
= b0
>> 4, e1
= abs(b1
-bps
);
545 int b2
= b1
>> 1, e2
= abs(b2
-bps
);
546 int b3
= b2
>> 1, e3
= abs(b3
-bps
);
548 if (e0
< e1
&& e0
< e2
&& e0
< e3
) {
552 } else if (e0
> e1
&& e1
< e2
&& e1
< e3
) {
556 } else if (e0
> e2
&& e1
> e2
&& e2
< e3
) {
566 err
= (err
* 1000)/bps
;
570 sf
= xcs
->cs_clocks
[i
].flags
& ~ZSC_BRG
;
577 zsprintf("Checking for rate %d. Found source #%d.\n",bps
, src
);
580 return (EINVAL
); /* no can do */
583 * The M.I. layer likes to keep cs_brg_clk current, even though
584 * we are the only ones who should be touching the BRG's rate.
586 * Note: we are assuming that any ZSC_EXTERN signal source comes in
587 * on the RTxC pin. Correct for the mac68k obio zsc.
590 cs
->cs_brg_clk
= xcs
->cs_clocks
[i
].clk
>> 4;
592 cs
->cs_brg_clk
= PCLK
/ 16;
595 * Now we have a source, so set it up.
598 xcs
->cs_psource
= src
;
599 xcs
->cs_pclk_flag
= sf
;
602 cs
->cs_preg
[4] = ZSWR4_CLK_X16
;
603 cs
->cs_preg
[11]= ZSWR11_RXCLK_BAUD
| ZSWR11_TXCLK_BAUD
;
605 cs
->cs_preg
[14] = ZSWR14_BAUD_ENA
| ZSWR14_BAUD_FROM_PCLK
;
607 cs
->cs_preg
[14] = ZSWR14_BAUD_ENA
;
611 cs
->cs_preg
[4] = tc0
;
612 if (sf
& ZSC_RTXDIV
) {
613 cs
->cs_preg
[11] = ZSWR11_RXCLK_RTXC
| ZSWR11_TXCLK_RTXC
;
615 cs
->cs_preg
[11] = ZSWR11_RXCLK_TRXC
| ZSWR11_TXCLK_TRXC
;
620 /* Set the BAUD rate divisor. */
621 cs
->cs_preg
[12] = tc
;
622 cs
->cs_preg
[13] = tc
>> 8;
626 zsprintf("Rate is %7d, tc is %7d, source no. %2d, flags %4x\n", \
628 zsprintf("Registers are: 4 %x, 11 %x, 14 %x\n\n",
629 cs
->cs_preg
[4], cs
->cs_preg
[11], cs
->cs_preg
[14]);
632 cs
->cs_preg
[5] |= ZSWR5_RTS
; /* Make sure the drivers are on! */
634 /* Caller will stuff the pending registers. */
639 zs_set_modes(struct zs_chanstate
*cs
, int cflag
)
641 struct xzs_chanstate
*xcs
= (void*)cs
;
645 * Make sure we don't enable hfc on a signal line we're ignoring.
646 * As we enable CTS interrupts only if we have CRTSCTS or CDTRCTS,
647 * this code also effectivly turns off ZSWR15_CTS_IE.
649 * Also, disable DCD interrupts if we've been told to ignore
650 * the DCD pin. Happens on mac68k because the input line for
651 * DCD can also be used as a clock input. (Just set CLOCAL.)
653 * If someone tries to turn an invalid flow mode on, Just Say No
656 if ((cflag
& CDTRCTS
) && (cflag
& (CRTSCTS
| MDMBUF
)))
659 if (xcs
->cs_hwflags
& ZS_HWFLAG_NO_DCD
) {
665 * cs->cs_rr0_pps indicates which bit MAY be used for pps.
666 * Enable only if nothing else will want the interrupt and
667 * it's ok to enable interrupts on this line.
669 if ((cflag
& (CLOCAL
| MDMBUF
)) == CLOCAL
)
670 cs
->cs_rr0_pps
= ZSRR0_DCD
;
672 if ((xcs
->cs_hwflags
& ZS_HWFLAG_NO_CTS
) && (cflag
& (CRTSCTS
| CDTRCTS
)))
676 * Output hardware flow control on the chip is horrendous:
677 * if carrier detect drops, the receiver is disabled, and if
678 * CTS drops, the transmitter is stoped IN MID CHARACTER!
679 * Therefore, NEVER set the HFC bit, and instead use the
680 * status interrupt to detect CTS changes.
683 if ((cflag
& (CLOCAL
| MDMBUF
)) != 0)
686 cs
->cs_rr0_dcd
= ZSRR0_DCD
;
688 * The mac hardware only has one output, DTR (HSKo in Mac
689 * parlance). In HFC mode, we use it for the functions
690 * typically served by RTS and DTR on other ports, so we
691 * have to fake the upper layer out some.
693 * CRTSCTS we use CTS as an input which tells us when to shut up.
694 * We make no effort to shut up the other side of the connection.
695 * DTR is used to hang up the modem.
697 * In CDTRCTS, we use CTS to tell us to stop, but we use DTR to
698 * shut up the other side.
700 if ((cflag
& CRTSCTS
) != 0) {
701 cs
->cs_wr5_dtr
= ZSWR5_DTR
;
703 cs
->cs_rr0_cts
= ZSRR0_CTS
;
704 } else if ((cflag
& CDTRCTS
) != 0) {
706 cs
->cs_wr5_rts
= ZSWR5_DTR
;
707 cs
->cs_rr0_cts
= ZSRR0_CTS
;
708 } else if ((cflag
& MDMBUF
) != 0) {
710 cs
->cs_wr5_rts
= ZSWR5_DTR
;
711 cs
->cs_rr0_cts
= ZSRR0_DCD
;
713 cs
->cs_wr5_dtr
= ZSWR5_DTR
;
719 /* Caller will stuff the pending registers. */
725 * Read or write the chip with suitable delays.
726 * MacII hardware has the delay built in.
727 * No need for extra delay. :-) However, some clock-chirped
728 * macs, or zsc's on serial add-on boards might need it.
733 zs_read_reg(struct zs_chanstate
*cs
, uint8_t reg
)
737 *cs
->cs_reg_csr
= reg
;
739 val
= *cs
->cs_reg_csr
;
745 zs_write_reg(struct zs_chanstate
*cs
, uint8_t reg
, uint8_t val
)
747 *cs
->cs_reg_csr
= reg
;
749 *cs
->cs_reg_csr
= val
;
754 zs_read_csr(struct zs_chanstate
*cs
)
758 val
= *cs
->cs_reg_csr
;
760 /* make up for the fact CTS is wired backwards */
766 zs_write_csr(struct zs_chanstate
*cs
, uint8_t val
)
768 /* Note, the csr does not write CTS... */
769 *cs
->cs_reg_csr
= val
;
774 zs_read_data(struct zs_chanstate
*cs
)
778 val
= *cs
->cs_reg_data
;
784 zs_write_data(struct zs_chanstate
*cs
, uint8_t val
)
786 *cs
->cs_reg_data
= val
;
790 /****************************************************************
791 * Console support functions (mac68k specific!)
792 * Note: this code is allowed to know about the layout of
793 * the chip registers, and uses that to keep things simple.
794 * XXX - I think I like the mvme167 code better. -gwr
795 * XXX - Well :-P :-) -wrs
796 ****************************************************************/
798 #define zscnpollc nullcnpollc
801 static void zscnsetup(void);
808 * This code modled after the zs_setparam routine in zskgdb
809 * It sets the console unit to a known state so we can output
815 struct xzs_chanstate xcs
;
816 struct zs_chanstate
*cs
;
820 /* Setup temporary chanstate. */
821 memset(&xcs
, 0, sizeof(xcs
));
824 cs
->cs_reg_csr
= &zc
->zc_csr
;
825 cs
->cs_reg_data
= &zc
->zc_data
;
826 cs
->cs_channel
= zs_consunit
;
827 cs
->cs_brg_clk
= PCLK
/ 16;
829 memcpy(cs
->cs_preg
, zs_init_reg
, 16);
830 cs
->cs_preg
[5] |= ZSWR5_DTR
| ZSWR5_RTS
;
831 cs
->cs_preg
[15] = ZSWR15_BREAK_IE
;
832 tconst
= BPS_TO_TCONST(cs
->cs_brg_clk
, zs_defspeed
[zs_consunit
]);
833 cs
->cs_preg
[12] = tconst
;
834 cs
->cs_preg
[13] = tconst
>> 8;
835 /* can't use zs_set_speed as we haven't set up the
836 * signal sources, and it's not worth it for now
840 * As zs_loadchannelregs doesn't touch reg 9 (interrupt control),
841 * we won't accidentally turn on interrupts below
844 zs_loadchannelregs(cs
);
849 * zscnprobe is the routine which gets called as the kernel is trying to
850 * figure out where the console should be. Each io driver which might
851 * be the console (as defined in mac68k/conf.c) gets probed. The probe
852 * fills in the consdev structure. Important parts are the device #,
853 * and the console priority. Values are CN_DEAD (don't touch me),
854 * CN_NORMAL (I'm here, but elsewhere might be better), CN_INTERNAL
855 * (the video, better than CN_NORMAL), and CN_REMOTE (pick me!)
857 * As the mac's a bit different, we do extra work here. We mainly check
858 * to see if we have serial echo going on. Also chould check for default
862 zscnprobe(struct consdev
* cp
)
864 extern u_long IOBase
;
866 extern const struct cdevsw zstty_cdevsw
;
868 maj
= cdevsw_lookup_major(&zstty_cdevsw
);
870 cp
->cn_pri
= CN_NORMAL
; /* Lower than CN_INTERNAL */
871 if (mac68k_machine
.serial_console
!= 0) {
872 cp
->cn_pri
= CN_REMOTE
; /* Higher than CN_INTERNAL */
873 mac68k_machine
.serial_boot_echo
=0;
876 unit
= (mac68k_machine
.serial_console
== 1) ? 0 : 1;
878 zs_conschan
= (struct zschan
*) -1; /* dummy flag for zs_init() */
880 mac68k_zsdev
= cp
->cn_dev
= makedev(maj
, unit
);
882 if (mac68k_machine
.serial_boot_echo
) {
884 * at this point, we know that we don't have a serial
885 * console, but are doing echo
887 zs_conschan
= (struct zschan
*) -1; /* dummy flag for zs_init() */
889 zs_hwflags
[zs_consunit
] = ZS_HWFLAG_CONSOLE
;
892 if ((i
= mac68k_machine
.modem_d_speed
) > 0) {
893 if (zs_cn_check_speed(i
))
896 if ((i
= mac68k_machine
.print_d_speed
) > 0) {
897 if (zs_cn_check_speed(i
))
900 mac68k_set_io_offsets(IOBase
);
903 * zsinit will set up the addresses of the scc. It will also, if
904 * zs_conschan != 0, calculate the new address of the conschan for
905 * unit zs_consunit. So if we are (or think we are) going to use the
906 * chip for console I/O, we just set up the internal addresses for it.
908 * Now turn off interrupts for the chip. Note: using sccA to get at
909 * the chip is the only vestage of the NetBSD 1.0 ser driver. :-)
911 unit
= sccA
[2]; /* reset reg. access */
913 sccA
[2] = 9; sccA
[2] = 0; /* write 0 to reg. 9, clearing MIE */
914 sccA
[2] = ZSWR0_CLR_INTR
; unit
= sccA
[2]; /* reset any pending ints. */
915 sccA
[0] = ZSWR0_CLR_INTR
; unit
= sccA
[0];
917 if (mac68k_machine
.serial_boot_echo
)
923 zscninit(struct consdev
*cp
)
926 zs_hwflags
[zs_consunit
] = ZS_HWFLAG_CONSOLE
;
929 * zsinit will set up the addresses of the scc. It will also, if
930 * zs_conschan != 0, calculate the new address of the conschan for
931 * unit zs_consunit. So zs_init implicitly sets zs_conschan to the right
935 printf("\nNetBSD/mac68k console\n");
945 volatile struct zschan
*zc
= arg
;
949 /* Wait for a character to arrive. */
953 } while ((rr0
& ZSRR0_RX_READY
) == 0);
960 * This is used by the kd driver to read scan codes,
961 * so don't translate '\r' ==> '\n' here...
967 * Polled output char.
970 zs_putc(void *arg
, int c
)
972 volatile struct zschan
*zc
= arg
;
977 /* Wait for transmitter to become ready. */
981 } while (((rr0
& ZSRR0_TX_READY
) == 0) && (wait
++ < 1000000));
983 if ((rr0
& ZSRR0_TX_READY
) != 0) {
992 * Polled console input putchar.
997 struct zschan
*zc
= zs_conschan
;
1005 * Polled console output putchar.
1008 zscnputc(dev_t dev
, int c
)
1010 struct zschan
*zc
= zs_conschan
;
1018 * Handle user request to enter kernel debugger.
1021 zs_abort(struct zs_chanstate
*cs
)
1023 volatile struct zschan
*zc
= zs_conschan
;
1027 if (zs_cons_canabort
== 0)
1030 /* Wait for end of break to avoid PROM abort. */
1034 } while ((rr0
& ZSRR0_BREAK
) && (wait
++ < ZSABORT_DELAY
));
1036 if (wait
> ZSABORT_DELAY
) {
1037 zs_cons_canabort
= 0;
1038 /* If we time out, turn off the abort ability! */