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