zs.c revision 1.47.2.2 1 1.47.2.2 chs /* $NetBSD: zs.c,v 1.47.2.2 2005/01/16 00:33:00 chs Exp $ */
2 1.47.2.2 chs
3 1.47.2.2 chs /*
4 1.47.2.2 chs * Copyright (c) 1996-1998 Bill Studenmund
5 1.47.2.2 chs * Copyright (c) 1995 Gordon W. Ross
6 1.47.2.2 chs * All rights reserved.
7 1.47.2.2 chs *
8 1.47.2.2 chs * Redistribution and use in source and binary forms, with or without
9 1.47.2.2 chs * modification, are permitted provided that the following conditions
10 1.47.2.2 chs * are met:
11 1.47.2.2 chs * 1. Redistributions of source code must retain the above copyright
12 1.47.2.2 chs * notice, this list of conditions and the following disclaimer.
13 1.47.2.2 chs * 2. Redistributions in binary form must reproduce the above copyright
14 1.47.2.2 chs * notice, this list of conditions and the following disclaimer in the
15 1.47.2.2 chs * documentation and/or other materials provided with the distribution.
16 1.47.2.2 chs * 3. The name of the author may not be used to endorse or promote products
17 1.47.2.2 chs * derived from this software without specific prior written permission.
18 1.47.2.2 chs * 4. All advertising materials mentioning features or use of this software
19 1.47.2.2 chs * must display the following acknowledgement:
20 1.47.2.2 chs * This product includes software developed by Gordon Ross
21 1.47.2.2 chs *
22 1.47.2.2 chs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.47.2.2 chs * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.47.2.2 chs * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.47.2.2 chs * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 1.47.2.2 chs * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 1.47.2.2 chs * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 1.47.2.2 chs * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 1.47.2.2 chs * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 1.47.2.2 chs * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 1.47.2.2 chs * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.47.2.2 chs */
33 1.47.2.2 chs
34 1.47.2.2 chs /*
35 1.47.2.2 chs * Zilog Z8530 Dual UART driver (machine-dependent part)
36 1.47.2.2 chs *
37 1.47.2.2 chs * Runs two serial lines per chip using slave drivers.
38 1.47.2.2 chs * Plain tty/async lines use the zs_async slave.
39 1.47.2.2 chs * Sun keyboard/mouse uses the zs_kbd/zs_ms slaves.
40 1.47.2.2 chs * Other ports use their own mice & keyboard slaves.
41 1.47.2.2 chs *
42 1.47.2.2 chs * Credits & history:
43 1.47.2.2 chs *
44 1.47.2.2 chs * With NetBSD 1.1, port-mac68k started using a port of the port-sparc
45 1.47.2.2 chs * (port-sun3?) zs.c driver (which was in turn based on code in the
46 1.47.2.2 chs * Berkeley 4.4 Lite release). Bill Studenmund did the port, with
47 1.47.2.2 chs * help from Allen Briggs and Gordon Ross <gwr (at) NetBSD.org>. Noud de
48 1.47.2.2 chs * Brouwer field-tested the driver at a local ISP.
49 1.47.2.2 chs *
50 1.47.2.2 chs * Bill Studenmund and Gordon Ross then ported the machine-independant
51 1.47.2.2 chs * z8530 driver to work with port-mac68k. NetBSD 1.2 contained an
52 1.47.2.2 chs * intermediate version (mac68k using a local, patched version of
53 1.47.2.2 chs * the m.i. drivers), with NetBSD 1.3 containing a full version.
54 1.47.2.2 chs */
55 1.47.2.2 chs
56 1.47.2.2 chs #include <sys/cdefs.h>
57 1.47.2.2 chs __KERNEL_RCSID(0, "$NetBSD: zs.c,v 1.47.2.2 2005/01/16 00:33:00 chs Exp $");
58 1.47.2.2 chs
59 1.47.2.2 chs #include "opt_ddb.h"
60 1.47.2.2 chs #include "opt_mac68k.h"
61 1.47.2.2 chs
62 1.47.2.2 chs #include <sys/param.h>
63 1.47.2.2 chs #include <sys/systm.h>
64 1.47.2.2 chs #include <sys/proc.h>
65 1.47.2.2 chs #include <sys/device.h>
66 1.47.2.2 chs #include <sys/conf.h>
67 1.47.2.2 chs #include <sys/file.h>
68 1.47.2.2 chs #include <sys/ioctl.h>
69 1.47.2.2 chs #include <sys/tty.h>
70 1.47.2.2 chs #include <sys/time.h>
71 1.47.2.2 chs #include <sys/kernel.h>
72 1.47.2.2 chs #include <sys/syslog.h>
73 1.47.2.2 chs
74 1.47.2.2 chs #include <machine/autoconf.h>
75 1.47.2.2 chs #include <machine/cpu.h>
76 1.47.2.2 chs #include <machine/psc.h>
77 1.47.2.2 chs #include <machine/viareg.h>
78 1.47.2.2 chs
79 1.47.2.2 chs #include <dev/cons.h>
80 1.47.2.2 chs #include <dev/ic/z8530reg.h>
81 1.47.2.2 chs #include <machine/z8530var.h>
82 1.47.2.2 chs #include <mac68k/dev/zs_cons.h>
83 1.47.2.2 chs
84 1.47.2.2 chs /* Are these in a header file anywhere? */
85 1.47.2.2 chs /* Booter flags interface */
86 1.47.2.2 chs #define ZSMAC_RAW 0x01
87 1.47.2.2 chs #define ZSMAC_LOCALTALK 0x02
88 1.47.2.2 chs
89 1.47.2.2 chs #define PCLK (9600 * 384)
90 1.47.2.2 chs
91 1.47.2.2 chs /*
92 1.47.2.2 chs * Some warts needed by z8530tty.c -
93 1.47.2.2 chs */
94 1.47.2.2 chs int zs_def_cflag = (CREAD | CS8 | HUPCL);
95 1.47.2.2 chs
96 1.47.2.2 chs /*
97 1.47.2.2 chs * abort detection on console will now timeout after iterating on a loop
98 1.47.2.2 chs * the following # of times. Cheep hack. Also, abort detection is turned
99 1.47.2.2 chs * off after a timeout (i.e. maybe there's not a terminal hooked up).
100 1.47.2.2 chs */
101 1.47.2.2 chs #define ZSABORT_DELAY 3000000
102 1.47.2.2 chs
103 1.47.2.2 chs /*
104 1.47.2.2 chs * Define interrupt levels.
105 1.47.2.2 chs */
106 1.47.2.2 chs #define ZSHARD_PRI 4 /* Wired on the CPU board... */
107 1.47.2.2 chs /*
108 1.47.2.2 chs * Serial port cards with zs chips on them are actually at the
109 1.47.2.2 chs * NuBus interrupt level, which is lower than 4. But blocking
110 1.47.2.2 chs * level 4 interrupts will block those interrupts too, so level
111 1.47.2.2 chs * 4 is fine.
112 1.47.2.2 chs */
113 1.47.2.2 chs
114 1.47.2.2 chs /* The layout of this is hardware-dependent (padding, order). */
115 1.47.2.2 chs struct zschan {
116 1.47.2.2 chs volatile u_char zc_csr; /* ctrl,status, and indirect access */
117 1.47.2.2 chs u_char zc_xxx0;
118 1.47.2.2 chs u_char zc_xxx1; /* part of the other channel lives here! */
119 1.47.2.2 chs u_char zc_xxx2; /* Yea Apple! */
120 1.47.2.2 chs volatile u_char zc_data; /* data */
121 1.47.2.2 chs u_char zc_xxx3;
122 1.47.2.2 chs u_char zc_xxx4;
123 1.47.2.2 chs u_char zc_xxx5;
124 1.47.2.2 chs };
125 1.47.2.2 chs
126 1.47.2.2 chs /* Flags from cninit() */
127 1.47.2.2 chs static int zs_hwflags[2];
128 1.47.2.2 chs /* Default speed for each channel */
129 1.47.2.2 chs static int zs_defspeed[2] = {
130 1.47.2.2 chs 9600, /* tty00 */
131 1.47.2.2 chs 9600, /* tty01 */
132 1.47.2.2 chs };
133 1.47.2.2 chs /* console stuff */
134 1.47.2.2 chs void *zs_conschan;
135 1.47.2.2 chs int zs_consunit;
136 1.47.2.2 chs #ifdef ZS_CONSOLE_ABORT
137 1.47.2.2 chs int zs_cons_canabort = 1;
138 1.47.2.2 chs #else
139 1.47.2.2 chs int zs_cons_canabort = 0;
140 1.47.2.2 chs #endif /* ZS_CONSOLE_ABORT*/
141 1.47.2.2 chs /* device to which the console is attached--if serial. */
142 1.47.2.2 chs dev_t mac68k_zsdev;
143 1.47.2.2 chs /* Mac stuff */
144 1.47.2.2 chs extern volatile unsigned char *sccA;
145 1.47.2.2 chs
146 1.47.2.2 chs int zs_cn_check_speed(int);
147 1.47.2.2 chs
148 1.47.2.2 chs /*
149 1.47.2.2 chs * Even though zsparam will set up the clock multiples, etc., we
150 1.47.2.2 chs * still set them here as: 1) mice & keyboards don't use zsparam,
151 1.47.2.2 chs * and 2) the console stuff uses these defaults before device
152 1.47.2.2 chs * attach.
153 1.47.2.2 chs */
154 1.47.2.2 chs
155 1.47.2.2 chs static u_char zs_init_reg[16] = {
156 1.47.2.2 chs 0, /* 0: CMD (reset, etc.) */
157 1.47.2.2 chs 0, /* 1: No interrupts yet. */
158 1.47.2.2 chs 0x18 + ZSHARD_PRI, /* IVECT */
159 1.47.2.2 chs ZSWR3_RX_8 | ZSWR3_RX_ENABLE,
160 1.47.2.2 chs ZSWR4_CLK_X16 | ZSWR4_ONESB | ZSWR4_EVENP,
161 1.47.2.2 chs ZSWR5_TX_8 | ZSWR5_TX_ENABLE,
162 1.47.2.2 chs 0, /* 6: TXSYNC/SYNCLO */
163 1.47.2.2 chs 0, /* 7: RXSYNC/SYNCHI */
164 1.47.2.2 chs 0, /* 8: alias for data port */
165 1.47.2.2 chs ZSWR9_MASTER_IE,
166 1.47.2.2 chs 0, /*10: Misc. TX/RX control bits */
167 1.47.2.2 chs ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD,
168 1.47.2.2 chs ((PCLK/32)/9600)-2, /*12: BAUDLO (default=9600) */
169 1.47.2.2 chs 0, /*13: BAUDHI (default=9600) */
170 1.47.2.2 chs ZSWR14_BAUD_ENA,
171 1.47.2.2 chs ZSWR15_BREAK_IE,
172 1.47.2.2 chs };
173 1.47.2.2 chs
174 1.47.2.2 chs struct zschan *
175 1.47.2.2 chs zs_get_chan_addr(int channel)
176 1.47.2.2 chs {
177 1.47.2.2 chs char *addr;
178 1.47.2.2 chs struct zschan *zc;
179 1.47.2.2 chs
180 1.47.2.2 chs addr = (char *)sccA;
181 1.47.2.2 chs if (channel == 0) {
182 1.47.2.2 chs zc = (struct zschan *)(addr + 2);
183 1.47.2.2 chs /* handle the fact the ports are intertwined. */
184 1.47.2.2 chs } else {
185 1.47.2.2 chs zc = (struct zschan *)(addr);
186 1.47.2.2 chs }
187 1.47.2.2 chs return (zc);
188 1.47.2.2 chs }
189 1.47.2.2 chs
190 1.47.2.2 chs
191 1.47.2.2 chs /* Find PROM mappings (for console support). */
192 1.47.2.2 chs int zsinited = 0; /* 0 = not, 1 = inited, not attached, 2= attached */
193 1.47.2.2 chs
194 1.47.2.2 chs void
195 1.47.2.2 chs zs_init()
196 1.47.2.2 chs {
197 1.47.2.2 chs zsinited = 1;
198 1.47.2.2 chs if (zs_conschan != 0){ /* we might have moved io under the console */
199 1.47.2.2 chs zs_conschan = zs_get_chan_addr(zs_consunit);
200 1.47.2.2 chs /* so recalc the console port */
201 1.47.2.2 chs }
202 1.47.2.2 chs }
203 1.47.2.2 chs
204 1.47.2.2 chs
205 1.47.2.2 chs /****************************************************************
206 1.47.2.2 chs * Autoconfig
207 1.47.2.2 chs ****************************************************************/
208 1.47.2.2 chs
209 1.47.2.2 chs /* Definition of the driver for autoconfig. */
210 1.47.2.2 chs static int zsc_match(struct device *, struct cfdata *, void *);
211 1.47.2.2 chs static void zsc_attach(struct device *, struct device *, void *);
212 1.47.2.2 chs static int zsc_print(void *, const char *);
213 1.47.2.2 chs
214 1.47.2.2 chs CFATTACH_DECL(zsc, sizeof(struct zsc_softc),
215 1.47.2.2 chs zsc_match, zsc_attach, NULL, NULL);
216 1.47.2.2 chs
217 1.47.2.2 chs extern struct cfdriver zsc_cd;
218 1.47.2.2 chs
219 1.47.2.2 chs int zshard(void *);
220 1.47.2.2 chs int zssoft(void *);
221 1.47.2.2 chs
222 1.47.2.2 chs /*
223 1.47.2.2 chs * Is the zs chip present?
224 1.47.2.2 chs */
225 1.47.2.2 chs static int
226 1.47.2.2 chs zsc_match(struct device *parent, struct cfdata *cf, void *aux)
227 1.47.2.2 chs {
228 1.47.2.2 chs if (zsinited == 2)
229 1.47.2.2 chs return 0;
230 1.47.2.2 chs
231 1.47.2.2 chs return 1;
232 1.47.2.2 chs }
233 1.47.2.2 chs
234 1.47.2.2 chs /*
235 1.47.2.2 chs * Attach a found zs.
236 1.47.2.2 chs *
237 1.47.2.2 chs * Match slave number to zs unit number, so that misconfiguration will
238 1.47.2.2 chs * not set up the keyboard as ttya, etc.
239 1.47.2.2 chs */
240 1.47.2.2 chs static void
241 1.47.2.2 chs zsc_attach(struct device *parent, struct device *self, void *aux)
242 1.47.2.2 chs {
243 1.47.2.2 chs struct zsc_softc *zsc = (void *) self;
244 1.47.2.2 chs struct zsc_attach_args zsc_args;
245 1.47.2.2 chs volatile struct zschan *zc;
246 1.47.2.2 chs struct xzs_chanstate *xcs;
247 1.47.2.2 chs struct zs_chanstate *cs;
248 1.47.2.2 chs int s, chip, theflags, channel;
249 1.47.2.2 chs
250 1.47.2.2 chs if (!zsinited)
251 1.47.2.2 chs zs_init();
252 1.47.2.2 chs zsinited = 2;
253 1.47.2.2 chs
254 1.47.2.2 chs chip = 0; /* We'll deal with chip types post 1.2 */
255 1.47.2.2 chs printf(" chip type %d \n",chip);
256 1.47.2.2 chs
257 1.47.2.2 chs /*
258 1.47.2.2 chs * Initialize software state for each channel.
259 1.47.2.2 chs */
260 1.47.2.2 chs for (channel = 0; channel < 2; channel++) {
261 1.47.2.2 chs zsc_args.channel = channel;
262 1.47.2.2 chs zsc_args.hwflags = zs_hwflags[channel];
263 1.47.2.2 chs xcs = &zsc->xzsc_xcs_store[channel];
264 1.47.2.2 chs cs = &xcs->xzs_cs;
265 1.47.2.2 chs zsc->zsc_cs[channel] = cs;
266 1.47.2.2 chs
267 1.47.2.2 chs simple_lock_init(&cs->cs_lock);
268 1.47.2.2 chs cs->cs_channel = channel;
269 1.47.2.2 chs cs->cs_private = NULL;
270 1.47.2.2 chs cs->cs_ops = &zsops_null;
271 1.47.2.2 chs
272 1.47.2.2 chs zc = zs_get_chan_addr(channel);
273 1.47.2.2 chs cs->cs_reg_csr = &zc->zc_csr;
274 1.47.2.2 chs cs->cs_reg_data = &zc->zc_data;
275 1.47.2.2 chs
276 1.47.2.2 chs memcpy(cs->cs_creg, zs_init_reg, 16);
277 1.47.2.2 chs memcpy(cs->cs_preg, zs_init_reg, 16);
278 1.47.2.2 chs
279 1.47.2.2 chs /* Current BAUD rate generator clock. */
280 1.47.2.2 chs cs->cs_brg_clk = PCLK / 16; /* RTxC is 230400*16, so use 230400 */
281 1.47.2.2 chs cs->cs_defspeed = zs_defspeed[channel];
282 1.47.2.2 chs cs->cs_defcflag = zs_def_cflag;
283 1.47.2.2 chs
284 1.47.2.2 chs /* Make these correspond to cs_defcflag (-crtscts) */
285 1.47.2.2 chs cs->cs_rr0_dcd = ZSRR0_DCD;
286 1.47.2.2 chs cs->cs_rr0_cts = 0;
287 1.47.2.2 chs cs->cs_wr5_dtr = ZSWR5_DTR;
288 1.47.2.2 chs cs->cs_wr5_rts = 0;
289 1.47.2.2 chs
290 1.47.2.2 chs #ifdef __notyet__
291 1.47.2.2 chs cs->cs_slave_type = ZS_SLAVE_NONE;
292 1.47.2.2 chs #endif
293 1.47.2.2 chs
294 1.47.2.2 chs /* Define BAUD rate stuff. */
295 1.47.2.2 chs xcs->cs_clocks[0].clk = PCLK;
296 1.47.2.2 chs xcs->cs_clocks[0].flags = ZSC_RTXBRG | ZSC_RTXDIV;
297 1.47.2.2 chs xcs->cs_clocks[1].flags =
298 1.47.2.2 chs ZSC_RTXBRG | ZSC_RTXDIV | ZSC_VARIABLE | ZSC_EXTERN;
299 1.47.2.2 chs xcs->cs_clocks[2].flags = ZSC_TRXDIV | ZSC_VARIABLE;
300 1.47.2.2 chs xcs->cs_clock_count = 3;
301 1.47.2.2 chs if (channel == 0) {
302 1.47.2.2 chs theflags = mac68k_machine.modem_flags;
303 1.47.2.2 chs xcs->cs_clocks[1].clk = mac68k_machine.modem_dcd_clk;
304 1.47.2.2 chs xcs->cs_clocks[2].clk = mac68k_machine.modem_cts_clk;
305 1.47.2.2 chs } else {
306 1.47.2.2 chs theflags = mac68k_machine.print_flags;
307 1.47.2.2 chs xcs->cs_clocks[1].flags = ZSC_VARIABLE;
308 1.47.2.2 chs /*
309 1.47.2.2 chs * Yes, we aren't defining ANY clock source enables for the
310 1.47.2.2 chs * printer's DCD clock in. The hardware won't let us
311 1.47.2.2 chs * use it. But a clock will freak out the chip, so we
312 1.47.2.2 chs * let you set it, telling us to bar interrupts on the line.
313 1.47.2.2 chs */
314 1.47.2.2 chs xcs->cs_clocks[1].clk = mac68k_machine.print_dcd_clk;
315 1.47.2.2 chs xcs->cs_clocks[2].clk = mac68k_machine.print_cts_clk;
316 1.47.2.2 chs }
317 1.47.2.2 chs if (xcs->cs_clocks[1].clk)
318 1.47.2.2 chs zsc_args.hwflags |= ZS_HWFLAG_NO_DCD;
319 1.47.2.2 chs if (xcs->cs_clocks[2].clk)
320 1.47.2.2 chs zsc_args.hwflags |= ZS_HWFLAG_NO_CTS;
321 1.47.2.2 chs
322 1.47.2.2 chs printf("zsc%d channel %d: d_speed %6d DCD clk %ld CTS clk %ld",
323 1.47.2.2 chs self->dv_unit, channel, cs->cs_defspeed,
324 1.47.2.2 chs xcs->cs_clocks[1].clk, xcs->cs_clocks[2].clk);
325 1.47.2.2 chs
326 1.47.2.2 chs /* Set defaults in our "extended" chanstate. */
327 1.47.2.2 chs xcs->cs_csource = 0;
328 1.47.2.2 chs xcs->cs_psource = 0;
329 1.47.2.2 chs xcs->cs_cclk_flag = 0; /* Nothing fancy by default */
330 1.47.2.2 chs xcs->cs_pclk_flag = 0;
331 1.47.2.2 chs
332 1.47.2.2 chs if (theflags & ZSMAC_RAW) {
333 1.47.2.2 chs zsc_args.hwflags |= ZS_HWFLAG_RAW;
334 1.47.2.2 chs printf(" (raw defaults)");
335 1.47.2.2 chs }
336 1.47.2.2 chs
337 1.47.2.2 chs /*
338 1.47.2.2 chs * XXX - This might be better done with a "stub" driver
339 1.47.2.2 chs * (to replace zstty) that ignores LocalTalk for now.
340 1.47.2.2 chs */
341 1.47.2.2 chs if (theflags & ZSMAC_LOCALTALK) {
342 1.47.2.2 chs printf(" shielding from LocalTalk");
343 1.47.2.2 chs cs->cs_defspeed = 1;
344 1.47.2.2 chs cs->cs_creg[ZSRR_BAUDLO] = cs->cs_preg[ZSRR_BAUDLO] = 0xff;
345 1.47.2.2 chs cs->cs_creg[ZSRR_BAUDHI] = cs->cs_preg[ZSRR_BAUDHI] = 0xff;
346 1.47.2.2 chs zs_write_reg(cs, ZSRR_BAUDLO, 0xff);
347 1.47.2.2 chs zs_write_reg(cs, ZSRR_BAUDHI, 0xff);
348 1.47.2.2 chs /*
349 1.47.2.2 chs * If we might have LocalTalk, then make sure we have the
350 1.47.2.2 chs * Baud rate low-enough to not do any damage.
351 1.47.2.2 chs */
352 1.47.2.2 chs }
353 1.47.2.2 chs
354 1.47.2.2 chs /*
355 1.47.2.2 chs * We used to disable chip interrupts here, but we now
356 1.47.2.2 chs * do that in zscnprobe, just in case MacOS left the chip on.
357 1.47.2.2 chs */
358 1.47.2.2 chs
359 1.47.2.2 chs xcs->cs_chip = chip;
360 1.47.2.2 chs
361 1.47.2.2 chs /* Stash away a copy of the final H/W flags. */
362 1.47.2.2 chs xcs->cs_hwflags = zsc_args.hwflags;
363 1.47.2.2 chs
364 1.47.2.2 chs printf("\n");
365 1.47.2.2 chs
366 1.47.2.2 chs /*
367 1.47.2.2 chs * Look for a child driver for this channel.
368 1.47.2.2 chs * The child attach will setup the hardware.
369 1.47.2.2 chs */
370 1.47.2.2 chs if (!config_found(self, (void *)&zsc_args, zsc_print)) {
371 1.47.2.2 chs /* No sub-driver. Just reset it. */
372 1.47.2.2 chs u_char reset = (channel == 0) ?
373 1.47.2.2 chs ZSWR9_A_RESET : ZSWR9_B_RESET;
374 1.47.2.2 chs s = splzs();
375 1.47.2.2 chs zs_write_reg(cs, 9, reset);
376 1.47.2.2 chs splx(s);
377 1.47.2.2 chs }
378 1.47.2.2 chs }
379 1.47.2.2 chs
380 1.47.2.2 chs if (current_mac_model->class == MACH_CLASSAV) {
381 1.47.2.2 chs add_psc_lev4_intr(PSCINTR_SCCA, zshard, zsc);
382 1.47.2.2 chs add_psc_lev4_intr(PSCINTR_SCCB, zshard, zsc);
383 1.47.2.2 chs } else {
384 1.47.2.2 chs intr_establish(zshard, zsc, ZSHARD_PRI);
385 1.47.2.2 chs }
386 1.47.2.2 chs
387 1.47.2.2 chs /* Now safe to enable interrupts. */
388 1.47.2.2 chs
389 1.47.2.2 chs /*
390 1.47.2.2 chs * Set the master interrupt enable and interrupt vector.
391 1.47.2.2 chs * (common to both channels, do it on A)
392 1.47.2.2 chs */
393 1.47.2.2 chs cs = zsc->zsc_cs[0];
394 1.47.2.2 chs s = splzs();
395 1.47.2.2 chs /* interrupt vector */
396 1.47.2.2 chs zs_write_reg(cs, 2, zs_init_reg[2]);
397 1.47.2.2 chs /* master interrupt control (enable) */
398 1.47.2.2 chs zs_write_reg(cs, 9, zs_init_reg[9]);
399 1.47.2.2 chs splx(s);
400 1.47.2.2 chs }
401 1.47.2.2 chs
402 1.47.2.2 chs static int
403 1.47.2.2 chs zsc_print(void *aux, const char *name)
404 1.47.2.2 chs {
405 1.47.2.2 chs struct zsc_attach_args *args = aux;
406 1.47.2.2 chs
407 1.47.2.2 chs if (name != NULL)
408 1.47.2.2 chs aprint_normal("%s: ", name);
409 1.47.2.2 chs
410 1.47.2.2 chs if (args->channel != -1)
411 1.47.2.2 chs aprint_normal(" channel %d", args->channel);
412 1.47.2.2 chs
413 1.47.2.2 chs return UNCONF;
414 1.47.2.2 chs }
415 1.47.2.2 chs
416 1.47.2.2 chs int
417 1.47.2.2 chs zsmdioctl(struct zs_chanstate *cs, u_long cmd, caddr_t data)
418 1.47.2.2 chs {
419 1.47.2.2 chs switch (cmd) {
420 1.47.2.2 chs default:
421 1.47.2.2 chs return (EPASSTHROUGH);
422 1.47.2.2 chs }
423 1.47.2.2 chs return (0);
424 1.47.2.2 chs }
425 1.47.2.2 chs
426 1.47.2.2 chs void
427 1.47.2.2 chs zsmd_setclock(struct zs_chanstate *cs)
428 1.47.2.2 chs {
429 1.47.2.2 chs struct xzs_chanstate *xcs = (void *)cs;
430 1.47.2.2 chs
431 1.47.2.2 chs if (cs->cs_channel != 0)
432 1.47.2.2 chs return;
433 1.47.2.2 chs
434 1.47.2.2 chs /*
435 1.47.2.2 chs * If the new clock has the external bit set, then select the
436 1.47.2.2 chs * external source.
437 1.47.2.2 chs */
438 1.47.2.2 chs via_set_modem((xcs->cs_pclk_flag & ZSC_EXTERN) ? 1 : 0);
439 1.47.2.2 chs }
440 1.47.2.2 chs
441 1.47.2.2 chs static int zssoftpending;
442 1.47.2.2 chs
443 1.47.2.2 chs /*
444 1.47.2.2 chs * Do the minimum work to pull data off of the chip and queue it up
445 1.47.2.2 chs * for later processing.
446 1.47.2.2 chs */
447 1.47.2.2 chs int
448 1.47.2.2 chs zshard(void *arg)
449 1.47.2.2 chs {
450 1.47.2.2 chs struct zsc_softc *zsc = (struct zsc_softc *)arg;
451 1.47.2.2 chs int rval;
452 1.47.2.2 chs
453 1.47.2.2 chs if (zsc == NULL)
454 1.47.2.2 chs return 0;
455 1.47.2.2 chs
456 1.47.2.2 chs rval = zsc_intr_hard(zsc);
457 1.47.2.2 chs if ((zsc->zsc_cs[0]->cs_softreq) || (zsc->zsc_cs[1]->cs_softreq)) {
458 1.47.2.2 chs /* zsc_req_softint(zsc); */
459 1.47.2.2 chs /* We are at splzs here, so no need to lock. */
460 1.47.2.2 chs if (zssoftpending == 0) {
461 1.47.2.2 chs zssoftpending = 1;
462 1.47.2.2 chs setsoftserial();
463 1.47.2.2 chs }
464 1.47.2.2 chs }
465 1.47.2.2 chs return (rval);
466 1.47.2.2 chs }
467 1.47.2.2 chs
468 1.47.2.2 chs /*
469 1.47.2.2 chs * Look at all of the zsc softint queues.
470 1.47.2.2 chs */
471 1.47.2.2 chs int
472 1.47.2.2 chs zssoft(void *arg)
473 1.47.2.2 chs {
474 1.47.2.2 chs struct zsc_softc *zsc;
475 1.47.2.2 chs int unit;
476 1.47.2.2 chs
477 1.47.2.2 chs /* This is not the only ISR on this IPL. */
478 1.47.2.2 chs if (zssoftpending == 0)
479 1.47.2.2 chs return (0);
480 1.47.2.2 chs
481 1.47.2.2 chs /*
482 1.47.2.2 chs * The soft intr. bit will be set by zshard only if
483 1.47.2.2 chs * the variable zssoftpending is zero.
484 1.47.2.2 chs */
485 1.47.2.2 chs zssoftpending = 0;
486 1.47.2.2 chs
487 1.47.2.2 chs for (unit = 0; unit < zsc_cd.cd_ndevs; ++unit) {
488 1.47.2.2 chs zsc = zsc_cd.cd_devs[unit];
489 1.47.2.2 chs if (zsc == NULL)
490 1.47.2.2 chs continue;
491 1.47.2.2 chs (void) zsc_intr_soft(zsc);
492 1.47.2.2 chs }
493 1.47.2.2 chs return (1);
494 1.47.2.2 chs }
495 1.47.2.2 chs
496 1.47.2.2 chs
497 1.47.2.2 chs #ifndef ZS_TOLERANCE
498 1.47.2.2 chs #define ZS_TOLERANCE 51
499 1.47.2.2 chs /* 5% in tenths of a %, plus 1 so that exactly 5% will be ok. */
500 1.47.2.2 chs #endif
501 1.47.2.2 chs
502 1.47.2.2 chs /*
503 1.47.2.2 chs * check out a rate for acceptability from the internal clock
504 1.47.2.2 chs * source. Used in console config to validate a requested
505 1.47.2.2 chs * default speed. Placed here so that all the speed checking code is
506 1.47.2.2 chs * in one place.
507 1.47.2.2 chs *
508 1.47.2.2 chs * != 0 means ok.
509 1.47.2.2 chs */
510 1.47.2.2 chs int
511 1.47.2.2 chs zs_cn_check_speed(int bps)
512 1.47.2.2 chs {
513 1.47.2.2 chs int tc, rate;
514 1.47.2.2 chs
515 1.47.2.2 chs tc = BPS_TO_TCONST(PCLK / 16, bps);
516 1.47.2.2 chs if (tc < 0)
517 1.47.2.2 chs return 0;
518 1.47.2.2 chs rate = TCONST_TO_BPS(PCLK / 16, tc);
519 1.47.2.2 chs if (ZS_TOLERANCE > abs(((rate - bps)*1000)/bps))
520 1.47.2.2 chs return 1;
521 1.47.2.2 chs else
522 1.47.2.2 chs return 0;
523 1.47.2.2 chs }
524 1.47.2.2 chs
525 1.47.2.2 chs /*
526 1.47.2.2 chs * Search through the signal sources in the channel, and
527 1.47.2.2 chs * pick the best one for the baud rate requested. Return
528 1.47.2.2 chs * a -1 if not achievable in tolerance. Otherwise return 0
529 1.47.2.2 chs * and fill in the values.
530 1.47.2.2 chs *
531 1.47.2.2 chs * This routine draws inspiration from the Atari port's zs.c
532 1.47.2.2 chs * driver in NetBSD 1.1 which did the same type of source switching.
533 1.47.2.2 chs * Tolerance code inspired by comspeed routine in isa/com.c.
534 1.47.2.2 chs *
535 1.47.2.2 chs * By Bill Studenmund, 1996-05-12
536 1.47.2.2 chs */
537 1.47.2.2 chs int
538 1.47.2.2 chs zs_set_speed(struct zs_chanstate *cs, int bps)
539 1.47.2.2 chs {
540 1.47.2.2 chs struct xzs_chanstate *xcs = (void *) cs;
541 1.47.2.2 chs int i, tc, tc0 = 0, tc1, s, sf = 0;
542 1.47.2.2 chs int src, rate0, rate1, err, tol;
543 1.47.2.2 chs
544 1.47.2.2 chs if (bps == 0)
545 1.47.2.2 chs return (0);
546 1.47.2.2 chs
547 1.47.2.2 chs src = -1; /* no valid source yet */
548 1.47.2.2 chs tol = ZS_TOLERANCE;
549 1.47.2.2 chs
550 1.47.2.2 chs /*
551 1.47.2.2 chs * Step through all the sources and see which one matches
552 1.47.2.2 chs * the best. A source has to match BETTER than tol to be chosen.
553 1.47.2.2 chs * Thus if two sources give the same error, the first one will be
554 1.47.2.2 chs * chosen. Also, allow for the possability that one source might run
555 1.47.2.2 chs * both the BRG and the direct divider (i.e. RTxC).
556 1.47.2.2 chs */
557 1.47.2.2 chs for (i=0; i < xcs->cs_clock_count; i++) {
558 1.47.2.2 chs if (xcs->cs_clocks[i].clk <= 0)
559 1.47.2.2 chs continue; /* skip non-existent or bad clocks */
560 1.47.2.2 chs if (xcs->cs_clocks[i].flags & ZSC_BRG) {
561 1.47.2.2 chs /* check out BRG at /16 */
562 1.47.2.2 chs tc1 = BPS_TO_TCONST(xcs->cs_clocks[i].clk >> 4, bps);
563 1.47.2.2 chs if (tc1 >= 0) {
564 1.47.2.2 chs rate1 = TCONST_TO_BPS(xcs->cs_clocks[i].clk >> 4, tc1);
565 1.47.2.2 chs err = abs(((rate1 - bps)*1000)/bps);
566 1.47.2.2 chs if (err < tol) {
567 1.47.2.2 chs tol = err;
568 1.47.2.2 chs src = i;
569 1.47.2.2 chs sf = xcs->cs_clocks[i].flags & ~ZSC_DIV;
570 1.47.2.2 chs tc0 = tc1;
571 1.47.2.2 chs rate0 = rate1;
572 1.47.2.2 chs }
573 1.47.2.2 chs }
574 1.47.2.2 chs }
575 1.47.2.2 chs if (xcs->cs_clocks[i].flags & ZSC_DIV) {
576 1.47.2.2 chs /*
577 1.47.2.2 chs * Check out either /1, /16, /32, or /64
578 1.47.2.2 chs * Note: for /1, you'd better be using a synchronized
579 1.47.2.2 chs * clock!
580 1.47.2.2 chs */
581 1.47.2.2 chs int b0 = xcs->cs_clocks[i].clk, e0 = abs(b0-bps);
582 1.47.2.2 chs int b1 = b0 >> 4, e1 = abs(b1-bps);
583 1.47.2.2 chs int b2 = b1 >> 1, e2 = abs(b2-bps);
584 1.47.2.2 chs int b3 = b2 >> 1, e3 = abs(b3-bps);
585 1.47.2.2 chs
586 1.47.2.2 chs if (e0 < e1 && e0 < e2 && e0 < e3) {
587 1.47.2.2 chs err = e0;
588 1.47.2.2 chs rate1 = b0;
589 1.47.2.2 chs tc1 = ZSWR4_CLK_X1;
590 1.47.2.2 chs } else if (e0 > e1 && e1 < e2 && e1 < e3) {
591 1.47.2.2 chs err = e1;
592 1.47.2.2 chs rate1 = b1;
593 1.47.2.2 chs tc1 = ZSWR4_CLK_X16;
594 1.47.2.2 chs } else if (e0 > e2 && e1 > e2 && e2 < e3) {
595 1.47.2.2 chs err = e2;
596 1.47.2.2 chs rate1 = b2;
597 1.47.2.2 chs tc1 = ZSWR4_CLK_X32;
598 1.47.2.2 chs } else {
599 1.47.2.2 chs err = e3;
600 1.47.2.2 chs rate1 = b3;
601 1.47.2.2 chs tc1 = ZSWR4_CLK_X64;
602 1.47.2.2 chs }
603 1.47.2.2 chs
604 1.47.2.2 chs err = (err * 1000)/bps;
605 1.47.2.2 chs if (err < tol) {
606 1.47.2.2 chs tol = err;
607 1.47.2.2 chs src = i;
608 1.47.2.2 chs sf = xcs->cs_clocks[i].flags & ~ZSC_BRG;
609 1.47.2.2 chs tc0 = tc1;
610 1.47.2.2 chs rate0 = rate1;
611 1.47.2.2 chs }
612 1.47.2.2 chs }
613 1.47.2.2 chs }
614 1.47.2.2 chs #ifdef ZSMACDEBUG
615 1.47.2.2 chs zsprintf("Checking for rate %d. Found source #%d.\n",bps, src);
616 1.47.2.2 chs #endif
617 1.47.2.2 chs if (src == -1)
618 1.47.2.2 chs return (EINVAL); /* no can do */
619 1.47.2.2 chs
620 1.47.2.2 chs /*
621 1.47.2.2 chs * The M.I. layer likes to keep cs_brg_clk current, even though
622 1.47.2.2 chs * we are the only ones who should be touching the BRG's rate.
623 1.47.2.2 chs *
624 1.47.2.2 chs * Note: we are assuming that any ZSC_EXTERN signal source comes in
625 1.47.2.2 chs * on the RTxC pin. Correct for the mac68k obio zsc.
626 1.47.2.2 chs */
627 1.47.2.2 chs if (sf & ZSC_EXTERN)
628 1.47.2.2 chs cs->cs_brg_clk = xcs->cs_clocks[i].clk >> 4;
629 1.47.2.2 chs else
630 1.47.2.2 chs cs->cs_brg_clk = PCLK / 16;
631 1.47.2.2 chs
632 1.47.2.2 chs /*
633 1.47.2.2 chs * Now we have a source, so set it up.
634 1.47.2.2 chs */
635 1.47.2.2 chs s = splzs();
636 1.47.2.2 chs xcs->cs_psource = src;
637 1.47.2.2 chs xcs->cs_pclk_flag = sf;
638 1.47.2.2 chs bps = rate0;
639 1.47.2.2 chs if (sf & ZSC_BRG) {
640 1.47.2.2 chs cs->cs_preg[4] = ZSWR4_CLK_X16;
641 1.47.2.2 chs cs->cs_preg[11]= ZSWR11_RXCLK_BAUD | ZSWR11_TXCLK_BAUD;
642 1.47.2.2 chs if (sf & ZSC_PCLK) {
643 1.47.2.2 chs cs->cs_preg[14] = ZSWR14_BAUD_ENA | ZSWR14_BAUD_FROM_PCLK;
644 1.47.2.2 chs } else {
645 1.47.2.2 chs cs->cs_preg[14] = ZSWR14_BAUD_ENA;
646 1.47.2.2 chs }
647 1.47.2.2 chs tc = tc0;
648 1.47.2.2 chs } else {
649 1.47.2.2 chs cs->cs_preg[4] = tc0;
650 1.47.2.2 chs if (sf & ZSC_RTXDIV) {
651 1.47.2.2 chs cs->cs_preg[11] = ZSWR11_RXCLK_RTXC | ZSWR11_TXCLK_RTXC;
652 1.47.2.2 chs } else {
653 1.47.2.2 chs cs->cs_preg[11] = ZSWR11_RXCLK_TRXC | ZSWR11_TXCLK_TRXC;
654 1.47.2.2 chs }
655 1.47.2.2 chs cs->cs_preg[14]= 0;
656 1.47.2.2 chs tc = 0xffff;
657 1.47.2.2 chs }
658 1.47.2.2 chs /* Set the BAUD rate divisor. */
659 1.47.2.2 chs cs->cs_preg[12] = tc;
660 1.47.2.2 chs cs->cs_preg[13] = tc >> 8;
661 1.47.2.2 chs splx(s);
662 1.47.2.2 chs
663 1.47.2.2 chs #ifdef ZSMACDEBUG
664 1.47.2.2 chs zsprintf("Rate is %7d, tc is %7d, source no. %2d, flags %4x\n", \
665 1.47.2.2 chs bps, tc, src, sf);
666 1.47.2.2 chs zsprintf("Registers are: 4 %x, 11 %x, 14 %x\n\n",
667 1.47.2.2 chs cs->cs_preg[4], cs->cs_preg[11], cs->cs_preg[14]);
668 1.47.2.2 chs #endif
669 1.47.2.2 chs
670 1.47.2.2 chs cs->cs_preg[5] |= ZSWR5_RTS; /* Make sure the drivers are on! */
671 1.47.2.2 chs
672 1.47.2.2 chs /* Caller will stuff the pending registers. */
673 1.47.2.2 chs return (0);
674 1.47.2.2 chs }
675 1.47.2.2 chs
676 1.47.2.2 chs int
677 1.47.2.2 chs zs_set_modes(struct zs_chanstate *cs, int cflag)
678 1.47.2.2 chs {
679 1.47.2.2 chs struct xzs_chanstate *xcs = (void*)cs;
680 1.47.2.2 chs int s;
681 1.47.2.2 chs
682 1.47.2.2 chs /*
683 1.47.2.2 chs * Make sure we don't enable hfc on a signal line we're ignoring.
684 1.47.2.2 chs * As we enable CTS interrupts only if we have CRTSCTS or CDTRCTS,
685 1.47.2.2 chs * this code also effectivly turns off ZSWR15_CTS_IE.
686 1.47.2.2 chs *
687 1.47.2.2 chs * Also, disable DCD interrupts if we've been told to ignore
688 1.47.2.2 chs * the DCD pin. Happens on mac68k because the input line for
689 1.47.2.2 chs * DCD can also be used as a clock input. (Just set CLOCAL.)
690 1.47.2.2 chs *
691 1.47.2.2 chs * If someone tries to turn an invalid flow mode on, Just Say No
692 1.47.2.2 chs * (Suggested by gwr)
693 1.47.2.2 chs */
694 1.47.2.2 chs if ((cflag & CDTRCTS) && (cflag & (CRTSCTS | MDMBUF)))
695 1.47.2.2 chs return (EINVAL);
696 1.47.2.2 chs cs->cs_rr0_pps = 0;
697 1.47.2.2 chs if (xcs->cs_hwflags & ZS_HWFLAG_NO_DCD) {
698 1.47.2.2 chs if (cflag & MDMBUF)
699 1.47.2.2 chs return (EINVAL);
700 1.47.2.2 chs cflag |= CLOCAL;
701 1.47.2.2 chs } else {
702 1.47.2.2 chs /*
703 1.47.2.2 chs * cs->cs_rr0_pps indicates which bit MAY be used for pps.
704 1.47.2.2 chs * Enable only if nothing else will want the interrupt and
705 1.47.2.2 chs * it's ok to enable interrupts on this line.
706 1.47.2.2 chs */
707 1.47.2.2 chs if ((cflag & (CLOCAL | MDMBUF)) == CLOCAL)
708 1.47.2.2 chs cs->cs_rr0_pps = ZSRR0_DCD;
709 1.47.2.2 chs }
710 1.47.2.2 chs if ((xcs->cs_hwflags & ZS_HWFLAG_NO_CTS) && (cflag & (CRTSCTS | CDTRCTS)))
711 1.47.2.2 chs return (EINVAL);
712 1.47.2.2 chs
713 1.47.2.2 chs /*
714 1.47.2.2 chs * Output hardware flow control on the chip is horrendous:
715 1.47.2.2 chs * if carrier detect drops, the receiver is disabled, and if
716 1.47.2.2 chs * CTS drops, the transmitter is stoped IN MID CHARACTER!
717 1.47.2.2 chs * Therefore, NEVER set the HFC bit, and instead use the
718 1.47.2.2 chs * status interrupt to detect CTS changes.
719 1.47.2.2 chs */
720 1.47.2.2 chs s = splzs();
721 1.47.2.2 chs if ((cflag & (CLOCAL | MDMBUF)) != 0)
722 1.47.2.2 chs cs->cs_rr0_dcd = 0;
723 1.47.2.2 chs else
724 1.47.2.2 chs cs->cs_rr0_dcd = ZSRR0_DCD;
725 1.47.2.2 chs /*
726 1.47.2.2 chs * The mac hardware only has one output, DTR (HSKo in Mac
727 1.47.2.2 chs * parlance). In HFC mode, we use it for the functions
728 1.47.2.2 chs * typically served by RTS and DTR on other ports, so we
729 1.47.2.2 chs * have to fake the upper layer out some.
730 1.47.2.2 chs *
731 1.47.2.2 chs * CRTSCTS we use CTS as an input which tells us when to shut up.
732 1.47.2.2 chs * We make no effort to shut up the other side of the connection.
733 1.47.2.2 chs * DTR is used to hang up the modem.
734 1.47.2.2 chs *
735 1.47.2.2 chs * In CDTRCTS, we use CTS to tell us to stop, but we use DTR to
736 1.47.2.2 chs * shut up the other side.
737 1.47.2.2 chs */
738 1.47.2.2 chs if ((cflag & CRTSCTS) != 0) {
739 1.47.2.2 chs cs->cs_wr5_dtr = ZSWR5_DTR;
740 1.47.2.2 chs cs->cs_wr5_rts = 0;
741 1.47.2.2 chs cs->cs_rr0_cts = ZSRR0_CTS;
742 1.47.2.2 chs } else if ((cflag & CDTRCTS) != 0) {
743 1.47.2.2 chs cs->cs_wr5_dtr = 0;
744 1.47.2.2 chs cs->cs_wr5_rts = ZSWR5_DTR;
745 1.47.2.2 chs cs->cs_rr0_cts = ZSRR0_CTS;
746 1.47.2.2 chs } else if ((cflag & MDMBUF) != 0) {
747 1.47.2.2 chs cs->cs_wr5_dtr = 0;
748 1.47.2.2 chs cs->cs_wr5_rts = ZSWR5_DTR;
749 1.47.2.2 chs cs->cs_rr0_cts = ZSRR0_DCD;
750 1.47.2.2 chs } else {
751 1.47.2.2 chs cs->cs_wr5_dtr = ZSWR5_DTR;
752 1.47.2.2 chs cs->cs_wr5_rts = 0;
753 1.47.2.2 chs cs->cs_rr0_cts = 0;
754 1.47.2.2 chs }
755 1.47.2.2 chs splx(s);
756 1.47.2.2 chs
757 1.47.2.2 chs /* Caller will stuff the pending registers. */
758 1.47.2.2 chs return (0);
759 1.47.2.2 chs }
760 1.47.2.2 chs
761 1.47.2.2 chs
762 1.47.2.2 chs /*
763 1.47.2.2 chs * Read or write the chip with suitable delays.
764 1.47.2.2 chs * MacII hardware has the delay built in.
765 1.47.2.2 chs * No need for extra delay. :-) However, some clock-chirped
766 1.47.2.2 chs * macs, or zsc's on serial add-on boards might need it.
767 1.47.2.2 chs */
768 1.47.2.2 chs #define ZS_DELAY()
769 1.47.2.2 chs
770 1.47.2.2 chs u_char
771 1.47.2.2 chs zs_read_reg(struct zs_chanstate *cs, u_char reg)
772 1.47.2.2 chs {
773 1.47.2.2 chs u_char val;
774 1.47.2.2 chs
775 1.47.2.2 chs *cs->cs_reg_csr = reg;
776 1.47.2.2 chs ZS_DELAY();
777 1.47.2.2 chs val = *cs->cs_reg_csr;
778 1.47.2.2 chs ZS_DELAY();
779 1.47.2.2 chs return val;
780 1.47.2.2 chs }
781 1.47.2.2 chs
782 1.47.2.2 chs void
783 1.47.2.2 chs zs_write_reg(struct zs_chanstate *cs, u_char reg, u_char val)
784 1.47.2.2 chs {
785 1.47.2.2 chs *cs->cs_reg_csr = reg;
786 1.47.2.2 chs ZS_DELAY();
787 1.47.2.2 chs *cs->cs_reg_csr = val;
788 1.47.2.2 chs ZS_DELAY();
789 1.47.2.2 chs }
790 1.47.2.2 chs
791 1.47.2.2 chs u_char
792 1.47.2.2 chs zs_read_csr(struct zs_chanstate *cs)
793 1.47.2.2 chs {
794 1.47.2.2 chs u_char val;
795 1.47.2.2 chs
796 1.47.2.2 chs val = *cs->cs_reg_csr;
797 1.47.2.2 chs ZS_DELAY();
798 1.47.2.2 chs /* make up for the fact CTS is wired backwards */
799 1.47.2.2 chs val ^= ZSRR0_CTS;
800 1.47.2.2 chs return val;
801 1.47.2.2 chs }
802 1.47.2.2 chs
803 1.47.2.2 chs void
804 1.47.2.2 chs zs_write_csr(struct zs_chanstate *cs, u_char val)
805 1.47.2.2 chs {
806 1.47.2.2 chs /* Note, the csr does not write CTS... */
807 1.47.2.2 chs *cs->cs_reg_csr = val;
808 1.47.2.2 chs ZS_DELAY();
809 1.47.2.2 chs }
810 1.47.2.2 chs
811 1.47.2.2 chs u_char
812 1.47.2.2 chs zs_read_data(struct zs_chanstate *cs)
813 1.47.2.2 chs {
814 1.47.2.2 chs u_char val;
815 1.47.2.2 chs
816 1.47.2.2 chs val = *cs->cs_reg_data;
817 1.47.2.2 chs ZS_DELAY();
818 1.47.2.2 chs return val;
819 1.47.2.2 chs }
820 1.47.2.2 chs
821 1.47.2.2 chs void
822 1.47.2.2 chs zs_write_data(struct zs_chanstate *cs, u_char val)
823 1.47.2.2 chs {
824 1.47.2.2 chs *cs->cs_reg_data = val;
825 1.47.2.2 chs ZS_DELAY();
826 1.47.2.2 chs }
827 1.47.2.2 chs
828 1.47.2.2 chs /****************************************************************
829 1.47.2.2 chs * Console support functions (mac68k specific!)
830 1.47.2.2 chs * Note: this code is allowed to know about the layout of
831 1.47.2.2 chs * the chip registers, and uses that to keep things simple.
832 1.47.2.2 chs * XXX - I think I like the mvme167 code better. -gwr
833 1.47.2.2 chs * XXX - Well :-P :-) -wrs
834 1.47.2.2 chs ****************************************************************/
835 1.47.2.2 chs
836 1.47.2.2 chs #define zscnpollc nullcnpollc
837 1.47.2.2 chs cons_decl(zs);
838 1.47.2.2 chs
839 1.47.2.2 chs static void zscnsetup(void);
840 1.47.2.2 chs
841 1.47.2.2 chs /*
842 1.47.2.2 chs * Console functions.
843 1.47.2.2 chs */
844 1.47.2.2 chs
845 1.47.2.2 chs /*
846 1.47.2.2 chs * This code modled after the zs_setparam routine in zskgdb
847 1.47.2.2 chs * It sets the console unit to a known state so we can output
848 1.47.2.2 chs * correctly.
849 1.47.2.2 chs */
850 1.47.2.2 chs static void
851 1.47.2.2 chs zscnsetup(void)
852 1.47.2.2 chs {
853 1.47.2.2 chs struct xzs_chanstate xcs;
854 1.47.2.2 chs struct zs_chanstate *cs;
855 1.47.2.2 chs struct zschan *zc;
856 1.47.2.2 chs int tconst, s;
857 1.47.2.2 chs
858 1.47.2.2 chs /* Setup temporary chanstate. */
859 1.47.2.2 chs memset(&xcs, 0, sizeof(xcs));
860 1.47.2.2 chs cs = &xcs.xzs_cs;
861 1.47.2.2 chs zc = zs_conschan;
862 1.47.2.2 chs cs->cs_reg_csr = &zc->zc_csr;
863 1.47.2.2 chs cs->cs_reg_data = &zc->zc_data;
864 1.47.2.2 chs cs->cs_channel = zs_consunit;
865 1.47.2.2 chs cs->cs_brg_clk = PCLK / 16;
866 1.47.2.2 chs
867 1.47.2.2 chs memcpy(cs->cs_preg, zs_init_reg, 16);
868 1.47.2.2 chs cs->cs_preg[5] |= ZSWR5_DTR | ZSWR5_RTS;
869 1.47.2.2 chs cs->cs_preg[15] = ZSWR15_BREAK_IE;
870 1.47.2.2 chs tconst = BPS_TO_TCONST(cs->cs_brg_clk, zs_defspeed[zs_consunit]);
871 1.47.2.2 chs cs->cs_preg[12] = tconst;
872 1.47.2.2 chs cs->cs_preg[13] = tconst >> 8;
873 1.47.2.2 chs /* can't use zs_set_speed as we haven't set up the
874 1.47.2.2 chs * signal sources, and it's not worth it for now
875 1.47.2.2 chs */
876 1.47.2.2 chs
877 1.47.2.2 chs /*
878 1.47.2.2 chs * As zs_loadchannelregs doesn't touch reg 9 (interrupt control),
879 1.47.2.2 chs * we won't accidentally turn on interrupts below
880 1.47.2.2 chs */
881 1.47.2.2 chs s = splhigh();
882 1.47.2.2 chs zs_loadchannelregs(cs);
883 1.47.2.2 chs splx(s);
884 1.47.2.2 chs }
885 1.47.2.2 chs
886 1.47.2.2 chs /*
887 1.47.2.2 chs * zscnprobe is the routine which gets called as the kernel is trying to
888 1.47.2.2 chs * figure out where the console should be. Each io driver which might
889 1.47.2.2 chs * be the console (as defined in mac68k/conf.c) gets probed. The probe
890 1.47.2.2 chs * fills in the consdev structure. Important parts are the device #,
891 1.47.2.2 chs * and the console priority. Values are CN_DEAD (don't touch me),
892 1.47.2.2 chs * CN_NORMAL (I'm here, but elsewhere might be better), CN_INTERNAL
893 1.47.2.2 chs * (the video, better than CN_NORMAL), and CN_REMOTE (pick me!)
894 1.47.2.2 chs *
895 1.47.2.2 chs * As the mac's a bit different, we do extra work here. We mainly check
896 1.47.2.2 chs * to see if we have serial echo going on. Also chould check for default
897 1.47.2.2 chs * speeds.
898 1.47.2.2 chs */
899 1.47.2.2 chs void
900 1.47.2.2 chs zscnprobe(struct consdev * cp)
901 1.47.2.2 chs {
902 1.47.2.2 chs extern u_long IOBase;
903 1.47.2.2 chs int maj, unit, i;
904 1.47.2.2 chs extern const struct cdevsw zstty_cdevsw;
905 1.47.2.2 chs
906 1.47.2.2 chs maj = cdevsw_lookup_major(&zstty_cdevsw);
907 1.47.2.2 chs if (maj != -1) {
908 1.47.2.2 chs cp->cn_pri = CN_NORMAL; /* Lower than CN_INTERNAL */
909 1.47.2.2 chs if (mac68k_machine.serial_console != 0) {
910 1.47.2.2 chs cp->cn_pri = CN_REMOTE; /* Higher than CN_INTERNAL */
911 1.47.2.2 chs mac68k_machine.serial_boot_echo =0;
912 1.47.2.2 chs }
913 1.47.2.2 chs
914 1.47.2.2 chs unit = (mac68k_machine.serial_console == 1) ? 0 : 1;
915 1.47.2.2 chs zs_consunit = unit;
916 1.47.2.2 chs zs_conschan = (struct zschan *) -1; /* dummy flag for zs_init() */
917 1.47.2.2 chs
918 1.47.2.2 chs mac68k_zsdev = cp->cn_dev = makedev(maj, unit);
919 1.47.2.2 chs }
920 1.47.2.2 chs if (mac68k_machine.serial_boot_echo) {
921 1.47.2.2 chs /*
922 1.47.2.2 chs * at this point, we know that we don't have a serial
923 1.47.2.2 chs * console, but are doing echo
924 1.47.2.2 chs */
925 1.47.2.2 chs zs_conschan = (struct zschan *) -1; /* dummy flag for zs_init() */
926 1.47.2.2 chs zs_consunit = 1;
927 1.47.2.2 chs zs_hwflags[zs_consunit] = ZS_HWFLAG_CONSOLE;
928 1.47.2.2 chs }
929 1.47.2.2 chs
930 1.47.2.2 chs if ((i = mac68k_machine.modem_d_speed) > 0) {
931 1.47.2.2 chs if (zs_cn_check_speed(i))
932 1.47.2.2 chs zs_defspeed[0] = i;
933 1.47.2.2 chs }
934 1.47.2.2 chs if ((i = mac68k_machine.print_d_speed) > 0) {
935 1.47.2.2 chs if (zs_cn_check_speed(i))
936 1.47.2.2 chs zs_defspeed[1] = i;
937 1.47.2.2 chs }
938 1.47.2.2 chs mac68k_set_io_offsets(IOBase);
939 1.47.2.2 chs zs_init();
940 1.47.2.2 chs /*
941 1.47.2.2 chs * zsinit will set up the addresses of the scc. It will also, if
942 1.47.2.2 chs * zs_conschan != 0, calculate the new address of the conschan for
943 1.47.2.2 chs * unit zs_consunit. So if we are (or think we are) going to use the
944 1.47.2.2 chs * chip for console I/O, we just set up the internal addresses for it.
945 1.47.2.2 chs *
946 1.47.2.2 chs * Now turn off interrupts for the chip. Note: using sccA to get at
947 1.47.2.2 chs * the chip is the only vestage of the NetBSD 1.0 ser driver. :-)
948 1.47.2.2 chs */
949 1.47.2.2 chs unit = sccA[2]; /* reset reg. access */
950 1.47.2.2 chs unit = sccA[0];
951 1.47.2.2 chs sccA[2] = 9; sccA[2] = 0; /* write 0 to reg. 9, clearing MIE */
952 1.47.2.2 chs sccA[2] = ZSWR0_CLR_INTR; unit = sccA[2]; /* reset any pending ints. */
953 1.47.2.2 chs sccA[0] = ZSWR0_CLR_INTR; unit = sccA[0];
954 1.47.2.2 chs
955 1.47.2.2 chs if (mac68k_machine.serial_boot_echo)
956 1.47.2.2 chs zscnsetup();
957 1.47.2.2 chs return;
958 1.47.2.2 chs }
959 1.47.2.2 chs
960 1.47.2.2 chs void
961 1.47.2.2 chs zscninit(struct consdev *cp)
962 1.47.2.2 chs {
963 1.47.2.2 chs
964 1.47.2.2 chs zs_hwflags[zs_consunit] = ZS_HWFLAG_CONSOLE;
965 1.47.2.2 chs
966 1.47.2.2 chs /*
967 1.47.2.2 chs * zsinit will set up the addresses of the scc. It will also, if
968 1.47.2.2 chs * zs_conschan != 0, calculate the new address of the conschan for
969 1.47.2.2 chs * unit zs_consunit. So zs_init implicitly sets zs_conschan to the right
970 1.47.2.2 chs * number. :-)
971 1.47.2.2 chs */
972 1.47.2.2 chs zscnsetup();
973 1.47.2.2 chs printf("\nNetBSD/mac68k console\n");
974 1.47.2.2 chs }
975 1.47.2.2 chs
976 1.47.2.2 chs
977 1.47.2.2 chs /*
978 1.47.2.2 chs * Polled input char.
979 1.47.2.2 chs */
980 1.47.2.2 chs int
981 1.47.2.2 chs zs_getc(void *arg)
982 1.47.2.2 chs {
983 1.47.2.2 chs volatile struct zschan *zc = arg;
984 1.47.2.2 chs int s, c, rr0;
985 1.47.2.2 chs
986 1.47.2.2 chs s = splhigh();
987 1.47.2.2 chs /* Wait for a character to arrive. */
988 1.47.2.2 chs do {
989 1.47.2.2 chs rr0 = zc->zc_csr;
990 1.47.2.2 chs ZS_DELAY();
991 1.47.2.2 chs } while ((rr0 & ZSRR0_RX_READY) == 0);
992 1.47.2.2 chs
993 1.47.2.2 chs c = zc->zc_data;
994 1.47.2.2 chs ZS_DELAY();
995 1.47.2.2 chs splx(s);
996 1.47.2.2 chs
997 1.47.2.2 chs /*
998 1.47.2.2 chs * This is used by the kd driver to read scan codes,
999 1.47.2.2 chs * so don't translate '\r' ==> '\n' here...
1000 1.47.2.2 chs */
1001 1.47.2.2 chs return (c);
1002 1.47.2.2 chs }
1003 1.47.2.2 chs
1004 1.47.2.2 chs /*
1005 1.47.2.2 chs * Polled output char.
1006 1.47.2.2 chs */
1007 1.47.2.2 chs void
1008 1.47.2.2 chs zs_putc(void *arg, int c)
1009 1.47.2.2 chs {
1010 1.47.2.2 chs volatile struct zschan *zc = arg;
1011 1.47.2.2 chs int s, rr0;
1012 1.47.2.2 chs long wait = 0;
1013 1.47.2.2 chs
1014 1.47.2.2 chs s = splhigh();
1015 1.47.2.2 chs /* Wait for transmitter to become ready. */
1016 1.47.2.2 chs do {
1017 1.47.2.2 chs rr0 = zc->zc_csr;
1018 1.47.2.2 chs ZS_DELAY();
1019 1.47.2.2 chs } while (((rr0 & ZSRR0_TX_READY) == 0) && (wait++ < 1000000));
1020 1.47.2.2 chs
1021 1.47.2.2 chs if ((rr0 & ZSRR0_TX_READY) != 0) {
1022 1.47.2.2 chs zc->zc_data = c;
1023 1.47.2.2 chs ZS_DELAY();
1024 1.47.2.2 chs }
1025 1.47.2.2 chs splx(s);
1026 1.47.2.2 chs }
1027 1.47.2.2 chs
1028 1.47.2.2 chs
1029 1.47.2.2 chs /*
1030 1.47.2.2 chs * Polled console input putchar.
1031 1.47.2.2 chs */
1032 1.47.2.2 chs int
1033 1.47.2.2 chs zscngetc(dev_t dev)
1034 1.47.2.2 chs {
1035 1.47.2.2 chs struct zschan *zc = zs_conschan;
1036 1.47.2.2 chs int c;
1037 1.47.2.2 chs
1038 1.47.2.2 chs c = zs_getc(zc);
1039 1.47.2.2 chs return (c);
1040 1.47.2.2 chs }
1041 1.47.2.2 chs
1042 1.47.2.2 chs /*
1043 1.47.2.2 chs * Polled console output putchar.
1044 1.47.2.2 chs */
1045 1.47.2.2 chs void
1046 1.47.2.2 chs zscnputc(dev_t dev, int c)
1047 1.47.2.2 chs {
1048 1.47.2.2 chs struct zschan *zc = zs_conschan;
1049 1.47.2.2 chs
1050 1.47.2.2 chs zs_putc(zc, c);
1051 1.47.2.2 chs }
1052 1.47.2.2 chs
1053 1.47.2.2 chs
1054 1.47.2.2 chs
1055 1.47.2.2 chs /*
1056 1.47.2.2 chs * Handle user request to enter kernel debugger.
1057 1.47.2.2 chs */
1058 1.47.2.2 chs void
1059 1.47.2.2 chs zs_abort(struct zs_chanstate *cs)
1060 1.47.2.2 chs {
1061 1.47.2.2 chs volatile struct zschan *zc = zs_conschan;
1062 1.47.2.2 chs int rr0;
1063 1.47.2.2 chs long wait = 0;
1064 1.47.2.2 chs
1065 1.47.2.2 chs if (zs_cons_canabort == 0)
1066 1.47.2.2 chs return;
1067 1.47.2.2 chs
1068 1.47.2.2 chs /* Wait for end of break to avoid PROM abort. */
1069 1.47.2.2 chs do {
1070 1.47.2.2 chs rr0 = zc->zc_csr;
1071 1.47.2.2 chs ZS_DELAY();
1072 1.47.2.2 chs } while ((rr0 & ZSRR0_BREAK) && (wait++ < ZSABORT_DELAY));
1073 1.47.2.2 chs
1074 1.47.2.2 chs if (wait > ZSABORT_DELAY) {
1075 1.47.2.2 chs zs_cons_canabort = 0;
1076 1.47.2.2 chs /* If we time out, turn off the abort ability! */
1077 1.47.2.2 chs }
1078 1.47.2.2 chs
1079 1.47.2.2 chs #ifdef DDB
1080 1.47.2.2 chs Debugger();
1081 1.47.2.2 chs #endif
1082 1.47.2.2 chs }
1083