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