zs.c revision 1.7 1 1.7 oki /* $NetBSD: zs.c,v 1.7 1997/10/12 18:06:26 oki Exp $ */
2 1.1 oki
3 1.1 oki /*
4 1.1 oki * Copyright (c) 1992, 1993
5 1.1 oki * The Regents of the University of California. All rights reserved.
6 1.1 oki *
7 1.1 oki * This software was developed by the Computer Systems Engineering group
8 1.1 oki * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 1.1 oki * contributed to Berkeley.
10 1.1 oki *
11 1.1 oki * All advertising materials mentioning features or use of this software
12 1.1 oki * must display the following acknowledgement:
13 1.1 oki * This product includes software developed by the University of
14 1.1 oki * California, Lawrence Berkeley Laboratory.
15 1.1 oki *
16 1.1 oki * Redistribution and use in source and binary forms, with or without
17 1.1 oki * modification, are permitted provided that the following conditions
18 1.1 oki * are met:
19 1.1 oki * 1. Redistributions of source code must retain the above copyright
20 1.1 oki * notice, this list of conditions and the following disclaimer.
21 1.1 oki * 2. Redistributions in binary form must reproduce the above copyright
22 1.1 oki * notice, this list of conditions and the following disclaimer in the
23 1.1 oki * documentation and/or other materials provided with the distribution.
24 1.1 oki * 3. All advertising materials mentioning features or use of this software
25 1.1 oki * must display the following acknowledgement:
26 1.1 oki * This product includes software developed by the University of
27 1.1 oki * California, Berkeley and its contributors.
28 1.1 oki * 4. Neither the name of the University nor the names of its contributors
29 1.1 oki * may be used to endorse or promote products derived from this software
30 1.1 oki * without specific prior written permission.
31 1.1 oki *
32 1.1 oki * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33 1.1 oki * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 1.1 oki * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 1.1 oki * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36 1.1 oki * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 1.1 oki * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 1.1 oki * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 1.1 oki * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 1.1 oki * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 1.1 oki * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 1.1 oki * SUCH DAMAGE.
43 1.1 oki *
44 1.1 oki * @(#)zs.c 8.1 (Berkeley) 7/19/93
45 1.1 oki */
46 1.1 oki
47 1.1 oki /*
48 1.1 oki * Zilog Z8530 (ZSCC) driver.
49 1.1 oki *
50 1.1 oki * Runs two tty ports (ttya and ttyb) on zs0,
51 1.1 oki * and runs a keyboard and mouse on zs1.
52 1.1 oki *
53 1.1 oki * This driver knows far too much about chip to usage mappings.
54 1.1 oki */
55 1.1 oki #include "zs.h"
56 1.1 oki #if NZS > 0
57 1.1 oki
58 1.1 oki #include <sys/param.h>
59 1.1 oki #include <sys/systm.h>
60 1.1 oki #include <sys/proc.h>
61 1.1 oki #include <sys/device.h>
62 1.1 oki #include <sys/conf.h>
63 1.1 oki #include <sys/file.h>
64 1.1 oki #include <sys/ioctl.h>
65 1.1 oki #include <sys/tty.h>
66 1.1 oki #include <sys/time.h>
67 1.1 oki #include <sys/kernel.h>
68 1.1 oki #include <sys/syslog.h>
69 1.1 oki
70 1.1 oki #include <machine/cpu.h>
71 1.1 oki
72 1.1 oki #include <x68k/x68k/iodevice.h>
73 1.1 oki #include <dev/ic/z8530reg.h>
74 1.1 oki #include <x68k/dev/zsvar.h>
75 1.1 oki
76 1.1 oki #ifdef KGDB
77 1.1 oki #include <machine/remote-sl.h>
78 1.1 oki #endif
79 1.1 oki
80 1.1 oki #define ZSMAJOR 12 /* XXX */
81 1.1 oki
82 1.1 oki #define ZS_MOUSE 1 /* XXX */
83 1.1 oki
84 1.1 oki #define PCLK (5*1000*1000) /* PCLK pin input clock rate */
85 1.1 oki
86 1.1 oki #if 0
87 1.1 oki /*
88 1.1 oki * Select software interrupt bit based on TTY ipl.
89 1.1 oki */
90 1.1 oki #if PIL_TTY == 1
91 1.1 oki # define IE_ZSSOFT IE_L1
92 1.1 oki #elif PIL_TTY == 4
93 1.1 oki # define IE_ZSSOFT IE_L4
94 1.1 oki #elif PIL_TTY == 6
95 1.1 oki # define IE_ZSSOFT IE_L6
96 1.1 oki #else
97 1.1 oki # error "no suitable software interrupt bit"
98 1.1 oki #endif
99 1.1 oki #endif
100 1.1 oki
101 1.1 oki /*
102 1.1 oki * Software state per found chip. This would be called `zs_softc',
103 1.1 oki * but the previous driver had a rather different zs_softc....
104 1.1 oki */
105 1.1 oki struct zs_softc {
106 1.1 oki struct device zi_dev; /* base device */
107 1.1 oki volatile struct zsdevice *zi_zs;/* chip registers */
108 1.1 oki struct zs_chanstate zi_cs[2]; /* channel A and B software state */
109 1.1 oki };
110 1.1 oki
111 1.1 oki struct tty *zs_tty[NZS * 2]; /* XXX should be dynamic */
112 1.1 oki
113 1.1 oki /* Definition of the driver for autoconfig. */
114 1.1 oki static int zsmatch __P((struct device *, void *, void *));
115 1.1 oki static void zsattach __P((struct device *, struct device *, void *));
116 1.1 oki
117 1.1 oki struct cfattach zs_ca = {
118 1.1 oki sizeof(struct zs_softc), zsmatch, zsattach
119 1.1 oki };
120 1.1 oki
121 1.1 oki struct cfdriver zs_cd = {
122 1.1 oki NULL, "zs", DV_TTY, NULL, 0
123 1.1 oki };
124 1.1 oki
125 1.1 oki #ifdef x68k
126 1.1 oki static struct zs_chanstate *zsms;
127 1.1 oki void zs_msmodem __P((int));
128 1.1 oki #endif
129 1.1 oki
130 1.1 oki /* Interrupt handlers. */
131 1.1 oki void zshard __P((int));
132 1.1 oki int zssoft __P((void *));
133 1.1 oki
134 1.1 oki struct zs_chanstate *zslist;
135 1.1 oki
136 1.1 oki /* Routines called from other code. */
137 1.7 oki cdev_decl(zs);
138 1.7 oki
139 1.1 oki static void zsiopen __P((struct tty *));
140 1.1 oki static void zsiclose __P((struct tty *));
141 1.1 oki static void zsstart __P((struct tty *));
142 1.4 mycroft void zsstop __P((struct tty *, int));
143 1.1 oki static int zsparam __P((struct tty *, struct termios *));
144 1.1 oki static int zshwiflow __P((struct tty *, int));
145 1.1 oki
146 1.1 oki /* Routines purely local to this driver. */
147 1.1 oki static int zs_getspeed __P((volatile struct zschan *));
148 1.1 oki #ifdef KGDB
149 1.1 oki static void zs_reset __P((volatile struct zschan *, int, int));
150 1.1 oki #endif
151 1.1 oki static void zs_modem __P((struct zs_chanstate *, int));
152 1.1 oki static void zs_loadchannelregs __P((volatile struct zschan *, u_char *));
153 1.1 oki static void zsabort __P((void));
154 1.7 oki static int zsrint __P((struct zs_chanstate *, volatile struct zschan *));
155 1.7 oki static int zsxint __P((struct zs_chanstate *, volatile struct zschan *));
156 1.7 oki static int zssint __P((struct zs_chanstate *, volatile struct zschan *));
157 1.7 oki static void zsoverrun __P((int, long *, char *));
158 1.1 oki
159 1.1 oki /* Console stuff. */
160 1.1 oki static struct tty *zs_ctty; /* console `struct tty *' */
161 1.1 oki static int zs_consin = -1, zs_consout = -1;
162 1.1 oki static void zscnputc __P((int)); /* console putc function */
163 1.1 oki static volatile struct zschan *zs_conschan;
164 1.1 oki static struct tty *zs_checkcons __P((struct zs_softc *, int, struct zs_chanstate *));
165 1.1 oki
166 1.1 oki #ifdef KGDB
167 1.1 oki /* KGDB stuff. Must reboot to change zs_kgdbunit. */
168 1.1 oki extern int kgdb_dev, kgdb_rate;
169 1.1 oki static int zs_kgdb_savedspeed;
170 1.1 oki static void zs_checkkgdb __P((int, struct zs_chanstate *, struct tty *));
171 1.1 oki #endif
172 1.1 oki
173 1.1 oki static volatile struct zsdevice *findzs __P((int));
174 1.1 oki static volatile struct zsdevice *zsaddr[NZS]; /* XXX, but saves work */
175 1.1 oki
176 1.1 oki int zshardscope;
177 1.1 oki int zsshortcuts; /* number of "shortcut" software interrupts */
178 1.1 oki
179 1.7 oki static u_int zs_read __P((volatile struct zschan *, u_int reg));
180 1.7 oki static u_int zs_write __P((volatile struct zschan *, u_int, u_int));
181 1.7 oki
182 1.7 oki static u_int
183 1.1 oki zs_read(zc, reg)
184 1.1 oki volatile struct zschan *zc;
185 1.7 oki u_int reg;
186 1.1 oki {
187 1.1 oki u_char val;
188 1.1 oki
189 1.1 oki zc->zc_csr = reg;
190 1.1 oki ZS_DELAY();
191 1.1 oki val = zc->zc_csr;
192 1.1 oki ZS_DELAY();
193 1.1 oki return val;
194 1.1 oki }
195 1.1 oki
196 1.7 oki static u_int
197 1.1 oki zs_write(zc, reg, val)
198 1.1 oki volatile struct zschan *zc;
199 1.7 oki u_int reg, val;
200 1.1 oki {
201 1.1 oki zc->zc_csr = reg;
202 1.1 oki ZS_DELAY();
203 1.1 oki zc->zc_csr = val;
204 1.1 oki ZS_DELAY();
205 1.1 oki return val;
206 1.1 oki }
207 1.1 oki
208 1.1 oki /*
209 1.1 oki * find zs address for x68k architecture
210 1.1 oki */
211 1.1 oki static volatile struct zsdevice *
212 1.1 oki findzs(zs)
213 1.1 oki int zs;
214 1.1 oki {
215 1.1 oki if (zs == 0)
216 1.1 oki return &IODEVbase->io_inscc;
217 1.1 oki if (1 <= zs && zs <= 4)
218 1.1 oki return &(IODEVbase->io_exscc)[zs - 1];
219 1.1 oki /* none */
220 1.1 oki return 0;
221 1.1 oki }
222 1.1 oki
223 1.1 oki /*
224 1.1 oki * Match slave number to zs unit number, so that misconfiguration will
225 1.1 oki * not set up the keyboard as ttya, etc.
226 1.1 oki */
227 1.1 oki static int
228 1.1 oki zsmatch(parent, match, aux)
229 1.1 oki struct device *parent;
230 1.1 oki void *match, *aux;
231 1.1 oki {
232 1.1 oki struct cfdata *cfp = match;
233 1.1 oki volatile void *addr;
234 1.1 oki
235 1.1 oki if(strcmp("zs", aux) || (addr = findzs(cfp->cf_unit)) == 0)
236 1.1 oki return(0);
237 1.1 oki if (badaddr(addr))
238 1.1 oki return 0;
239 1.1 oki return(1);
240 1.1 oki }
241 1.1 oki
242 1.1 oki /*
243 1.1 oki * Attach a found zs.
244 1.1 oki *
245 1.1 oki * USE ROM PROPERTIES port-a-ignore-cd AND port-b-ignore-cd FOR
246 1.1 oki * SOFT CARRIER, AND keyboard PROPERTY FOR KEYBOARD/MOUSE?
247 1.1 oki */
248 1.1 oki static void
249 1.1 oki zsattach(parent, dev, aux)
250 1.1 oki struct device *parent;
251 1.1 oki struct device *dev;
252 1.1 oki void *aux;
253 1.1 oki {
254 1.1 oki register int zs = dev->dv_unit, unit;
255 1.1 oki register struct zs_softc *zi;
256 1.1 oki register struct zs_chanstate *cs;
257 1.1 oki register volatile struct zsdevice *addr;
258 1.1 oki register struct tty *tp, *ctp;
259 1.1 oki register struct confargs *ca = aux;
260 1.1 oki int pri;
261 1.1 oki
262 1.1 oki if ((addr = zsaddr[zs]) == NULL)
263 1.1 oki addr = zsaddr[zs] = findzs(zs);
264 1.6 christos printf(" (%s)\n", zs ? "external" : "onboard");
265 1.1 oki zi = (struct zs_softc *)dev;
266 1.1 oki zi->zi_zs = addr;
267 1.1 oki unit = zs * 2;
268 1.1 oki cs = zi->zi_cs;
269 1.1 oki cs->cs_ttyp = tp = ttymalloc();
270 1.1 oki
271 1.1 oki /* link into interrupt list with order (A,B) (B=A+1) */
272 1.1 oki cs[0].cs_next = &cs[1];
273 1.1 oki cs[1].cs_next = zslist;
274 1.1 oki zslist = cs;
275 1.1 oki
276 1.1 oki cs->cs_unit = unit;
277 1.1 oki cs->cs_speed = zs_getspeed(&addr->zs_chan[ZS_CHAN_A]);
278 1.1 oki cs->cs_zc = &addr->zs_chan[ZS_CHAN_A];
279 1.1 oki tp->t_dev = makedev(ZSMAJOR, unit);
280 1.1 oki tp->t_oproc = zsstart;
281 1.1 oki tp->t_param = zsparam;
282 1.1 oki tp->t_hwiflow = zshwiflow;
283 1.1 oki if ((ctp = zs_checkcons(zi, unit, cs)) != NULL)
284 1.1 oki cs->cs_ttyp = tp = ctp;
285 1.1 oki #ifdef KGDB
286 1.1 oki if (ctp == NULL)
287 1.1 oki zs_checkkgdb(unit, cs, tp);
288 1.1 oki #endif
289 1.1 oki #ifdef sun
290 1.1 oki if (unit == ZS_KBD) {
291 1.1 oki /*
292 1.1 oki * Keyboard: tell /dev/kbd driver how to talk to us.
293 1.1 oki */
294 1.1 oki tp->t_ispeed = tp->t_ospeed = cs->cs_speed;
295 1.1 oki tp->t_cflag = CS8;
296 1.1 oki kbd_serial(tp, zsiopen, zsiclose);
297 1.1 oki cs->cs_conk = 1; /* do L1-A processing */
298 1.1 oki }
299 1.1 oki #endif
300 1.3 oki if (tp != ctp)
301 1.3 oki tty_attach(tp);
302 1.1 oki ZS_WRITE(cs->cs_zc, 2, 0x70 + zs); /* XXX interrupt vector */
303 1.1 oki unit++;
304 1.1 oki cs++;
305 1.1 oki cs->cs_ttyp = tp = ttymalloc();
306 1.1 oki cs->cs_unit = unit;
307 1.1 oki cs->cs_speed = zs_getspeed(&addr->zs_chan[ZS_CHAN_B]);
308 1.1 oki cs->cs_zc = &addr->zs_chan[ZS_CHAN_B];
309 1.1 oki tp->t_dev = makedev(ZSMAJOR, unit);
310 1.1 oki tp->t_oproc = zsstart;
311 1.1 oki tp->t_param = zsparam;
312 1.2 oki if (unit != ZS_MOUSE)
313 1.2 oki tp->t_hwiflow = zshwiflow;
314 1.1 oki if ((ctp = zs_checkcons(zi, unit, cs)) != NULL)
315 1.1 oki cs->cs_ttyp = tp = ctp;
316 1.1 oki #ifdef KGDB
317 1.1 oki if (ctp == NULL)
318 1.1 oki zs_checkkgdb(unit, cs, tp);
319 1.1 oki #endif
320 1.1 oki if (unit == ZS_MOUSE) {
321 1.1 oki /*
322 1.1 oki * Mouse: tell /dev/mouse driver how to talk to us.
323 1.1 oki */
324 1.1 oki tp->t_ispeed = tp->t_ospeed = cs->cs_speed;
325 1.1 oki tp->t_cflag = CS8 | CSTOPB;
326 1.1 oki ms_serial(tp, zsiopen, zsiclose);
327 1.1 oki #ifdef x68k
328 1.1 oki zsms = cs;
329 1.1 oki #endif
330 1.3 oki } else {
331 1.3 oki if (tp != ctp)
332 1.3 oki tty_attach(tp);
333 1.1 oki }
334 1.1 oki }
335 1.1 oki
336 1.1 oki #ifdef KGDB
337 1.1 oki /*
338 1.1 oki * Put a channel in a known state. Interrupts may be left disabled
339 1.1 oki * or enabled, as desired.
340 1.1 oki */
341 1.1 oki static void
342 1.1 oki zs_reset(zc, inten, speed)
343 1.1 oki volatile struct zschan *zc;
344 1.1 oki int inten, speed;
345 1.1 oki {
346 1.1 oki int tconst;
347 1.1 oki static u_char reg[16] = {
348 1.1 oki 0,
349 1.1 oki 0,
350 1.1 oki 0,
351 1.1 oki ZSWR3_RX_8 | ZSWR3_RX_ENABLE,
352 1.1 oki ZSWR4_CLK_X16 | ZSWR4_ONESB | ZSWR4_EVENP,
353 1.1 oki ZSWR5_TX_8 | ZSWR5_TX_ENABLE,
354 1.1 oki 0,
355 1.1 oki 0,
356 1.1 oki 0,
357 1.1 oki 0,
358 1.1 oki ZSWR10_NRZ,
359 1.1 oki ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD,
360 1.1 oki 0,
361 1.1 oki 0,
362 1.1 oki ZSWR14_BAUD_FROM_PCLK | ZSWR14_BAUD_ENA,
363 1.1 oki ZSWR15_BREAK_IE | ZSWR15_DCD_IE,
364 1.1 oki };
365 1.1 oki
366 1.1 oki reg[9] = inten ? ZSWR9_MASTER_IE | ZSWR9_NO_VECTOR : ZSWR9_NO_VECTOR;
367 1.1 oki tconst = BPS_TO_TCONST(PCLK / 16, speed);
368 1.1 oki reg[12] = tconst;
369 1.1 oki reg[13] = tconst >> 8;
370 1.1 oki zs_loadchannelregs(zc, reg);
371 1.1 oki }
372 1.1 oki #endif
373 1.1 oki
374 1.1 oki /*
375 1.1 oki * Polled console output putchar.
376 1.1 oki */
377 1.1 oki static void
378 1.1 oki zscnputc(c)
379 1.1 oki int c;
380 1.1 oki {
381 1.1 oki register volatile struct zschan *zc = zs_conschan;
382 1.1 oki register int s;
383 1.1 oki
384 1.1 oki if (c == '\n')
385 1.1 oki zscnputc('\r');
386 1.1 oki /*
387 1.1 oki * Must block output interrupts (i.e., raise to >= splzs) without
388 1.1 oki * lowering current ipl. Need a better way.
389 1.1 oki */
390 1.1 oki s = splhigh();
391 1.1 oki #ifdef SUN4C /* XXX */
392 1.1 oki if (CPU_ISSUN4C && s <= (12 << 8))
393 1.1 oki (void) splzs();
394 1.1 oki #endif
395 1.1 oki while ((zc->zc_csr & ZSRR0_TX_READY) == 0)
396 1.1 oki ZS_DELAY();
397 1.1 oki zc->zc_data = c;
398 1.1 oki ZS_DELAY();
399 1.1 oki splx(s);
400 1.1 oki }
401 1.1 oki
402 1.1 oki /*
403 1.1 oki * Set up the given unit as console input, output, both, or neither, as
404 1.1 oki * needed. Return console tty if it is to receive console input.
405 1.1 oki */
406 1.1 oki static struct tty *
407 1.1 oki zs_checkcons(zi, unit, cs)
408 1.1 oki struct zs_softc *zi;
409 1.1 oki int unit;
410 1.1 oki struct zs_chanstate *cs;
411 1.1 oki {
412 1.1 oki register struct tty *tp;
413 1.1 oki char *i, *o;
414 1.1 oki
415 1.1 oki if ((tp = zs_ctty) == NULL) /* XXX */
416 1.1 oki return (0);
417 1.1 oki i = zs_consin == unit ? "input" : NULL;
418 1.1 oki o = zs_consout == unit ? "output" : NULL;
419 1.1 oki if (i == NULL && o == NULL)
420 1.1 oki return (0);
421 1.1 oki
422 1.1 oki /* rewire the minor device (gack) */
423 1.1 oki tp->t_dev = makedev(major(tp->t_dev), unit);
424 1.1 oki
425 1.1 oki /*
426 1.1 oki * Rewire input and/or output. Note that baud rate reflects
427 1.1 oki * input settings, not output settings, but we can do no better
428 1.1 oki * if the console is split across two ports.
429 1.1 oki *
430 1.1 oki * XXX split consoles don't work anyway -- this needs to be
431 1.1 oki * thrown away and redone
432 1.1 oki */
433 1.1 oki if (i) {
434 1.1 oki tp->t_param = zsparam;
435 1.1 oki tp->t_ispeed = tp->t_ospeed = cs->cs_speed;
436 1.1 oki tp->t_cflag = CS8;
437 1.1 oki ttsetwater(tp);
438 1.1 oki }
439 1.1 oki if (o) {
440 1.1 oki tp->t_oproc = zsstart;
441 1.1 oki }
442 1.6 christos printf("%s%c: console %s\n",
443 1.1 oki zi->zi_dev.dv_xname, (unit & 1) + 'a', i ? (o ? "i/o" : i) : o);
444 1.1 oki cs->cs_consio = 1;
445 1.1 oki cs->cs_brkabort = 1;
446 1.1 oki return (tp);
447 1.1 oki }
448 1.1 oki
449 1.1 oki #ifdef KGDB
450 1.1 oki /*
451 1.1 oki * The kgdb zs port, if any, was altered at boot time (see zs_kgdb_init).
452 1.1 oki * Pick up the current speed and character size and restore the original
453 1.1 oki * speed.
454 1.1 oki */
455 1.1 oki static void
456 1.1 oki zs_checkkgdb(unit, cs, tp)
457 1.1 oki int unit;
458 1.1 oki struct zs_chanstate *cs;
459 1.1 oki struct tty *tp;
460 1.1 oki {
461 1.1 oki
462 1.1 oki if (kgdb_dev == makedev(ZSMAJOR, unit)) {
463 1.1 oki tp->t_ispeed = tp->t_ospeed = kgdb_rate;
464 1.1 oki tp->t_cflag = CS8;
465 1.1 oki cs->cs_kgdb = 1;
466 1.1 oki cs->cs_speed = zs_kgdb_savedspeed;
467 1.1 oki (void) zsparam(tp, &tp->t_termios);
468 1.1 oki }
469 1.1 oki }
470 1.1 oki #endif
471 1.1 oki
472 1.1 oki /*
473 1.1 oki * Compute the current baud rate given a ZSCC channel.
474 1.1 oki */
475 1.1 oki static int
476 1.1 oki zs_getspeed(zc)
477 1.1 oki register volatile struct zschan *zc;
478 1.1 oki {
479 1.1 oki register int tconst;
480 1.1 oki
481 1.1 oki tconst = ZS_READ(zc, 12);
482 1.1 oki tconst |= ZS_READ(zc, 13) << 8;
483 1.1 oki return (TCONST_TO_BPS(PCLK / 16, tconst));
484 1.1 oki }
485 1.1 oki
486 1.1 oki
487 1.1 oki /*
488 1.1 oki * Do an internal open.
489 1.1 oki */
490 1.1 oki static void
491 1.1 oki zsiopen(tp)
492 1.1 oki struct tty *tp;
493 1.1 oki {
494 1.1 oki
495 1.1 oki (void) zsparam(tp, &tp->t_termios);
496 1.1 oki ttsetwater(tp);
497 1.1 oki tp->t_state = TS_ISOPEN | TS_CARR_ON;
498 1.1 oki }
499 1.1 oki
500 1.1 oki /*
501 1.1 oki * Do an internal close. Eventually we should shut off the chip when both
502 1.1 oki * ports on it are closed.
503 1.1 oki */
504 1.1 oki static void
505 1.1 oki zsiclose(tp)
506 1.1 oki struct tty *tp;
507 1.1 oki {
508 1.1 oki
509 1.1 oki ttylclose(tp, 0); /* ??? */
510 1.1 oki ttyclose(tp); /* ??? */
511 1.1 oki tp->t_state = 0;
512 1.1 oki }
513 1.1 oki
514 1.1 oki
515 1.1 oki /*
516 1.1 oki * Open a zs serial port. This interface may not be used to open
517 1.1 oki * the keyboard and mouse ports. (XXX)
518 1.1 oki */
519 1.1 oki int
520 1.1 oki zsopen(dev, flags, mode, p)
521 1.1 oki dev_t dev;
522 1.1 oki int flags;
523 1.1 oki int mode;
524 1.1 oki struct proc *p;
525 1.1 oki {
526 1.1 oki register struct tty *tp;
527 1.1 oki register struct zs_chanstate *cs;
528 1.1 oki struct zs_softc *zi;
529 1.1 oki int unit = minor(dev), zs = unit >> 1, error, s;
530 1.1 oki
531 1.1 oki if (zs >= zs_cd.cd_ndevs || (zi = zs_cd.cd_devs[zs]) == NULL ||
532 1.1 oki unit == ZS_MOUSE)
533 1.1 oki return (ENXIO);
534 1.1 oki if (zi->zi_zs == NULL)
535 1.1 oki return (ENXIO);
536 1.1 oki cs = &zi->zi_cs[unit & 1];
537 1.1 oki if (cs->cs_consio)
538 1.1 oki return (ENXIO); /* ??? */
539 1.1 oki tp = cs->cs_ttyp;
540 1.1 oki s = spltty();
541 1.1 oki if ((tp->t_state & TS_ISOPEN) == 0) {
542 1.1 oki ttychars(tp);
543 1.1 oki if (tp->t_ispeed == 0) {
544 1.1 oki tp->t_iflag = TTYDEF_IFLAG;
545 1.1 oki tp->t_oflag = TTYDEF_OFLAG;
546 1.1 oki tp->t_cflag = TTYDEF_CFLAG;
547 1.1 oki tp->t_lflag = TTYDEF_LFLAG;
548 1.1 oki tp->t_ispeed = tp->t_ospeed = cs->cs_speed;
549 1.1 oki }
550 1.1 oki (void) zsparam(tp, &tp->t_termios);
551 1.1 oki ttsetwater(tp);
552 1.1 oki } else if (tp->t_state & TS_XCLUDE && p->p_ucred->cr_uid != 0) {
553 1.1 oki splx(s);
554 1.1 oki return (EBUSY);
555 1.1 oki }
556 1.1 oki error = 0;
557 1.1 oki for (;;) {
558 1.1 oki register int rr0;
559 1.1 oki
560 1.1 oki /* loop, turning on the device, until carrier present */
561 1.1 oki zs_modem(cs, 1);
562 1.1 oki /* May never get status intr if carrier already on. -gwr */
563 1.1 oki rr0 = cs->cs_zc->zc_csr;
564 1.1 oki ZS_DELAY();
565 1.1 oki if ((rr0 & ZSRR0_DCD) || cs->cs_softcar)
566 1.1 oki tp->t_state |= TS_CARR_ON;
567 1.1 oki if (flags & O_NONBLOCK || tp->t_cflag & CLOCAL ||
568 1.1 oki tp->t_state & TS_CARR_ON)
569 1.1 oki break;
570 1.1 oki tp->t_state |= TS_WOPEN;
571 1.1 oki error = ttysleep(tp, (caddr_t)&tp->t_rawq, TTIPRI | PCATCH,
572 1.1 oki ttopen, 0);
573 1.1 oki if (error) {
574 1.1 oki if (!(tp->t_state & TS_ISOPEN)) {
575 1.1 oki zs_modem(cs, 0);
576 1.1 oki tp->t_state &= ~TS_WOPEN;
577 1.1 oki ttwakeup(tp);
578 1.1 oki }
579 1.1 oki splx(s);
580 1.1 oki return error;
581 1.1 oki }
582 1.1 oki }
583 1.1 oki splx(s);
584 1.1 oki if (error == 0)
585 1.1 oki error = linesw[tp->t_line].l_open(dev, tp);
586 1.1 oki if (error)
587 1.1 oki zs_modem(cs, 0);
588 1.1 oki return (error);
589 1.1 oki }
590 1.1 oki
591 1.1 oki /*
592 1.1 oki * Close a zs serial port.
593 1.1 oki */
594 1.1 oki int
595 1.1 oki zsclose(dev, flags, mode, p)
596 1.1 oki dev_t dev;
597 1.1 oki int flags;
598 1.1 oki int mode;
599 1.1 oki struct proc *p;
600 1.1 oki {
601 1.1 oki register struct zs_chanstate *cs;
602 1.1 oki register struct tty *tp;
603 1.1 oki struct zs_softc *zi;
604 1.1 oki int unit = minor(dev), s;
605 1.1 oki
606 1.1 oki zi = zs_cd.cd_devs[unit >> 1];
607 1.1 oki cs = &zi->zi_cs[unit & 1];
608 1.1 oki tp = cs->cs_ttyp;
609 1.1 oki linesw[tp->t_line].l_close(tp, flags);
610 1.1 oki if (tp->t_cflag & HUPCL || tp->t_state & TS_WOPEN ||
611 1.1 oki (tp->t_state & TS_ISOPEN) == 0) {
612 1.1 oki zs_modem(cs, 0);
613 1.1 oki /* hold low for 1 second */
614 1.1 oki (void) tsleep((caddr_t)cs, TTIPRI, ttclos, hz);
615 1.1 oki }
616 1.1 oki if (cs->cs_creg[5] & ZSWR5_BREAK)
617 1.1 oki {
618 1.1 oki s = splzs();
619 1.1 oki cs->cs_preg[5] &= ~ZSWR5_BREAK;
620 1.1 oki cs->cs_creg[5] &= ~ZSWR5_BREAK;
621 1.1 oki ZS_WRITE(cs->cs_zc, 5, cs->cs_creg[5]);
622 1.1 oki splx(s);
623 1.1 oki }
624 1.1 oki ttyclose(tp);
625 1.1 oki #ifdef KGDB
626 1.1 oki /* Reset the speed if we're doing kgdb on this port */
627 1.1 oki if (cs->cs_kgdb) {
628 1.1 oki tp->t_ispeed = tp->t_ospeed = kgdb_rate;
629 1.1 oki (void) zsparam(tp, &tp->t_termios);
630 1.1 oki }
631 1.1 oki #endif
632 1.1 oki return (0);
633 1.1 oki }
634 1.1 oki
635 1.1 oki /*
636 1.1 oki * Read/write zs serial port.
637 1.1 oki */
638 1.1 oki int
639 1.1 oki zsread(dev, uio, flags)
640 1.1 oki dev_t dev;
641 1.1 oki struct uio *uio;
642 1.1 oki int flags;
643 1.1 oki {
644 1.1 oki register struct zs_chanstate *cs;
645 1.1 oki register struct zs_softc *zi;
646 1.1 oki register struct tty *tp;
647 1.1 oki int unit = minor(dev);
648 1.1 oki
649 1.1 oki zi = zs_cd.cd_devs[unit >> 1];
650 1.1 oki cs = &zi->zi_cs[unit & 1];
651 1.1 oki tp = cs->cs_ttyp;
652 1.1 oki
653 1.1 oki return (linesw[tp->t_line].l_read(tp, uio, flags));
654 1.1 oki
655 1.1 oki }
656 1.1 oki
657 1.1 oki int
658 1.1 oki zswrite(dev, uio, flags)
659 1.1 oki dev_t dev;
660 1.1 oki struct uio *uio;
661 1.1 oki int flags;
662 1.1 oki {
663 1.1 oki register struct zs_chanstate *cs;
664 1.1 oki register struct zs_softc *zi;
665 1.1 oki register struct tty *tp;
666 1.1 oki int unit = minor(dev);
667 1.1 oki
668 1.1 oki zi = zs_cd.cd_devs[unit >> 1];
669 1.1 oki cs = &zi->zi_cs[unit & 1];
670 1.1 oki tp = cs->cs_ttyp;
671 1.1 oki
672 1.1 oki return (linesw[tp->t_line].l_write(tp, uio, flags));
673 1.1 oki }
674 1.1 oki
675 1.1 oki struct tty *
676 1.1 oki zstty(dev)
677 1.1 oki dev_t dev;
678 1.1 oki {
679 1.1 oki register struct zs_chanstate *cs;
680 1.1 oki register struct zs_softc *zi;
681 1.1 oki int unit = minor(dev);
682 1.1 oki
683 1.1 oki zi = zs_cd.cd_devs[unit >> 1];
684 1.1 oki cs = &zi->zi_cs[unit & 1];
685 1.1 oki
686 1.1 oki return (cs->cs_ttyp);
687 1.1 oki
688 1.1 oki }
689 1.1 oki
690 1.1 oki /*
691 1.1 oki * ZS hardware interrupt. Scan all ZS channels. NB: we know here that
692 1.1 oki * channels are kept in (A,B) pairs.
693 1.1 oki *
694 1.1 oki * Do just a little, then get out; set a software interrupt if more
695 1.1 oki * work is needed.
696 1.1 oki *
697 1.1 oki * We deliberately ignore the vectoring Zilog gives us, and match up
698 1.1 oki * only the number of `reset interrupt under service' operations, not
699 1.1 oki * the order.
700 1.1 oki */
701 1.1 oki /* ARGSUSED */
702 1.1 oki void
703 1.1 oki zshard(intrarg)
704 1.1 oki int intrarg;
705 1.1 oki {
706 1.1 oki register struct zs_chanstate *a;
707 1.1 oki #define b (a + 1)
708 1.1 oki register volatile struct zschan *zc;
709 1.1 oki register int rr3, intflags = 0, v, i;
710 1.1 oki
711 1.7 oki a = &((struct zs_softc*)zs_cd.cd_devs[(intrarg >> 2) & 0x0f])->zi_cs[0];
712 1.7 oki rr3 = ZS_READ(a->cs_zc, 3);
713 1.7 oki if (rr3 & (ZSRR3_IP_A_RX|ZSRR3_IP_A_TX|ZSRR3_IP_A_STAT)) {
714 1.7 oki intflags |= 2;
715 1.7 oki zc = a->cs_zc;
716 1.7 oki i = a->cs_rbput;
717 1.7 oki if (rr3 & ZSRR3_IP_A_RX && (v = zsrint(a, zc)) != 0) {
718 1.7 oki a->cs_rbuf[i++ & ZLRB_RING_MASK] = v;
719 1.7 oki intflags |= 1;
720 1.7 oki }
721 1.7 oki if (rr3 & ZSRR3_IP_A_TX && (v = zsxint(a, zc)) != 0) {
722 1.7 oki a->cs_rbuf[i++ & ZLRB_RING_MASK] = v;
723 1.7 oki intflags |= 1;
724 1.7 oki intflags |= 4;
725 1.7 oki }
726 1.7 oki if (rr3 & ZSRR3_IP_A_STAT && (v = zssint(a, zc)) != 0) {
727 1.7 oki a->cs_rbuf[i++ & ZLRB_RING_MASK] = v;
728 1.7 oki intflags |= 1;
729 1.7 oki }
730 1.7 oki a->cs_rbput = i;
731 1.7 oki }
732 1.7 oki if (rr3 & (ZSRR3_IP_B_RX|ZSRR3_IP_B_TX|ZSRR3_IP_B_STAT)) {
733 1.7 oki intflags |= 2;
734 1.7 oki zc = b->cs_zc;
735 1.7 oki i = b->cs_rbput;
736 1.7 oki if (rr3 & ZSRR3_IP_B_RX && (v = zsrint(b, zc)) != 0) {
737 1.7 oki b->cs_rbuf[i++ & ZLRB_RING_MASK] = v;
738 1.7 oki intflags |= 1;
739 1.7 oki }
740 1.7 oki if (rr3 & ZSRR3_IP_B_TX && (v = zsxint(b, zc)) != 0) {
741 1.7 oki b->cs_rbuf[i++ & ZLRB_RING_MASK] = v;
742 1.7 oki intflags |= 1;
743 1.7 oki intflags |= 4;
744 1.1 oki }
745 1.7 oki if (rr3 & ZSRR3_IP_B_STAT && (v = zssint(b, zc)) != 0) {
746 1.7 oki b->cs_rbuf[i++ & ZLRB_RING_MASK] = v;
747 1.7 oki intflags |= 1;
748 1.1 oki }
749 1.7 oki b->cs_rbput = i;
750 1.1 oki }
751 1.1 oki #undef b
752 1.1 oki if (intflags & 1) {
753 1.1 oki #if defined(SUN4C) || defined(SUN4M)
754 1.1 oki if (CPU_ISSUN4M || CPU_ISSUN4C) {
755 1.1 oki /* XXX -- but this will go away when zshard moves to locore.s */
756 1.1 oki struct clockframe *p = intrarg;
757 1.1 oki
758 1.1 oki if ((p->psr & PSR_PIL) < (PIL_TTY << 8)) {
759 1.1 oki zsshortcuts++;
760 1.1 oki (void) spltty();
761 1.1 oki if (zshardscope) {
762 1.1 oki LED_ON;
763 1.1 oki LED_OFF;
764 1.1 oki }
765 1.1 oki return (zssoft(intrarg));
766 1.1 oki }
767 1.1 oki }
768 1.1 oki #endif
769 1.1 oki #if x68k
770 1.1 oki #define PSL_TTY PSL_IPL4 /* XXX */
771 1.1 oki if (((intrarg >> 16) & PSL_IPL) < PSL_TTY) {
772 1.1 oki zsshortcuts++;
773 1.1 oki (void) spltty();
774 1.1 oki zssoft(0/*intrarg*/);
775 1.1 oki return;
776 1.1 oki }
777 1.1 oki setsoftserial();
778 1.1 oki #else
779 1.1 oki ienab_bis(IE_ZSSOFT);
780 1.1 oki #endif
781 1.1 oki }
782 1.1 oki }
783 1.1 oki
784 1.1 oki static int
785 1.1 oki zsrint(cs, zc)
786 1.1 oki register struct zs_chanstate *cs;
787 1.1 oki register volatile struct zschan *zc;
788 1.1 oki {
789 1.1 oki register int c = zc->zc_data;
790 1.1 oki
791 1.1 oki ZS_DELAY();
792 1.1 oki #ifndef x68k
793 1.1 oki if (cs->cs_conk) {
794 1.1 oki register struct conk_state *conk = &zsconk_state;
795 1.1 oki
796 1.1 oki /*
797 1.1 oki * Check here for console abort function, so that we
798 1.1 oki * can abort even when interrupts are locking up the
799 1.1 oki * machine.
800 1.1 oki */
801 1.1 oki if (c == KBD_RESET) {
802 1.1 oki conk->conk_id = 1; /* ignore next byte */
803 1.1 oki conk->conk_l1 = 0;
804 1.1 oki } else if (conk->conk_id)
805 1.1 oki conk->conk_id = 0; /* stop ignoring bytes */
806 1.1 oki else if (c == KBD_L1)
807 1.1 oki conk->conk_l1 = 1; /* L1 went down */
808 1.1 oki else if (c == (KBD_L1|KBD_UP))
809 1.1 oki conk->conk_l1 = 0; /* L1 went up */
810 1.1 oki else if (c == KBD_A && conk->conk_l1) {
811 1.1 oki zsabort();
812 1.1 oki conk->conk_l1 = 0; /* we never see the up */
813 1.1 oki goto clearit; /* eat the A after L1-A */
814 1.1 oki }
815 1.1 oki }
816 1.1 oki #endif
817 1.1 oki #ifdef KGDB
818 1.1 oki if (c == FRAME_START && cs->cs_kgdb &&
819 1.1 oki (cs->cs_ttyp->t_state & TS_ISOPEN) == 0) {
820 1.1 oki zskgdb(cs->cs_unit);
821 1.1 oki goto clearit;
822 1.1 oki }
823 1.1 oki #endif
824 1.1 oki /* compose receive character and status */
825 1.1 oki c <<= 8;
826 1.1 oki c |= ZS_READ(zc, 1);
827 1.1 oki
828 1.1 oki /* clear receive error & interrupt condition */
829 1.1 oki zc->zc_csr = ZSWR0_RESET_ERRORS;
830 1.1 oki ZS_DELAY();
831 1.1 oki zc->zc_csr = ZSWR0_CLR_INTR;
832 1.1 oki ZS_DELAY();
833 1.1 oki
834 1.1 oki return (ZRING_MAKE(ZRING_RINT, c));
835 1.1 oki
836 1.1 oki clearit:
837 1.1 oki zc->zc_csr = ZSWR0_RESET_ERRORS;
838 1.1 oki ZS_DELAY();
839 1.1 oki zc->zc_csr = ZSWR0_CLR_INTR;
840 1.1 oki ZS_DELAY();
841 1.1 oki return (0);
842 1.1 oki }
843 1.1 oki
844 1.1 oki static int
845 1.1 oki zsxint(cs, zc)
846 1.1 oki register struct zs_chanstate *cs;
847 1.1 oki register volatile struct zschan *zc;
848 1.1 oki {
849 1.1 oki register int i = cs->cs_tbc;
850 1.1 oki
851 1.1 oki if (i == 0) {
852 1.1 oki zc->zc_csr = ZSWR0_RESET_TXINT;
853 1.1 oki ZS_DELAY();
854 1.1 oki zc->zc_csr = ZSWR0_CLR_INTR;
855 1.1 oki ZS_DELAY();
856 1.1 oki return (ZRING_MAKE(ZRING_XINT, 0));
857 1.1 oki }
858 1.1 oki cs->cs_tbc = i - 1;
859 1.1 oki zc->zc_data = *cs->cs_tba++;
860 1.1 oki ZS_DELAY();
861 1.1 oki zc->zc_csr = ZSWR0_CLR_INTR;
862 1.1 oki ZS_DELAY();
863 1.1 oki return (0);
864 1.1 oki }
865 1.1 oki
866 1.1 oki static int
867 1.1 oki zssint(cs, zc)
868 1.1 oki register struct zs_chanstate *cs;
869 1.1 oki register volatile struct zschan *zc;
870 1.1 oki {
871 1.1 oki register int rr0;
872 1.1 oki
873 1.1 oki rr0 = zc->zc_csr;
874 1.1 oki ZS_DELAY();
875 1.1 oki zc->zc_csr = ZSWR0_RESET_STATUS;
876 1.1 oki ZS_DELAY();
877 1.1 oki zc->zc_csr = ZSWR0_CLR_INTR;
878 1.1 oki ZS_DELAY();
879 1.1 oki /*
880 1.1 oki * The chip's hardware flow control is, as noted in zsreg.h,
881 1.1 oki * busted---if the DCD line goes low the chip shuts off the
882 1.1 oki * receiver (!). If we want hardware CTS flow control but do
883 1.1 oki * not have it, and carrier is now on, turn HFC on; if we have
884 1.1 oki * HFC now but carrier has gone low, turn it off.
885 1.1 oki */
886 1.1 oki if (rr0 & ZSRR0_DCD) {
887 1.1 oki if (cs->cs_ttyp->t_cflag & CCTS_OFLOW &&
888 1.1 oki (cs->cs_creg[3] & ZSWR3_HFC) == 0) {
889 1.1 oki cs->cs_creg[3] |= ZSWR3_HFC;
890 1.1 oki ZS_WRITE(zc, 3, cs->cs_creg[3]);
891 1.1 oki }
892 1.1 oki } else {
893 1.1 oki if (cs->cs_creg[3] & ZSWR3_HFC) {
894 1.1 oki cs->cs_creg[3] &= ~ZSWR3_HFC;
895 1.1 oki ZS_WRITE(zc, 3, cs->cs_creg[3]);
896 1.1 oki }
897 1.1 oki }
898 1.1 oki if ((rr0 & ZSRR0_BREAK) && cs->cs_brkabort) {
899 1.1 oki #ifdef SUN4
900 1.1 oki /*
901 1.1 oki * XXX This might not be necessary. Test and
902 1.1 oki * delete if it isn't.
903 1.1 oki */
904 1.1 oki if (CPU_ISSUN4) {
905 1.1 oki while (zc->zc_csr & ZSRR0_BREAK)
906 1.1 oki ZS_DELAY();
907 1.1 oki }
908 1.1 oki #endif
909 1.1 oki zsabort();
910 1.1 oki return (0);
911 1.1 oki }
912 1.1 oki return (ZRING_MAKE(ZRING_SINT, rr0));
913 1.1 oki }
914 1.1 oki
915 1.1 oki static void
916 1.1 oki zsabort()
917 1.1 oki {
918 1.1 oki
919 1.1 oki #ifdef DDB
920 1.1 oki Debugger();
921 1.1 oki #else
922 1.6 christos printf("stopping on keyboard abort\n");
923 1.1 oki #ifndef x68k
924 1.1 oki callrom();
925 1.1 oki #endif
926 1.1 oki #endif
927 1.1 oki }
928 1.1 oki
929 1.1 oki #ifdef KGDB
930 1.1 oki /*
931 1.1 oki * KGDB framing character received: enter kernel debugger. This probably
932 1.1 oki * should time out after a few seconds to avoid hanging on spurious input.
933 1.1 oki */
934 1.1 oki void
935 1.1 oki zskgdb(unit)
936 1.1 oki int unit;
937 1.1 oki {
938 1.1 oki
939 1.6 christos printf("zs%d%c: kgdb interrupt\n", unit >> 1, (unit & 1) + 'a');
940 1.1 oki kgdb_connect(1);
941 1.1 oki }
942 1.1 oki #endif
943 1.1 oki
944 1.1 oki /*
945 1.1 oki * Print out a ring or fifo overrun error message.
946 1.1 oki */
947 1.1 oki static void
948 1.1 oki zsoverrun(unit, ptime, what)
949 1.1 oki int unit;
950 1.1 oki long *ptime;
951 1.1 oki char *what;
952 1.1 oki {
953 1.1 oki
954 1.1 oki if (*ptime != time.tv_sec) {
955 1.1 oki *ptime = time.tv_sec;
956 1.1 oki log(LOG_WARNING, "zs%d%c: %s overrun\n", unit >> 1,
957 1.1 oki (unit & 1) + 'a', what);
958 1.1 oki }
959 1.1 oki }
960 1.1 oki
961 1.1 oki /*
962 1.1 oki * ZS software interrupt. Scan all channels for deferred interrupts.
963 1.1 oki */
964 1.1 oki int
965 1.1 oki zssoft(arg)
966 1.1 oki void *arg;
967 1.1 oki {
968 1.1 oki register struct zs_chanstate *cs;
969 1.1 oki register volatile struct zschan *zc;
970 1.1 oki register struct linesw *line;
971 1.1 oki register struct tty *tp;
972 1.1 oki register int get, n, c, cc, unit, s;
973 1.1 oki int retval = 0;
974 1.1 oki
975 1.1 oki for (cs = zslist; cs != NULL; cs = cs->cs_next) {
976 1.1 oki get = cs->cs_rbget;
977 1.1 oki again:
978 1.1 oki n = cs->cs_rbput; /* atomic */
979 1.1 oki if (get == n) /* nothing more on this line */
980 1.1 oki continue;
981 1.1 oki retval = 1;
982 1.1 oki unit = cs->cs_unit; /* set up to handle interrupts */
983 1.1 oki zc = cs->cs_zc;
984 1.1 oki tp = cs->cs_ttyp;
985 1.1 oki line = &linesw[tp->t_line];
986 1.1 oki /*
987 1.1 oki * Compute the number of interrupts in the receive ring.
988 1.1 oki * If the count is overlarge, we lost some events, and
989 1.1 oki * must advance to the first valid one. It may get
990 1.1 oki * overwritten if more data are arriving, but this is
991 1.1 oki * too expensive to check and gains nothing (we already
992 1.1 oki * lost out; all we can do at this point is trade one
993 1.1 oki * kind of loss for another).
994 1.1 oki */
995 1.1 oki n -= get;
996 1.1 oki if (n > ZLRB_RING_SIZE) {
997 1.1 oki zsoverrun(unit, &cs->cs_rotime, "ring");
998 1.1 oki get += n - ZLRB_RING_SIZE;
999 1.1 oki n = ZLRB_RING_SIZE;
1000 1.1 oki }
1001 1.1 oki while (--n >= 0) {
1002 1.1 oki /* race to keep ahead of incoming interrupts */
1003 1.1 oki c = cs->cs_rbuf[get++ & ZLRB_RING_MASK];
1004 1.1 oki switch (ZRING_TYPE(c)) {
1005 1.1 oki
1006 1.1 oki case ZRING_RINT:
1007 1.1 oki c = ZRING_VALUE(c);
1008 1.1 oki if (c & ZSRR1_DO)
1009 1.1 oki zsoverrun(unit, &cs->cs_fotime, "fifo");
1010 1.1 oki cc = c >> 8;
1011 1.1 oki if (c & ZSRR1_FE)
1012 1.1 oki cc |= TTY_FE;
1013 1.1 oki if (c & ZSRR1_PE)
1014 1.1 oki cc |= TTY_PE;
1015 1.1 oki /*
1016 1.1 oki * this should be done through
1017 1.1 oki * bstreams XXX gag choke
1018 1.1 oki */
1019 1.1 oki else if (unit == ZS_MOUSE)
1020 1.1 oki ms_rint(cc);
1021 1.1 oki else
1022 1.1 oki line->l_rint(cc, tp);
1023 1.1 oki break;
1024 1.1 oki
1025 1.1 oki case ZRING_XINT:
1026 1.1 oki /*
1027 1.1 oki * Transmit done: change registers and resume,
1028 1.1 oki * or clear BUSY.
1029 1.1 oki */
1030 1.1 oki if (cs->cs_heldchange) {
1031 1.1 oki s = splzs();
1032 1.1 oki c = zc->zc_csr;
1033 1.1 oki ZS_DELAY();
1034 1.1 oki if ((c & ZSRR0_DCD) == 0)
1035 1.1 oki cs->cs_preg[3] &= ~ZSWR3_HFC;
1036 1.1 oki bcopy((caddr_t)cs->cs_preg,
1037 1.1 oki (caddr_t)cs->cs_creg, 16);
1038 1.1 oki zs_loadchannelregs(zc, cs->cs_creg);
1039 1.1 oki splx(s);
1040 1.1 oki cs->cs_heldchange = 0;
1041 1.1 oki if (cs->cs_heldtbc &&
1042 1.1 oki (tp->t_state & TS_TTSTOP) == 0) {
1043 1.1 oki cs->cs_tbc = cs->cs_heldtbc - 1;
1044 1.1 oki zc->zc_data = *cs->cs_tba++;
1045 1.1 oki ZS_DELAY();
1046 1.1 oki goto again;
1047 1.1 oki }
1048 1.1 oki }
1049 1.1 oki tp->t_state &= ~TS_BUSY;
1050 1.1 oki if (tp->t_state & TS_FLUSH)
1051 1.1 oki tp->t_state &= ~TS_FLUSH;
1052 1.1 oki else
1053 1.1 oki ndflush(&tp->t_outq,
1054 1.1 oki cs->cs_tba - (caddr_t)tp->t_outq.c_cf);
1055 1.1 oki line->l_start(tp);
1056 1.1 oki break;
1057 1.1 oki
1058 1.1 oki case ZRING_SINT:
1059 1.1 oki /*
1060 1.1 oki * Status line change. HFC bit is run in
1061 1.1 oki * hardware interrupt, to avoid locking
1062 1.1 oki * at splzs here.
1063 1.1 oki */
1064 1.1 oki c = ZRING_VALUE(c);
1065 1.1 oki if ((c ^ cs->cs_rr0) & ZSRR0_DCD) {
1066 1.1 oki cc = (c & ZSRR0_DCD) != 0;
1067 1.1 oki if (line->l_modem(tp, cc) == 0)
1068 1.1 oki zs_modem(cs, cc);
1069 1.1 oki }
1070 1.1 oki cs->cs_rr0 = c;
1071 1.1 oki break;
1072 1.1 oki
1073 1.1 oki default:
1074 1.1 oki log(LOG_ERR, "zs%d%c: bad ZRING_TYPE (%x)\n",
1075 1.1 oki unit >> 1, (unit & 1) + 'a', c);
1076 1.1 oki break;
1077 1.1 oki }
1078 1.1 oki }
1079 1.1 oki cs->cs_rbget = get;
1080 1.1 oki goto again;
1081 1.1 oki }
1082 1.1 oki return (retval);
1083 1.1 oki }
1084 1.1 oki
1085 1.1 oki int
1086 1.1 oki zsioctl(dev, cmd, data, flag, p)
1087 1.1 oki dev_t dev;
1088 1.1 oki u_long cmd;
1089 1.1 oki caddr_t data;
1090 1.1 oki int flag;
1091 1.1 oki struct proc *p;
1092 1.1 oki {
1093 1.1 oki int unit = minor(dev);
1094 1.1 oki struct zs_softc *zi = zs_cd.cd_devs[unit >> 1];
1095 1.1 oki register struct zs_chanstate *cs = &zi->zi_cs[unit & 1];
1096 1.1 oki register struct tty *tp = cs->cs_ttyp;
1097 1.1 oki register int error, s;
1098 1.1 oki
1099 1.1 oki error = linesw[tp->t_line].l_ioctl(tp, cmd, data, flag, p);
1100 1.1 oki if (error >= 0)
1101 1.1 oki return (error);
1102 1.1 oki error = ttioctl(tp, cmd, data, flag, p);
1103 1.1 oki if (error >= 0)
1104 1.1 oki return (error);
1105 1.1 oki
1106 1.1 oki switch (cmd) {
1107 1.1 oki case TIOCSBRK:
1108 1.1 oki s = splzs();
1109 1.1 oki cs->cs_preg[5] |= ZSWR5_BREAK;
1110 1.1 oki cs->cs_creg[5] |= ZSWR5_BREAK;
1111 1.1 oki ZS_WRITE(cs->cs_zc, 5, cs->cs_creg[5]);
1112 1.1 oki splx(s);
1113 1.1 oki break;
1114 1.1 oki case TIOCCBRK:
1115 1.1 oki s = splzs();
1116 1.1 oki cs->cs_preg[5] &= ~ZSWR5_BREAK;
1117 1.1 oki cs->cs_creg[5] &= ~ZSWR5_BREAK;
1118 1.1 oki ZS_WRITE(cs->cs_zc, 5, cs->cs_creg[5]);
1119 1.1 oki splx(s);
1120 1.1 oki break;
1121 1.1 oki case TIOCGFLAGS: {
1122 1.1 oki int bits = 0;
1123 1.1 oki
1124 1.1 oki if (cs->cs_softcar)
1125 1.1 oki bits |= TIOCFLAG_SOFTCAR;
1126 1.1 oki if (cs->cs_creg[15] & ZSWR15_DCD_IE)
1127 1.1 oki bits |= TIOCFLAG_CLOCAL;
1128 1.1 oki if (cs->cs_creg[3] & ZSWR3_HFC)
1129 1.1 oki bits |= TIOCFLAG_CRTSCTS;
1130 1.1 oki *(int *)data = bits;
1131 1.1 oki break;
1132 1.1 oki }
1133 1.1 oki case TIOCSFLAGS: {
1134 1.1 oki int userbits, driverbits = 0;
1135 1.1 oki
1136 1.1 oki error = suser(p->p_ucred, &p->p_acflag);
1137 1.1 oki if (error != 0)
1138 1.1 oki return (EPERM);
1139 1.1 oki
1140 1.1 oki userbits = *(int *)data;
1141 1.1 oki
1142 1.1 oki /*
1143 1.1 oki * can have `local' or `softcar', and `rtscts' or `mdmbuf'
1144 1.1 oki # defaulting to software flow control.
1145 1.1 oki */
1146 1.1 oki if (userbits & TIOCFLAG_SOFTCAR && userbits & TIOCFLAG_CLOCAL)
1147 1.1 oki return(EINVAL);
1148 1.1 oki if (userbits & TIOCFLAG_MDMBUF) /* don't support this (yet?) */
1149 1.1 oki return(ENXIO);
1150 1.1 oki
1151 1.1 oki s = splzs();
1152 1.1 oki if ((userbits & TIOCFLAG_SOFTCAR) || cs->cs_consio) {
1153 1.1 oki cs->cs_softcar = 1; /* turn on softcar */
1154 1.1 oki cs->cs_preg[15] &= ~ZSWR15_DCD_IE; /* turn off dcd */
1155 1.1 oki cs->cs_creg[15] &= ~ZSWR15_DCD_IE;
1156 1.1 oki ZS_WRITE(cs->cs_zc, 15, cs->cs_creg[15]);
1157 1.1 oki } else if (userbits & TIOCFLAG_CLOCAL) {
1158 1.1 oki cs->cs_softcar = 0; /* turn off softcar */
1159 1.1 oki cs->cs_preg[15] |= ZSWR15_DCD_IE; /* turn on dcd */
1160 1.1 oki cs->cs_creg[15] |= ZSWR15_DCD_IE;
1161 1.1 oki ZS_WRITE(cs->cs_zc, 15, cs->cs_creg[15]);
1162 1.1 oki tp->t_termios.c_cflag |= CLOCAL;
1163 1.1 oki }
1164 1.1 oki if (userbits & TIOCFLAG_CRTSCTS) {
1165 1.1 oki cs->cs_preg[15] |= ZSWR15_CTS_IE;
1166 1.1 oki cs->cs_creg[15] |= ZSWR15_CTS_IE;
1167 1.1 oki ZS_WRITE(cs->cs_zc, 15, cs->cs_creg[15]);
1168 1.1 oki cs->cs_preg[3] |= ZSWR3_HFC;
1169 1.1 oki cs->cs_creg[3] |= ZSWR3_HFC;
1170 1.1 oki ZS_WRITE(cs->cs_zc, 3, cs->cs_creg[3]);
1171 1.1 oki tp->t_termios.c_cflag |= CRTSCTS;
1172 1.1 oki } else {
1173 1.1 oki /* no mdmbuf, so we must want software flow control */
1174 1.1 oki cs->cs_preg[15] &= ~ZSWR15_CTS_IE;
1175 1.1 oki cs->cs_creg[15] &= ~ZSWR15_CTS_IE;
1176 1.1 oki ZS_WRITE(cs->cs_zc, 15, cs->cs_creg[15]);
1177 1.1 oki cs->cs_preg[3] &= ~ZSWR3_HFC;
1178 1.1 oki cs->cs_creg[3] &= ~ZSWR3_HFC;
1179 1.1 oki ZS_WRITE(cs->cs_zc, 3, cs->cs_creg[3]);
1180 1.1 oki tp->t_termios.c_cflag &= ~CRTSCTS;
1181 1.1 oki }
1182 1.1 oki splx(s);
1183 1.1 oki break;
1184 1.1 oki }
1185 1.1 oki case TIOCSDTR:
1186 1.1 oki zs_modem(cs, 1);
1187 1.1 oki break;
1188 1.1 oki case TIOCCDTR:
1189 1.1 oki zs_modem(cs, 0);
1190 1.1 oki break;
1191 1.1 oki case TIOCMSET:
1192 1.1 oki case TIOCMBIS:
1193 1.1 oki case TIOCMBIC:
1194 1.1 oki case TIOCMGET:
1195 1.1 oki default:
1196 1.1 oki return (ENOTTY);
1197 1.1 oki }
1198 1.1 oki return (0);
1199 1.1 oki }
1200 1.1 oki
1201 1.1 oki /*
1202 1.1 oki * Start or restart transmission.
1203 1.1 oki */
1204 1.1 oki static void
1205 1.1 oki zsstart(tp)
1206 1.1 oki register struct tty *tp;
1207 1.1 oki {
1208 1.1 oki register struct zs_chanstate *cs;
1209 1.1 oki register int s, nch;
1210 1.1 oki int unit = minor(tp->t_dev);
1211 1.1 oki struct zs_softc *zi = zs_cd.cd_devs[unit >> 1];
1212 1.1 oki
1213 1.1 oki cs = &zi->zi_cs[unit & 1];
1214 1.1 oki s = spltty();
1215 1.1 oki
1216 1.1 oki /*
1217 1.1 oki * If currently active or delaying, no need to do anything.
1218 1.1 oki */
1219 1.1 oki if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))
1220 1.1 oki goto out;
1221 1.1 oki
1222 1.1 oki /*
1223 1.1 oki * If there are sleepers, and output has drained below low
1224 1.1 oki * water mark, awaken.
1225 1.1 oki */
1226 1.1 oki if (tp->t_outq.c_cc <= tp->t_lowat) {
1227 1.1 oki if (tp->t_state & TS_ASLEEP) {
1228 1.1 oki tp->t_state &= ~TS_ASLEEP;
1229 1.1 oki wakeup((caddr_t)&tp->t_outq);
1230 1.1 oki }
1231 1.1 oki selwakeup(&tp->t_wsel);
1232 1.1 oki }
1233 1.1 oki
1234 1.1 oki nch = ndqb(&tp->t_outq, 0); /* XXX */
1235 1.1 oki if (nch) {
1236 1.1 oki register char *p = tp->t_outq.c_cf;
1237 1.1 oki
1238 1.1 oki /* mark busy, enable tx done interrupts, & send first byte */
1239 1.1 oki tp->t_state |= TS_BUSY;
1240 1.1 oki (void) splzs();
1241 1.1 oki cs->cs_preg[1] |= ZSWR1_TIE;
1242 1.1 oki cs->cs_creg[1] |= ZSWR1_TIE;
1243 1.1 oki ZS_WRITE(cs->cs_zc, 1, cs->cs_creg[1]);
1244 1.1 oki cs->cs_zc->zc_data = *p;
1245 1.1 oki ZS_DELAY();
1246 1.1 oki cs->cs_tba = p + 1;
1247 1.1 oki cs->cs_tbc = nch - 1;
1248 1.1 oki } else {
1249 1.1 oki /*
1250 1.1 oki * Nothing to send, turn off transmit done interrupts.
1251 1.1 oki * This is useful if something is doing polled output.
1252 1.1 oki */
1253 1.1 oki (void) splzs();
1254 1.1 oki cs->cs_preg[1] &= ~ZSWR1_TIE;
1255 1.1 oki cs->cs_creg[1] &= ~ZSWR1_TIE;
1256 1.1 oki ZS_WRITE(cs->cs_zc, 1, cs->cs_creg[1]);
1257 1.1 oki }
1258 1.1 oki out:
1259 1.1 oki splx(s);
1260 1.1 oki }
1261 1.1 oki
1262 1.1 oki /*
1263 1.1 oki * Stop output, e.g., for ^S or output flush.
1264 1.1 oki */
1265 1.4 mycroft void
1266 1.1 oki zsstop(tp, flag)
1267 1.1 oki register struct tty *tp;
1268 1.1 oki int flag;
1269 1.1 oki {
1270 1.1 oki register struct zs_chanstate *cs;
1271 1.1 oki register int s, unit = minor(tp->t_dev);
1272 1.1 oki struct zs_softc *zi = zs_cd.cd_devs[unit >> 1];
1273 1.1 oki
1274 1.1 oki cs = &zi->zi_cs[unit & 1];
1275 1.1 oki s = splzs();
1276 1.1 oki if (tp->t_state & TS_BUSY) {
1277 1.1 oki /*
1278 1.1 oki * Device is transmitting; must stop it.
1279 1.1 oki */
1280 1.1 oki cs->cs_tbc = 0;
1281 1.1 oki if ((tp->t_state & TS_TTSTOP) == 0)
1282 1.1 oki tp->t_state |= TS_FLUSH;
1283 1.1 oki }
1284 1.1 oki splx(s);
1285 1.1 oki }
1286 1.1 oki
1287 1.1 oki /*
1288 1.1 oki * Set ZS tty parameters from termios.
1289 1.1 oki *
1290 1.1 oki * This routine makes use of the fact that only registers
1291 1.1 oki * 1, 3, 4, 5, 9, 10, 11, 12, 13, 14, and 15 are written.
1292 1.1 oki */
1293 1.1 oki static int
1294 1.1 oki zsparam(tp, t)
1295 1.1 oki register struct tty *tp;
1296 1.1 oki register struct termios *t;
1297 1.1 oki {
1298 1.1 oki int unit = minor(tp->t_dev);
1299 1.1 oki struct zs_softc *zi = zs_cd.cd_devs[unit >> 1];
1300 1.1 oki register struct zs_chanstate *cs = &zi->zi_cs[unit & 1];
1301 1.1 oki register int tmp, tmp5, cflag, s;
1302 1.1 oki
1303 1.1 oki /*
1304 1.1 oki * Because PCLK is only run at 5 MHz, the fastest we
1305 1.1 oki * can go is 51200 baud (this corresponds to TC=1).
1306 1.1 oki * This is somewhat unfortunate as there is no real
1307 1.1 oki * reason we should not be able to handle higher rates.
1308 1.1 oki */
1309 1.1 oki tmp = t->c_ospeed;
1310 1.1 oki if (tmp < 0 || (t->c_ispeed && t->c_ispeed != tmp))
1311 1.1 oki return (EINVAL);
1312 1.1 oki if (tmp == 0) {
1313 1.1 oki /* stty 0 => drop DTR and RTS */
1314 1.1 oki zs_modem(cs, 0);
1315 1.1 oki return (0);
1316 1.1 oki }
1317 1.1 oki tmp = BPS_TO_TCONST(PCLK / 16, tmp);
1318 1.1 oki if (tmp < 2)
1319 1.1 oki return (EINVAL);
1320 1.1 oki
1321 1.1 oki cflag = t->c_cflag;
1322 1.1 oki tp->t_ispeed = tp->t_ospeed = TCONST_TO_BPS(PCLK / 16, tmp);
1323 1.1 oki tp->t_cflag = cflag;
1324 1.1 oki
1325 1.1 oki /*
1326 1.1 oki * Block interrupts so that state will not
1327 1.1 oki * be altered until we are done setting it up.
1328 1.1 oki */
1329 1.1 oki s = splzs();
1330 1.1 oki cs->cs_preg[12] = tmp;
1331 1.1 oki cs->cs_preg[13] = tmp >> 8;
1332 1.1 oki cs->cs_preg[1] = ZSWR1_RIE | ZSWR1_TIE | ZSWR1_SIE;
1333 1.1 oki switch (cflag & CSIZE) {
1334 1.1 oki case CS5:
1335 1.1 oki tmp = ZSWR3_RX_5;
1336 1.1 oki tmp5 = ZSWR5_TX_5;
1337 1.1 oki break;
1338 1.1 oki case CS6:
1339 1.1 oki tmp = ZSWR3_RX_6;
1340 1.1 oki tmp5 = ZSWR5_TX_6;
1341 1.1 oki break;
1342 1.1 oki case CS7:
1343 1.1 oki tmp = ZSWR3_RX_7;
1344 1.1 oki tmp5 = ZSWR5_TX_7;
1345 1.1 oki break;
1346 1.1 oki case CS8:
1347 1.1 oki default:
1348 1.1 oki tmp = ZSWR3_RX_8;
1349 1.1 oki tmp5 = ZSWR5_TX_8;
1350 1.1 oki break;
1351 1.1 oki }
1352 1.1 oki
1353 1.1 oki /*
1354 1.1 oki * Output hardware flow control on the chip is horrendous: if
1355 1.1 oki * carrier detect drops, the receiver is disabled. Hence we
1356 1.1 oki * can only do this when the carrier is on.
1357 1.1 oki */
1358 1.1 oki tmp |= ZSWR3_RX_ENABLE;
1359 1.1 oki if (cflag & CCTS_OFLOW) {
1360 1.1 oki if (cs->cs_zc->zc_csr & ZSRR0_DCD)
1361 1.1 oki tmp |= ZSWR3_HFC;
1362 1.1 oki ZS_DELAY();
1363 1.1 oki }
1364 1.1 oki cs->cs_preg[3] = tmp;
1365 1.1 oki cs->cs_preg[5] = tmp5 | ZSWR5_TX_ENABLE | ZSWR5_DTR | ZSWR5_RTS;
1366 1.1 oki
1367 1.1 oki tmp = ZSWR4_CLK_X16 | (cflag & CSTOPB ? ZSWR4_TWOSB : ZSWR4_ONESB);
1368 1.1 oki if ((cflag & PARODD) == 0)
1369 1.1 oki tmp |= ZSWR4_EVENP;
1370 1.1 oki if (cflag & PARENB)
1371 1.1 oki tmp |= ZSWR4_PARENB;
1372 1.1 oki cs->cs_preg[4] = tmp;
1373 1.1 oki cs->cs_preg[9] = ZSWR9_MASTER_IE /*| ZSWR9_NO_VECTOR*/;
1374 1.1 oki cs->cs_preg[10] = ZSWR10_NRZ;
1375 1.1 oki cs->cs_preg[11] = ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD;
1376 1.1 oki cs->cs_preg[14] = ZSWR14_BAUD_FROM_PCLK | ZSWR14_BAUD_ENA;
1377 1.1 oki cs->cs_preg[15] = ZSWR15_BREAK_IE | ZSWR15_DCD_IE;
1378 1.1 oki
1379 1.1 oki /*
1380 1.1 oki * If nothing is being transmitted, set up new current values,
1381 1.1 oki * else mark them as pending.
1382 1.1 oki */
1383 1.1 oki if (cs->cs_heldchange == 0) {
1384 1.1 oki if (cs->cs_ttyp->t_state & TS_BUSY) {
1385 1.1 oki cs->cs_heldtbc = cs->cs_tbc;
1386 1.1 oki cs->cs_tbc = 0;
1387 1.1 oki cs->cs_heldchange = 1;
1388 1.1 oki } else {
1389 1.1 oki bcopy((caddr_t)cs->cs_preg, (caddr_t)cs->cs_creg, 16);
1390 1.1 oki zs_loadchannelregs(cs->cs_zc, cs->cs_creg);
1391 1.1 oki }
1392 1.1 oki }
1393 1.1 oki splx(s);
1394 1.1 oki return (0);
1395 1.1 oki }
1396 1.1 oki
1397 1.1 oki /*
1398 1.1 oki * Raise or lower modem control (DTR/RTS) signals. If a character is
1399 1.1 oki * in transmission, the change is deferred.
1400 1.1 oki */
1401 1.1 oki static void
1402 1.1 oki zs_modem(cs, onoff)
1403 1.1 oki struct zs_chanstate *cs;
1404 1.1 oki int onoff;
1405 1.1 oki {
1406 1.1 oki int s, bis, and;
1407 1.1 oki
1408 1.1 oki if (onoff) {
1409 1.1 oki bis = ZSWR5_DTR | ZSWR5_RTS;
1410 1.1 oki and = ~0;
1411 1.1 oki } else {
1412 1.1 oki bis = 0;
1413 1.1 oki and = ~(ZSWR5_DTR | ZSWR5_RTS);
1414 1.1 oki }
1415 1.1 oki s = splzs();
1416 1.1 oki cs->cs_preg[5] = (cs->cs_preg[5] | bis) & and;
1417 1.1 oki if (cs->cs_heldchange == 0) {
1418 1.1 oki if (cs->cs_ttyp->t_state & TS_BUSY) {
1419 1.1 oki cs->cs_heldtbc = cs->cs_tbc;
1420 1.1 oki cs->cs_tbc = 0;
1421 1.1 oki cs->cs_heldchange = 1;
1422 1.1 oki } else {
1423 1.1 oki cs->cs_creg[5] = (cs->cs_creg[5] | bis) & and;
1424 1.1 oki ZS_WRITE(cs->cs_zc, 5, cs->cs_creg[5]);
1425 1.1 oki }
1426 1.1 oki }
1427 1.1 oki splx(s);
1428 1.1 oki }
1429 1.1 oki
1430 1.1 oki /*
1431 1.1 oki * Hardware flow (RTS) control.
1432 1.1 oki */
1433 1.1 oki static int
1434 1.1 oki zshwiflow(tp, flag)
1435 1.1 oki struct tty *tp;
1436 1.1 oki int flag;
1437 1.1 oki {
1438 1.1 oki int unit = minor(tp->t_dev);
1439 1.1 oki struct zs_softc *zi = zs_cd.cd_devs[unit >> 1];
1440 1.1 oki register struct zs_chanstate *cs = &zi->zi_cs[unit & 1];
1441 1.1 oki int s;
1442 1.1 oki
1443 1.1 oki #if 0
1444 1.6 christos printf ("zshwiflow %d\n", flag);
1445 1.1 oki #endif
1446 1.1 oki s = splzs();
1447 1.1 oki if (flag) {
1448 1.1 oki cs->cs_preg[5] &= ~ZSWR5_RTS;
1449 1.1 oki cs->cs_creg[5] &= ~ZSWR5_RTS;
1450 1.1 oki ZS_WRITE(cs->cs_zc, 5, cs->cs_creg[5]);
1451 1.1 oki } else {
1452 1.1 oki cs->cs_preg[5] |= ZSWR5_RTS;
1453 1.1 oki cs->cs_creg[5] |= ZSWR5_RTS;
1454 1.1 oki ZS_WRITE(cs->cs_zc, 5, cs->cs_creg[5]);
1455 1.1 oki }
1456 1.1 oki splx(s);
1457 1.1 oki return 1;
1458 1.1 oki }
1459 1.1 oki
1460 1.1 oki /*
1461 1.1 oki * Write the given register set to the given zs channel in the proper order.
1462 1.1 oki * The channel must not be transmitting at the time. The receiver will
1463 1.1 oki * be disabled for the time it takes to write all the registers.
1464 1.1 oki */
1465 1.1 oki static void
1466 1.1 oki zs_loadchannelregs(zc, reg)
1467 1.1 oki volatile struct zschan *zc;
1468 1.1 oki u_char *reg;
1469 1.1 oki {
1470 1.1 oki int i;
1471 1.1 oki
1472 1.1 oki zc->zc_csr = ZSM_RESET_ERR; /* reset error condition */
1473 1.1 oki ZS_DELAY();
1474 1.1 oki i = zc->zc_data; /* drain fifo */
1475 1.1 oki ZS_DELAY();
1476 1.1 oki i = zc->zc_data;
1477 1.1 oki ZS_DELAY();
1478 1.1 oki i = zc->zc_data;
1479 1.1 oki ZS_DELAY();
1480 1.1 oki ZS_WRITE(zc, 4, reg[4]);
1481 1.1 oki ZS_WRITE(zc, 10, reg[10]);
1482 1.1 oki ZS_WRITE(zc, 3, reg[3] & ~ZSWR3_RX_ENABLE);
1483 1.1 oki ZS_WRITE(zc, 5, reg[5] & ~ZSWR5_TX_ENABLE);
1484 1.1 oki ZS_WRITE(zc, 1, reg[1]);
1485 1.1 oki ZS_WRITE(zc, 9, reg[9]);
1486 1.1 oki ZS_WRITE(zc, 11, reg[11]);
1487 1.1 oki ZS_WRITE(zc, 12, reg[12]);
1488 1.1 oki ZS_WRITE(zc, 13, reg[13]);
1489 1.1 oki ZS_WRITE(zc, 14, reg[14]);
1490 1.1 oki ZS_WRITE(zc, 15, reg[15]);
1491 1.1 oki ZS_WRITE(zc, 3, reg[3]);
1492 1.1 oki ZS_WRITE(zc, 5, reg[5]);
1493 1.1 oki }
1494 1.1 oki
1495 1.1 oki #ifdef x68k
1496 1.1 oki void
1497 1.1 oki zs_msmodem(onoff)
1498 1.1 oki int onoff;
1499 1.1 oki {
1500 1.1 oki if (zsms != NULL) {
1501 1.1 oki zs_modem(zsms, onoff);
1502 1.1 oki while(!(mfp.tsr & MFP_TSR_BE))
1503 1.1 oki /* XXX wait */ ;
1504 1.1 oki mfp.udr = 0x40 | (onoff ? 0 : 1);
1505 1.1 oki }
1506 1.1 oki }
1507 1.1 oki #endif
1508 1.1 oki
1509 1.1 oki #ifdef KGDB
1510 1.1 oki /*
1511 1.1 oki * Get a character from the given kgdb channel. Called at splhigh().
1512 1.1 oki */
1513 1.1 oki static int
1514 1.1 oki zs_kgdb_getc(arg)
1515 1.1 oki void *arg;
1516 1.1 oki {
1517 1.1 oki register volatile struct zschan *zc = (volatile struct zschan *)arg;
1518 1.1 oki
1519 1.1 oki while ((zc->zc_csr & ZSRR0_RX_READY) == 0)
1520 1.1 oki ZS_DELAY();
1521 1.1 oki return (zc->zc_data);
1522 1.1 oki }
1523 1.1 oki
1524 1.1 oki /*
1525 1.1 oki * Put a character to the given kgdb channel. Called at splhigh().
1526 1.1 oki */
1527 1.1 oki static void
1528 1.1 oki zs_kgdb_putc(arg, c)
1529 1.1 oki void *arg;
1530 1.1 oki int c;
1531 1.1 oki {
1532 1.1 oki register volatile struct zschan *zc = (volatile struct zschan *)arg;
1533 1.1 oki
1534 1.1 oki while ((zc->zc_csr & ZSRR0_TX_READY) == 0)
1535 1.1 oki ZS_DELAY();
1536 1.1 oki zc->zc_data = c;
1537 1.1 oki ZS_DELAY();
1538 1.1 oki }
1539 1.1 oki
1540 1.1 oki /*
1541 1.1 oki * Set up for kgdb; called at boot time before configuration.
1542 1.1 oki * KGDB interrupts will be enabled later when zs0 is configured.
1543 1.1 oki */
1544 1.1 oki void
1545 1.1 oki zs_kgdb_init()
1546 1.1 oki {
1547 1.1 oki volatile struct zsdevice *addr;
1548 1.1 oki volatile struct zschan *zc;
1549 1.1 oki int unit, zs;
1550 1.1 oki
1551 1.1 oki if (major(kgdb_dev) != ZSMAJOR)
1552 1.1 oki return;
1553 1.1 oki unit = minor(kgdb_dev);
1554 1.1 oki zs = unit >> 1;
1555 1.1 oki if ((addr = zsaddr[zs]) == NULL)
1556 1.1 oki addr = zsaddr[zs] = findzs(zs);
1557 1.1 oki unit &= 1;
1558 1.1 oki zc = unit == 0 ? &addr->zs_chan[ZS_CHAN_A] : &addr->zs_chan[ZS_CHAN_B];
1559 1.1 oki zs_kgdb_savedspeed = zs_getspeed(zc);
1560 1.6 christos printf("zs_kgdb_init: attaching zs%d%c at %d baud\n",
1561 1.1 oki zs, unit + 'a', kgdb_rate);
1562 1.1 oki zs_reset(zc, 1, kgdb_rate);
1563 1.1 oki kgdb_attach(zs_kgdb_getc, zs_kgdb_putc, (void *)zc);
1564 1.1 oki }
1565 1.1 oki #endif /* KGDB */
1566 1.1 oki #endif
1567