zs.c revision 1.5 1 1.5 leo /* $NetBSD: zs.c,v 1.5 1995/05/14 15:55:51 leo Exp $ */
2 1.1 leo
3 1.1 leo /*
4 1.1 leo * Copyright (c) 1995 L. Weppelman (Atari modifications)
5 1.1 leo * Copyright (c) 1992, 1993
6 1.1 leo * The Regents of the University of California. All rights reserved.
7 1.1 leo *
8 1.1 leo * This software was developed by the Computer Systems Engineering group
9 1.1 leo * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
10 1.1 leo * contributed to Berkeley.
11 1.1 leo *
12 1.1 leo *
13 1.1 leo * All advertising materials mentioning features or use of this software
14 1.1 leo * must display the following acknowledgement:
15 1.1 leo * This product includes software developed by the University of
16 1.1 leo * California, Lawrence Berkeley Laboratory.
17 1.1 leo *
18 1.1 leo * Redistribution and use in source and binary forms, with or without
19 1.1 leo * modification, are permitted provided that the following conditions
20 1.1 leo * are met:
21 1.1 leo * 1. Redistributions of source code must retain the above copyright
22 1.1 leo * notice, this list of conditions and the following disclaimer.
23 1.1 leo * 2. Redistributions in binary form must reproduce the above copyright
24 1.1 leo * notice, this list of conditions and the following disclaimer in the
25 1.1 leo * documentation and/or other materials provided with the distribution.
26 1.1 leo * 3. All advertising materials mentioning features or use of this software
27 1.1 leo * must display the following acknowledgement:
28 1.1 leo * This product includes software developed by the University of
29 1.1 leo * California, Berkeley and its contributors.
30 1.1 leo * 4. Neither the name of the University nor the names of its contributors
31 1.1 leo * may be used to endorse or promote products derived from this software
32 1.1 leo * without specific prior written permission.
33 1.1 leo *
34 1.1 leo * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
35 1.1 leo * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36 1.1 leo * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37 1.1 leo * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
38 1.1 leo * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39 1.1 leo * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
40 1.1 leo * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41 1.1 leo * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42 1.1 leo * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
43 1.1 leo * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44 1.1 leo * SUCH DAMAGE.
45 1.1 leo *
46 1.1 leo * @(#)zs.c 8.1 (Berkeley) 7/19/93
47 1.1 leo */
48 1.1 leo
49 1.1 leo /*
50 1.1 leo * Zilog Z8530 (ZSCC) driver.
51 1.1 leo *
52 1.1 leo * Runs two tty ports (modem2 and serial2) on zs0.
53 1.1 leo *
54 1.1 leo * This driver knows far too much about chip to usage mappings.
55 1.1 leo */
56 1.1 leo #include <sys/param.h>
57 1.1 leo #include <sys/proc.h>
58 1.1 leo #include <sys/device.h>
59 1.1 leo #include <sys/conf.h>
60 1.1 leo #include <sys/file.h>
61 1.1 leo #include <sys/ioctl.h>
62 1.1 leo #include <sys/tty.h>
63 1.1 leo #include <sys/time.h>
64 1.1 leo #include <sys/kernel.h>
65 1.1 leo #include <sys/syslog.h>
66 1.1 leo
67 1.1 leo #include <machine/cpu.h>
68 1.1 leo #include <machine/iomap.h>
69 1.1 leo #include <machine/scu.h>
70 1.1 leo #include <machine/mfp.h>
71 1.1 leo
72 1.2 mycroft #include <dev/ic/z8530.h>
73 1.1 leo #include <atari/dev/zsvar.h>
74 1.1 leo #include "zs.h"
75 1.1 leo #if NZS > 1
76 1.1 leo #error "This driver supports only 1 85C30!"
77 1.1 leo #endif
78 1.1 leo
79 1.1 leo #if NZS > 0
80 1.1 leo
81 1.1 leo #define PCLK (8000000) /* PCLK pin input clock rate */
82 1.1 leo
83 1.1 leo #define splzs spl5
84 1.1 leo
85 1.1 leo /*
86 1.1 leo * Software state per found chip.
87 1.1 leo */
88 1.1 leo struct zs_softc {
89 1.1 leo struct device zi_dev; /* base device */
90 1.1 leo volatile struct zsdevice *zi_zs; /* chip registers */
91 1.1 leo struct zs_chanstate zi_cs[2]; /* chan A and B software state */
92 1.1 leo };
93 1.1 leo
94 1.1 leo /*
95 1.1 leo * Define the registers for a closed port
96 1.1 leo */
97 1.1 leo u_char zs_init_regs[16] = {
98 1.1 leo /* 0 */ 0,
99 1.1 leo /* 1 */ 0,
100 1.1 leo /* 2 */ 0x60,
101 1.1 leo /* 3 */ 0,
102 1.1 leo /* 4 */ 0,
103 1.1 leo /* 5 */ 0,
104 1.1 leo /* 6 */ 0,
105 1.1 leo /* 7 */ 0,
106 1.1 leo /* 8 */ 0,
107 1.1 leo /* 9 */ ZSWR9_VECTOR_INCL_STAT,
108 1.1 leo /* 10 */ ZSWR10_NRZ,
109 1.1 leo /* 11 */ ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD,
110 1.1 leo /* 12 */ 0,
111 1.1 leo /* 13 */ 0,
112 1.1 leo /* 14 */ ZSWR14_BAUD_FROM_PCLK | ZSWR14_BAUD_ENA,
113 1.1 leo /* 15 */ 0
114 1.1 leo };
115 1.1 leo
116 1.1 leo /* Definition of the driver for autoconfig. */
117 1.1 leo static int zsmatch __P((struct device *, struct cfdata *, void *));
118 1.1 leo static void zsattach __P((struct device *, struct device *, void *));
119 1.1 leo struct cfdriver zscd = {
120 1.1 leo NULL, "zs", (cfmatch_t)zsmatch, zsattach, DV_TTY,
121 1.1 leo sizeof(struct zs_softc), NULL, 0 };
122 1.1 leo
123 1.1 leo /* Interrupt handlers. */
124 1.1 leo int zshard __P((long));
125 1.1 leo static int zssoft __P((long));
126 1.1 leo static int zsrint __P((struct zs_chanstate *, volatile struct zschan *));
127 1.1 leo static int zsxint __P((struct zs_chanstate *, volatile struct zschan *));
128 1.1 leo static int zssint __P((struct zs_chanstate *, volatile struct zschan *));
129 1.1 leo
130 1.1 leo struct zs_chanstate *zslist;
131 1.1 leo
132 1.1 leo /* Routines called from other code. */
133 1.1 leo static void zsstart __P((struct tty *));
134 1.1 leo void zsstop __P((struct tty *, int));
135 1.1 leo static int zsparam __P((struct tty *, struct termios *));
136 1.1 leo
137 1.1 leo /* Routines purely local to this driver. */
138 1.1 leo static void zs_reset __P((volatile struct zschan *, int, int));
139 1.1 leo static int zs_modem __P((struct zs_chanstate *, int, int));
140 1.1 leo static void zs_loadchannelregs __P((volatile struct zschan *, u_char *));
141 1.1 leo
142 1.1 leo int zsshortcuts; /* number of "shortcut" software interrupts */
143 1.1 leo
144 1.4 leo static int
145 1.4 leo zsmatch(pdp, cfp, auxp)
146 1.1 leo struct device *pdp;
147 1.1 leo struct cfdata *cfp;
148 1.1 leo void *auxp;
149 1.1 leo {
150 1.1 leo if(strcmp("zs", auxp) || cfp->cf_unit != 0)
151 1.1 leo return(0);
152 1.1 leo return(1);
153 1.1 leo }
154 1.1 leo
155 1.1 leo /*
156 1.1 leo * Attach a found zs.
157 1.1 leo */
158 1.1 leo static void
159 1.1 leo zsattach(parent, dev, aux)
160 1.1 leo struct device *parent;
161 1.1 leo struct device *dev;
162 1.1 leo void *aux;
163 1.1 leo {
164 1.1 leo register struct zs_softc *zi;
165 1.1 leo register struct zs_chanstate *cs;
166 1.1 leo register volatile struct zsdevice *addr;
167 1.1 leo register struct tty *tp;
168 1.1 leo char tmp;
169 1.1 leo
170 1.1 leo addr = (struct zsdevice *)AD_SCC;
171 1.1 leo zi = (struct zs_softc *)dev;
172 1.1 leo zi->zi_zs = addr;
173 1.1 leo cs = zi->zi_cs;
174 1.1 leo
175 1.1 leo /*
176 1.1 leo * Get the command register into a known state.
177 1.1 leo */
178 1.2 mycroft tmp = addr->zs_chan[ZS_CHAN_A].zc_csr;
179 1.2 mycroft tmp = addr->zs_chan[ZS_CHAN_A].zc_csr;
180 1.2 mycroft tmp = addr->zs_chan[ZS_CHAN_B].zc_csr;
181 1.2 mycroft tmp = addr->zs_chan[ZS_CHAN_B].zc_csr;
182 1.1 leo
183 1.1 leo /*
184 1.1 leo * Do a hardware reset.
185 1.1 leo */
186 1.2 mycroft ZS_WRITE(&addr->zs_chan[ZS_CHAN_A], 9, ZSWR9_HARD_RESET);
187 1.1 leo delay(50000); /*enough ? */
188 1.2 mycroft ZS_WRITE(&addr->zs_chan[ZS_CHAN_A], 9, 0);
189 1.1 leo
190 1.1 leo /*
191 1.1 leo * Initialize both channels
192 1.1 leo */
193 1.2 mycroft zs_loadchannelregs(&addr->zs_chan[ZS_CHAN_A], zs_init_regs);
194 1.2 mycroft zs_loadchannelregs(&addr->zs_chan[ZS_CHAN_B], zs_init_regs);
195 1.1 leo
196 1.5 leo if(machineid & ATARI_TT) {
197 1.5 leo /*
198 1.5 leo * enable scc related interrupts
199 1.5 leo */
200 1.5 leo SCU->sys_mask |= SCU_SCC;
201 1.5 leo }
202 1.1 leo
203 1.1 leo /* link into interrupt list with order (A,B) (B=A+1) */
204 1.1 leo cs[0].cs_next = &cs[1];
205 1.1 leo cs[1].cs_next = zslist;
206 1.1 leo zslist = cs;
207 1.1 leo
208 1.1 leo cs->cs_unit = 0;
209 1.2 mycroft cs->cs_zc = &addr->zs_chan[ZS_CHAN_A];
210 1.1 leo cs++;
211 1.1 leo cs->cs_unit = 1;
212 1.2 mycroft cs->cs_zc = &addr->zs_chan[ZS_CHAN_B];
213 1.1 leo
214 1.1 leo printf(": serial2 on channel a and modem2 on channel b\n");
215 1.1 leo }
216 1.1 leo
217 1.1 leo /*
218 1.1 leo * Open a zs serial port.
219 1.1 leo */
220 1.1 leo int
221 1.1 leo zsopen(dev, flags, mode, p)
222 1.1 leo dev_t dev;
223 1.1 leo int flags;
224 1.1 leo int mode;
225 1.1 leo struct proc *p;
226 1.1 leo {
227 1.1 leo register struct tty *tp;
228 1.1 leo register struct zs_chanstate *cs;
229 1.1 leo struct zs_softc *zi;
230 1.1 leo int unit = ZS_UNIT(dev);
231 1.1 leo int zs = unit >> 1;
232 1.1 leo int error, s;
233 1.1 leo
234 1.1 leo if(zs >= zscd.cd_ndevs || (zi = zscd.cd_devs[zs]) == NULL)
235 1.1 leo return (ENXIO);
236 1.1 leo cs = &zi->zi_cs[unit & 1];
237 1.1 leo tp = cs->cs_ttyp;
238 1.1 leo if(tp == NULL) {
239 1.4 leo cs->cs_ttyp = tp = ttymalloc();
240 1.1 leo tp->t_dev = dev;
241 1.1 leo tp->t_oproc = zsstart;
242 1.1 leo tp->t_param = zsparam;
243 1.1 leo }
244 1.1 leo
245 1.1 leo s = spltty();
246 1.1 leo if((tp->t_state & TS_ISOPEN) == 0) {
247 1.1 leo ttychars(tp);
248 1.1 leo if(tp->t_ispeed == 0) {
249 1.1 leo tp->t_iflag = TTYDEF_IFLAG;
250 1.1 leo tp->t_oflag = TTYDEF_OFLAG;
251 1.1 leo tp->t_cflag = TTYDEF_CFLAG;
252 1.1 leo tp->t_lflag = TTYDEF_LFLAG;
253 1.1 leo tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
254 1.1 leo }
255 1.1 leo (void)zsparam(tp, &tp->t_termios);
256 1.1 leo ttsetwater(tp);
257 1.1 leo }
258 1.1 leo else if(tp->t_state & TS_XCLUDE && p->p_ucred->cr_uid != 0) {
259 1.1 leo splx(s);
260 1.1 leo return (EBUSY);
261 1.1 leo }
262 1.1 leo error = 0;
263 1.1 leo for(;;) {
264 1.1 leo /* loop, turning on the device, until carrier present */
265 1.1 leo zs_modem(cs, ZSWR5_RTS|ZSWR5_DTR, DMSET);
266 1.1 leo if(cs->cs_softcar)
267 1.1 leo tp->t_state |= TS_CARR_ON;
268 1.1 leo if(flags & O_NONBLOCK || tp->t_cflag & CLOCAL ||
269 1.1 leo tp->t_state & TS_CARR_ON)
270 1.1 leo break;
271 1.1 leo tp->t_state |= TS_WOPEN;
272 1.1 leo if(error = ttysleep(tp, (caddr_t)&tp->t_rawq, TTIPRI | PCATCH,
273 1.1 leo ttopen, 0)) {
274 1.1 leo if(!(tp->t_state & TS_ISOPEN)) {
275 1.1 leo zs_modem(cs, 0, DMSET);
276 1.1 leo tp->t_state &= ~TS_WOPEN;
277 1.1 leo ttwakeup(tp);
278 1.1 leo }
279 1.1 leo splx(s);
280 1.1 leo return error;
281 1.1 leo }
282 1.1 leo }
283 1.1 leo splx(s);
284 1.1 leo if(error == 0)
285 1.1 leo error = linesw[tp->t_line].l_open(dev, tp);
286 1.1 leo if(error)
287 1.1 leo zs_modem(cs, 0, DMSET);
288 1.1 leo return(error);
289 1.1 leo }
290 1.1 leo
291 1.1 leo /*
292 1.1 leo * Close a zs serial port.
293 1.1 leo */
294 1.1 leo int
295 1.1 leo zsclose(dev, flags, mode, p)
296 1.1 leo dev_t dev;
297 1.1 leo int flags;
298 1.1 leo int mode;
299 1.1 leo struct proc *p;
300 1.1 leo {
301 1.1 leo register struct zs_chanstate *cs;
302 1.1 leo register struct tty *tp;
303 1.1 leo struct zs_softc *zi;
304 1.1 leo int unit = ZS_UNIT(dev);
305 1.1 leo int s;
306 1.1 leo
307 1.1 leo zi = zscd.cd_devs[unit >> 1];
308 1.1 leo cs = &zi->zi_cs[unit & 1];
309 1.1 leo tp = cs->cs_ttyp;
310 1.1 leo linesw[tp->t_line].l_close(tp, flags);
311 1.1 leo if(tp->t_cflag & HUPCL || tp->t_state & TS_WOPEN ||
312 1.1 leo (tp->t_state & TS_ISOPEN) == 0) {
313 1.1 leo zs_modem(cs, 0, DMSET);
314 1.1 leo /* hold low for 1 second */
315 1.1 leo (void)tsleep((caddr_t)cs, TTIPRI, ttclos, hz);
316 1.1 leo }
317 1.1 leo if(cs->cs_creg[5] & ZSWR5_BREAK) {
318 1.1 leo s = splzs();
319 1.1 leo cs->cs_preg[5] &= ~ZSWR5_BREAK;
320 1.1 leo cs->cs_creg[5] &= ~ZSWR5_BREAK;
321 1.1 leo ZS_WRITE(cs->cs_zc, 5, cs->cs_creg[5]);
322 1.1 leo splx(s);
323 1.1 leo }
324 1.1 leo ttyclose(tp);
325 1.1 leo
326 1.1 leo /*
327 1.1 leo * Drop all lines and cancel interrupts
328 1.1 leo */
329 1.1 leo zs_loadchannelregs(&zi->zi_zs->zs_chan[unit & 1], zs_init_regs);
330 1.1 leo return (0);
331 1.1 leo }
332 1.1 leo
333 1.1 leo /*
334 1.1 leo * Read/write zs serial port.
335 1.1 leo */
336 1.1 leo int
337 1.1 leo zsread(dev, uio, flags)
338 1.1 leo dev_t dev;
339 1.1 leo struct uio *uio;
340 1.1 leo int flags;
341 1.1 leo {
342 1.4 leo register struct zs_chanstate *cs;
343 1.4 leo register struct zs_softc *zi;
344 1.4 leo register struct tty *tp;
345 1.4 leo int unit;
346 1.4 leo
347 1.4 leo unit = ZS_UNIT(dev);
348 1.4 leo zi = zscd.cd_devs[unit >> 1];
349 1.4 leo cs = &zi->zi_cs[unit & 1];
350 1.4 leo tp = cs->cs_ttyp;
351 1.1 leo
352 1.1 leo return(linesw[tp->t_line].l_read(tp, uio, flags));
353 1.1 leo }
354 1.1 leo
355 1.4 leo int
356 1.4 leo zswrite(dev, uio, flags)
357 1.1 leo dev_t dev;
358 1.1 leo struct uio *uio;
359 1.1 leo int flags;
360 1.1 leo {
361 1.4 leo register struct zs_chanstate *cs;
362 1.4 leo register struct zs_softc *zi;
363 1.4 leo register struct tty *tp;
364 1.4 leo int unit;
365 1.4 leo
366 1.4 leo unit = ZS_UNIT(dev);
367 1.4 leo zi = zscd.cd_devs[unit >> 1];
368 1.4 leo cs = &zi->zi_cs[unit & 1];
369 1.4 leo tp = cs->cs_ttyp;
370 1.1 leo
371 1.1 leo return(linesw[tp->t_line].l_write(tp, uio, flags));
372 1.4 leo }
373 1.4 leo
374 1.4 leo struct tty *
375 1.4 leo zstty(dev)
376 1.4 leo dev_t dev;
377 1.4 leo {
378 1.4 leo register struct zs_chanstate *cs;
379 1.4 leo register struct zs_softc *zi;
380 1.4 leo int unit;
381 1.4 leo
382 1.4 leo unit = ZS_UNIT(dev);
383 1.4 leo zi = zscd.cd_devs[unit >> 1];
384 1.4 leo cs = &zi->zi_cs[unit & 1];
385 1.4 leo return(cs->cs_ttyp);
386 1.1 leo }
387 1.1 leo
388 1.1 leo /*
389 1.1 leo * ZS hardware interrupt. Scan all ZS channels. NB: we know here that
390 1.1 leo * channels are kept in (A,B) pairs.
391 1.1 leo *
392 1.1 leo * Do just a little, then get out; set a software interrupt if more
393 1.1 leo * work is needed.
394 1.1 leo *
395 1.1 leo * We deliberately ignore the vectoring Zilog gives us, and match up
396 1.1 leo * only the number of `reset interrupt under service' operations, not
397 1.1 leo * the order.
398 1.1 leo */
399 1.1 leo int
400 1.1 leo zshard(sr)
401 1.1 leo long sr;
402 1.1 leo {
403 1.1 leo register struct zs_chanstate *a;
404 1.1 leo #define b (a + 1)
405 1.1 leo register volatile struct zschan *zc;
406 1.1 leo register int rr3, intflags = 0, v, i;
407 1.1 leo
408 1.1 leo for(a = zslist; a != NULL; a = b->cs_next) {
409 1.1 leo rr3 = ZS_READ(a->cs_zc, 3);
410 1.1 leo if(rr3 & (ZSRR3_IP_A_RX|ZSRR3_IP_A_TX|ZSRR3_IP_A_STAT)) {
411 1.1 leo intflags |= 2;
412 1.1 leo zc = a->cs_zc;
413 1.1 leo i = a->cs_rbput;
414 1.1 leo if(rr3 & ZSRR3_IP_A_RX && (v = zsrint(a, zc)) != 0) {
415 1.1 leo a->cs_rbuf[i++ & ZLRB_RING_MASK] = v;
416 1.1 leo intflags |= 1;
417 1.1 leo }
418 1.1 leo if(rr3 & ZSRR3_IP_A_TX && (v = zsxint(a, zc)) != 0) {
419 1.1 leo a->cs_rbuf[i++ & ZLRB_RING_MASK] = v;
420 1.1 leo intflags |= 1;
421 1.1 leo }
422 1.1 leo if(rr3 & ZSRR3_IP_A_STAT && (v = zssint(a, zc)) != 0) {
423 1.1 leo a->cs_rbuf[i++ & ZLRB_RING_MASK] = v;
424 1.1 leo intflags |= 1;
425 1.1 leo }
426 1.1 leo a->cs_rbput = i;
427 1.1 leo }
428 1.1 leo if(rr3 & (ZSRR3_IP_B_RX|ZSRR3_IP_B_TX|ZSRR3_IP_B_STAT)) {
429 1.1 leo intflags |= 2;
430 1.1 leo zc = b->cs_zc;
431 1.1 leo i = b->cs_rbput;
432 1.1 leo if(rr3 & ZSRR3_IP_B_RX && (v = zsrint(b, zc)) != 0) {
433 1.1 leo b->cs_rbuf[i++ & ZLRB_RING_MASK] = v;
434 1.1 leo intflags |= 1;
435 1.1 leo }
436 1.1 leo if(rr3 & ZSRR3_IP_B_TX && (v = zsxint(b, zc)) != 0) {
437 1.1 leo b->cs_rbuf[i++ & ZLRB_RING_MASK] = v;
438 1.1 leo intflags |= 1;
439 1.1 leo }
440 1.1 leo if(rr3 & ZSRR3_IP_B_STAT && (v = zssint(b, zc)) != 0) {
441 1.1 leo b->cs_rbuf[i++ & ZLRB_RING_MASK] = v;
442 1.1 leo intflags |= 1;
443 1.1 leo }
444 1.1 leo b->cs_rbput = i;
445 1.1 leo }
446 1.1 leo }
447 1.1 leo #undef b
448 1.1 leo
449 1.1 leo if(intflags & 1) {
450 1.1 leo if(BASEPRI(sr)) {
451 1.1 leo spl1();
452 1.1 leo zsshortcuts++;
453 1.1 leo return(zssoft(sr));
454 1.1 leo }
455 1.1 leo else add_sicallback(zssoft, 0, 0);
456 1.1 leo }
457 1.1 leo return(intflags & 2);
458 1.1 leo }
459 1.1 leo
460 1.1 leo static int
461 1.1 leo zsrint(cs, zc)
462 1.1 leo register struct zs_chanstate *cs;
463 1.1 leo register volatile struct zschan *zc;
464 1.1 leo {
465 1.1 leo register int c = zc->zc_data;
466 1.1 leo
467 1.1 leo /* compose receive character and status */
468 1.1 leo c <<= 8;
469 1.1 leo c |= ZS_READ(zc, 1);
470 1.1 leo
471 1.1 leo /* clear receive error & interrupt condition */
472 1.1 leo zc->zc_csr = ZSWR0_RESET_ERRORS;
473 1.1 leo zc->zc_csr = ZSWR0_CLR_INTR;
474 1.1 leo
475 1.1 leo return(ZRING_MAKE(ZRING_RINT, c));
476 1.1 leo }
477 1.1 leo
478 1.1 leo static int
479 1.1 leo zsxint(cs, zc)
480 1.1 leo register struct zs_chanstate *cs;
481 1.1 leo register volatile struct zschan *zc;
482 1.1 leo {
483 1.1 leo register int i = cs->cs_tbc;
484 1.1 leo
485 1.1 leo if(i == 0) {
486 1.1 leo zc->zc_csr = ZSWR0_RESET_TXINT;
487 1.1 leo zc->zc_csr = ZSWR0_CLR_INTR;
488 1.1 leo return(ZRING_MAKE(ZRING_XINT, 0));
489 1.1 leo }
490 1.1 leo cs->cs_tbc = i - 1;
491 1.1 leo zc->zc_data = *cs->cs_tba++;
492 1.1 leo zc->zc_csr = ZSWR0_CLR_INTR;
493 1.1 leo return (0);
494 1.1 leo }
495 1.1 leo
496 1.1 leo static int
497 1.1 leo zssint(cs, zc)
498 1.1 leo register struct zs_chanstate *cs;
499 1.1 leo register volatile struct zschan *zc;
500 1.1 leo {
501 1.1 leo register int rr0;
502 1.1 leo
503 1.1 leo rr0 = zc->zc_csr;
504 1.1 leo zc->zc_csr = ZSWR0_RESET_STATUS;
505 1.1 leo zc->zc_csr = ZSWR0_CLR_INTR;
506 1.1 leo /*
507 1.1 leo * The chip's hardware flow control is, as noted in zsreg.h,
508 1.1 leo * busted---if the DCD line goes low the chip shuts off the
509 1.1 leo * receiver (!). If we want hardware CTS flow control but do
510 1.1 leo * not have it, and carrier is now on, turn HFC on; if we have
511 1.1 leo * HFC now but carrier has gone low, turn it off.
512 1.1 leo */
513 1.1 leo if(rr0 & ZSRR0_DCD) {
514 1.1 leo if(cs->cs_ttyp->t_cflag & CCTS_OFLOW &&
515 1.1 leo (cs->cs_creg[3] & ZSWR3_HFC) == 0) {
516 1.1 leo cs->cs_creg[3] |= ZSWR3_HFC;
517 1.1 leo ZS_WRITE(zc, 3, cs->cs_creg[3]);
518 1.1 leo }
519 1.1 leo }
520 1.1 leo else {
521 1.1 leo if (cs->cs_creg[3] & ZSWR3_HFC) {
522 1.1 leo cs->cs_creg[3] &= ~ZSWR3_HFC;
523 1.1 leo ZS_WRITE(zc, 3, cs->cs_creg[3]);
524 1.1 leo }
525 1.1 leo }
526 1.1 leo return(ZRING_MAKE(ZRING_SINT, rr0));
527 1.1 leo }
528 1.1 leo
529 1.1 leo /*
530 1.1 leo * Print out a ring or fifo overrun error message.
531 1.1 leo */
532 1.1 leo static void
533 1.1 leo zsoverrun(unit, ptime, what)
534 1.1 leo int unit;
535 1.1 leo long *ptime;
536 1.1 leo char *what;
537 1.1 leo {
538 1.1 leo
539 1.1 leo if(*ptime != time.tv_sec) {
540 1.1 leo *ptime = time.tv_sec;
541 1.1 leo log(LOG_WARNING, "zs%d%c: %s overrun\n", unit >> 1,
542 1.1 leo (unit & 1) + 'a', what);
543 1.1 leo }
544 1.1 leo }
545 1.1 leo
546 1.1 leo /*
547 1.1 leo * ZS software interrupt. Scan all channels for deferred interrupts.
548 1.1 leo */
549 1.1 leo int
550 1.1 leo zssoft(sr)
551 1.1 leo long sr;
552 1.1 leo {
553 1.1 leo register struct zs_chanstate *cs;
554 1.1 leo register volatile struct zschan *zc;
555 1.1 leo register struct linesw *line;
556 1.1 leo register struct tty *tp;
557 1.1 leo register int get, n, c, cc, unit, s;
558 1.1 leo int retval = 0;
559 1.1 leo
560 1.1 leo s = spltty();
561 1.1 leo for(cs = zslist; cs != NULL; cs = cs->cs_next) {
562 1.1 leo get = cs->cs_rbget;
563 1.1 leo again:
564 1.1 leo n = cs->cs_rbput; /* atomic */
565 1.1 leo if(get == n) /* nothing more on this line */
566 1.1 leo continue;
567 1.1 leo retval = 1;
568 1.1 leo unit = cs->cs_unit; /* set up to handle interrupts */
569 1.1 leo zc = cs->cs_zc;
570 1.1 leo tp = cs->cs_ttyp;
571 1.1 leo line = &linesw[tp->t_line];
572 1.1 leo /*
573 1.1 leo * Compute the number of interrupts in the receive ring.
574 1.1 leo * If the count is overlarge, we lost some events, and
575 1.1 leo * must advance to the first valid one. It may get
576 1.1 leo * overwritten if more data are arriving, but this is
577 1.1 leo * too expensive to check and gains nothing (we already
578 1.1 leo * lost out; all we can do at this point is trade one
579 1.1 leo * kind of loss for another).
580 1.1 leo */
581 1.1 leo n -= get;
582 1.1 leo if(n > ZLRB_RING_SIZE) {
583 1.1 leo zsoverrun(unit, &cs->cs_rotime, "ring");
584 1.1 leo get += n - ZLRB_RING_SIZE;
585 1.1 leo n = ZLRB_RING_SIZE;
586 1.1 leo }
587 1.1 leo while(--n >= 0) {
588 1.1 leo /* race to keep ahead of incoming interrupts */
589 1.1 leo c = cs->cs_rbuf[get++ & ZLRB_RING_MASK];
590 1.1 leo switch (ZRING_TYPE(c)) {
591 1.1 leo
592 1.1 leo case ZRING_RINT:
593 1.1 leo c = ZRING_VALUE(c);
594 1.1 leo if(c & ZSRR1_DO)
595 1.1 leo zsoverrun(unit, &cs->cs_fotime, "fifo");
596 1.1 leo cc = c >> 8;
597 1.1 leo if(c & ZSRR1_FE)
598 1.1 leo cc |= TTY_FE;
599 1.1 leo if(c & ZSRR1_PE)
600 1.1 leo cc |= TTY_PE;
601 1.1 leo line->l_rint(cc, tp);
602 1.1 leo break;
603 1.1 leo
604 1.1 leo case ZRING_XINT:
605 1.1 leo /*
606 1.1 leo * Transmit done: change registers and resume,
607 1.1 leo * or clear BUSY.
608 1.1 leo */
609 1.1 leo if(cs->cs_heldchange) {
610 1.1 leo int sps;
611 1.1 leo
612 1.1 leo sps = splzs();
613 1.1 leo c = zc->zc_csr;
614 1.1 leo if((c & ZSRR0_DCD) == 0)
615 1.1 leo cs->cs_preg[3] &= ~ZSWR3_HFC;
616 1.1 leo bcopy((caddr_t)cs->cs_preg,
617 1.1 leo (caddr_t)cs->cs_creg, 16);
618 1.1 leo zs_loadchannelregs(zc, cs->cs_creg);
619 1.1 leo splx(sps);
620 1.1 leo cs->cs_heldchange = 0;
621 1.1 leo if(cs->cs_heldtbc
622 1.1 leo && (tp->t_state & TS_TTSTOP) == 0) {
623 1.1 leo cs->cs_tbc = cs->cs_heldtbc - 1;
624 1.1 leo zc->zc_data = *cs->cs_tba++;
625 1.1 leo goto again;
626 1.1 leo }
627 1.1 leo }
628 1.1 leo tp->t_state &= ~TS_BUSY;
629 1.1 leo if(tp->t_state & TS_FLUSH)
630 1.1 leo tp->t_state &= ~TS_FLUSH;
631 1.1 leo else ndflush(&tp->t_outq,cs->cs_tba
632 1.1 leo - (caddr_t)tp->t_outq.c_cf);
633 1.1 leo line->l_start(tp);
634 1.1 leo break;
635 1.1 leo
636 1.1 leo case ZRING_SINT:
637 1.1 leo /*
638 1.1 leo * Status line change. HFC bit is run in
639 1.1 leo * hardware interrupt, to avoid locking
640 1.1 leo * at splzs here.
641 1.1 leo */
642 1.1 leo c = ZRING_VALUE(c);
643 1.1 leo if((c ^ cs->cs_rr0) & ZSRR0_DCD) {
644 1.1 leo cc = (c & ZSRR0_DCD) != 0;
645 1.1 leo if(line->l_modem(tp, cc) == 0)
646 1.1 leo zs_modem(cs, ZSWR5_RTS|ZSWR5_DTR,
647 1.1 leo cc ? DMBIS : DMBIC);
648 1.1 leo }
649 1.1 leo cs->cs_rr0 = c;
650 1.1 leo break;
651 1.1 leo
652 1.1 leo default:
653 1.1 leo log(LOG_ERR, "zs%d%c: bad ZRING_TYPE (%x)\n",
654 1.1 leo unit >> 1, (unit & 1) + 'a', c);
655 1.1 leo break;
656 1.1 leo }
657 1.1 leo }
658 1.1 leo cs->cs_rbget = get;
659 1.1 leo goto again;
660 1.1 leo }
661 1.1 leo splx(s);
662 1.1 leo return (retval);
663 1.1 leo }
664 1.1 leo
665 1.1 leo int
666 1.1 leo zsioctl(dev, cmd, data, flag, p)
667 1.1 leo dev_t dev;
668 1.1 leo u_long cmd;
669 1.1 leo caddr_t data;
670 1.1 leo int flag;
671 1.1 leo struct proc *p;
672 1.1 leo {
673 1.1 leo int unit = ZS_UNIT(dev);
674 1.1 leo struct zs_softc *zi = zscd.cd_devs[unit >> 1];
675 1.1 leo register struct tty *tp = zi->zi_cs[unit & 1].cs_ttyp;
676 1.1 leo register int error, s;
677 1.1 leo register struct zs_chanstate *cs = &zi->zi_cs[unit & 1];
678 1.1 leo
679 1.1 leo error = linesw[tp->t_line].l_ioctl(tp, cmd, data, flag, p);
680 1.1 leo if(error >= 0)
681 1.1 leo return(error);
682 1.1 leo error = ttioctl(tp, cmd, data, flag, p);
683 1.1 leo if(error >= 0)
684 1.1 leo return (error);
685 1.1 leo
686 1.1 leo switch (cmd) {
687 1.1 leo case TIOCSBRK:
688 1.1 leo s = splzs();
689 1.1 leo cs->cs_preg[5] |= ZSWR5_BREAK;
690 1.1 leo cs->cs_creg[5] |= ZSWR5_BREAK;
691 1.1 leo ZS_WRITE(cs->cs_zc, 5, cs->cs_creg[5]);
692 1.1 leo splx(s);
693 1.1 leo break;
694 1.1 leo case TIOCCBRK:
695 1.1 leo s = splzs();
696 1.1 leo cs->cs_preg[5] &= ~ZSWR5_BREAK;
697 1.1 leo cs->cs_creg[5] &= ~ZSWR5_BREAK;
698 1.1 leo ZS_WRITE(cs->cs_zc, 5, cs->cs_creg[5]);
699 1.1 leo splx(s);
700 1.1 leo break;
701 1.1 leo case TIOCGFLAGS: {
702 1.1 leo int bits = 0;
703 1.1 leo
704 1.1 leo if(cs->cs_softcar)
705 1.1 leo bits |= TIOCFLAG_SOFTCAR;
706 1.1 leo if(cs->cs_creg[15] & ZSWR15_DCD_IE)
707 1.1 leo bits |= TIOCFLAG_CLOCAL;
708 1.1 leo if(cs->cs_creg[3] & ZSWR3_HFC)
709 1.1 leo bits |= TIOCFLAG_CRTSCTS;
710 1.1 leo *(int *)data = bits;
711 1.1 leo break;
712 1.1 leo }
713 1.1 leo case TIOCSFLAGS: {
714 1.1 leo int userbits, driverbits = 0;
715 1.1 leo
716 1.3 mycroft error = suser(p->p_ucred, &p->p_acflag);
717 1.1 leo if(error != 0)
718 1.1 leo return (EPERM);
719 1.1 leo
720 1.1 leo userbits = *(int *)data;
721 1.1 leo
722 1.1 leo /*
723 1.1 leo * can have `local' or `softcar', and `rtscts' or `mdmbuf'
724 1.1 leo # defaulting to software flow control.
725 1.1 leo */
726 1.1 leo if(userbits & TIOCFLAG_SOFTCAR && userbits & TIOCFLAG_CLOCAL)
727 1.1 leo return(EINVAL);
728 1.1 leo if(userbits & TIOCFLAG_MDMBUF) /* don't support this (yet?) */
729 1.1 leo return(ENXIO);
730 1.1 leo
731 1.1 leo s = splzs();
732 1.1 leo if((userbits & TIOCFLAG_SOFTCAR)) {
733 1.1 leo cs->cs_softcar = 1; /* turn on softcar */
734 1.1 leo cs->cs_preg[15] &= ~ZSWR15_DCD_IE; /* turn off dcd */
735 1.1 leo cs->cs_creg[15] &= ~ZSWR15_DCD_IE;
736 1.1 leo ZS_WRITE(cs->cs_zc, 15, cs->cs_creg[15]);
737 1.1 leo }
738 1.1 leo else if(userbits & TIOCFLAG_CLOCAL) {
739 1.1 leo cs->cs_softcar = 0; /* turn off softcar */
740 1.1 leo cs->cs_preg[15] |= ZSWR15_DCD_IE; /* turn on dcd */
741 1.1 leo cs->cs_creg[15] |= ZSWR15_DCD_IE;
742 1.1 leo ZS_WRITE(cs->cs_zc, 15, cs->cs_creg[15]);
743 1.1 leo tp->t_termios.c_cflag |= CLOCAL;
744 1.1 leo }
745 1.1 leo if(userbits & TIOCFLAG_CRTSCTS) {
746 1.1 leo cs->cs_preg[15] |= ZSWR15_CTS_IE;
747 1.1 leo cs->cs_creg[15] |= ZSWR15_CTS_IE;
748 1.1 leo ZS_WRITE(cs->cs_zc, 15, cs->cs_creg[15]);
749 1.1 leo cs->cs_preg[3] |= ZSWR3_HFC;
750 1.1 leo cs->cs_creg[3] |= ZSWR3_HFC;
751 1.1 leo ZS_WRITE(cs->cs_zc, 3, cs->cs_creg[3]);
752 1.1 leo tp->t_termios.c_cflag |= CRTSCTS;
753 1.1 leo }
754 1.1 leo else {
755 1.1 leo /* no mdmbuf, so we must want software flow control */
756 1.1 leo cs->cs_preg[15] &= ~ZSWR15_CTS_IE;
757 1.1 leo cs->cs_creg[15] &= ~ZSWR15_CTS_IE;
758 1.1 leo ZS_WRITE(cs->cs_zc, 15, cs->cs_creg[15]);
759 1.1 leo cs->cs_preg[3] &= ~ZSWR3_HFC;
760 1.1 leo cs->cs_creg[3] &= ~ZSWR3_HFC;
761 1.1 leo ZS_WRITE(cs->cs_zc, 3, cs->cs_creg[3]);
762 1.1 leo tp->t_termios.c_cflag &= ~CRTSCTS;
763 1.1 leo }
764 1.1 leo splx(s);
765 1.1 leo break;
766 1.1 leo }
767 1.1 leo case TIOCSDTR:
768 1.1 leo zs_modem(cs, ZSWR5_DTR, DMBIS);
769 1.1 leo break;
770 1.1 leo case TIOCCDTR:
771 1.1 leo zs_modem(cs, ZSWR5_DTR, DMBIC);
772 1.1 leo break;
773 1.1 leo case TIOCMGET:
774 1.1 leo zs_modem(cs, 0, DMGET);
775 1.1 leo break;
776 1.1 leo case TIOCMSET:
777 1.1 leo case TIOCMBIS:
778 1.1 leo case TIOCMBIC:
779 1.1 leo default:
780 1.1 leo return (ENOTTY);
781 1.1 leo }
782 1.1 leo return (0);
783 1.1 leo }
784 1.1 leo
785 1.1 leo /*
786 1.1 leo * Start or restart transmission.
787 1.1 leo */
788 1.1 leo static void
789 1.1 leo zsstart(tp)
790 1.1 leo register struct tty *tp;
791 1.1 leo {
792 1.1 leo register struct zs_chanstate *cs;
793 1.1 leo register int s, nch;
794 1.1 leo int unit = ZS_UNIT(tp->t_dev);
795 1.1 leo struct zs_softc *zi = zscd.cd_devs[unit >> 1];
796 1.1 leo
797 1.1 leo cs = &zi->zi_cs[unit & 1];
798 1.1 leo s = spltty();
799 1.1 leo
800 1.1 leo /*
801 1.1 leo * If currently active or delaying, no need to do anything.
802 1.1 leo */
803 1.1 leo if(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))
804 1.1 leo goto out;
805 1.1 leo
806 1.1 leo /*
807 1.1 leo * If there are sleepers, and output has drained below low
808 1.1 leo * water mark, awaken.
809 1.1 leo */
810 1.1 leo if(tp->t_outq.c_cc <= tp->t_lowat) {
811 1.1 leo if(tp->t_state & TS_ASLEEP) {
812 1.1 leo tp->t_state &= ~TS_ASLEEP;
813 1.1 leo wakeup((caddr_t)&tp->t_outq);
814 1.1 leo }
815 1.1 leo selwakeup(&tp->t_wsel);
816 1.1 leo }
817 1.1 leo
818 1.1 leo nch = ndqb(&tp->t_outq, 0); /* XXX */
819 1.1 leo if(nch) {
820 1.1 leo register char *p = tp->t_outq.c_cf;
821 1.1 leo
822 1.1 leo /* mark busy, enable tx done interrupts, & send first byte */
823 1.1 leo tp->t_state |= TS_BUSY;
824 1.1 leo (void) splzs();
825 1.1 leo cs->cs_preg[1] |= ZSWR1_TIE;
826 1.1 leo cs->cs_creg[1] |= ZSWR1_TIE;
827 1.1 leo ZS_WRITE(cs->cs_zc, 1, cs->cs_creg[1]);
828 1.1 leo cs->cs_zc->zc_data = *p;
829 1.1 leo cs->cs_tba = p + 1;
830 1.1 leo cs->cs_tbc = nch - 1;
831 1.1 leo } else {
832 1.1 leo /*
833 1.1 leo * Nothing to send, turn off transmit done interrupts.
834 1.1 leo * This is useful if something is doing polled output.
835 1.1 leo */
836 1.1 leo (void) splzs();
837 1.1 leo cs->cs_preg[1] &= ~ZSWR1_TIE;
838 1.1 leo cs->cs_creg[1] &= ~ZSWR1_TIE;
839 1.1 leo ZS_WRITE(cs->cs_zc, 1, cs->cs_creg[1]);
840 1.1 leo }
841 1.1 leo out:
842 1.1 leo splx(s);
843 1.1 leo }
844 1.1 leo
845 1.1 leo /*
846 1.1 leo * Stop output, e.g., for ^S or output flush.
847 1.1 leo */
848 1.1 leo void
849 1.1 leo zsstop(tp, flag)
850 1.1 leo register struct tty *tp;
851 1.1 leo int flag;
852 1.1 leo {
853 1.1 leo register struct zs_chanstate *cs;
854 1.1 leo register int s, unit = ZS_UNIT(tp->t_dev);
855 1.1 leo struct zs_softc *zi = zscd.cd_devs[unit >> 1];
856 1.1 leo
857 1.1 leo cs = &zi->zi_cs[unit & 1];
858 1.1 leo s = splzs();
859 1.1 leo if(tp->t_state & TS_BUSY) {
860 1.1 leo /*
861 1.1 leo * Device is transmitting; must stop it.
862 1.1 leo */
863 1.1 leo cs->cs_tbc = 0;
864 1.1 leo if ((tp->t_state & TS_TTSTOP) == 0)
865 1.1 leo tp->t_state |= TS_FLUSH;
866 1.1 leo }
867 1.1 leo splx(s);
868 1.1 leo }
869 1.1 leo
870 1.1 leo /*
871 1.1 leo * Set ZS tty parameters from termios.
872 1.1 leo *
873 1.1 leo * This routine makes use of the fact that only registers
874 1.1 leo * 1, 3, 4, 5, 9, 10, 11, 12, 13, 14, and 15 are written.
875 1.1 leo */
876 1.1 leo static int
877 1.1 leo zsparam(tp, t)
878 1.1 leo register struct tty *tp;
879 1.1 leo register struct termios *t;
880 1.1 leo {
881 1.1 leo int unit = ZS_UNIT(tp->t_dev);
882 1.1 leo struct zs_softc *zi = zscd.cd_devs[unit >> 1];
883 1.1 leo register struct zs_chanstate *cs = &zi->zi_cs[unit & 1];
884 1.1 leo register int tmp, tmp5, cflag, s;
885 1.1 leo
886 1.1 leo tmp = t->c_ospeed;
887 1.1 leo if(tmp < 0 || (t->c_ispeed && t->c_ispeed != tmp))
888 1.1 leo return(EINVAL);
889 1.1 leo if(tmp == 0) {
890 1.1 leo /* stty 0 => drop DTR and RTS */
891 1.1 leo zs_modem(cs, 0, DMSET);
892 1.1 leo return(0);
893 1.1 leo }
894 1.1 leo tmp = BPS_TO_TCONST(PCLK / 16, tmp);
895 1.1 leo if(tmp < 2)
896 1.1 leo return(EINVAL);
897 1.1 leo
898 1.1 leo cflag = t->c_cflag;
899 1.1 leo tp->t_ispeed = tp->t_ospeed = TCONST_TO_BPS(PCLK / 16, tmp);
900 1.1 leo tp->t_cflag = cflag;
901 1.1 leo
902 1.1 leo /*
903 1.1 leo * Block interrupts so that state will not
904 1.1 leo * be altered until we are done setting it up.
905 1.1 leo */
906 1.1 leo s = splzs();
907 1.1 leo cs->cs_preg[12] = tmp;
908 1.1 leo cs->cs_preg[13] = tmp >> 8;
909 1.1 leo cs->cs_preg[1] = ZSWR1_RIE | ZSWR1_TIE | ZSWR1_SIE;
910 1.1 leo switch(cflag & CSIZE) {
911 1.1 leo case CS5:
912 1.1 leo tmp = ZSWR3_RX_5;
913 1.1 leo tmp5 = ZSWR5_TX_5;
914 1.1 leo break;
915 1.1 leo case CS6:
916 1.1 leo tmp = ZSWR3_RX_6;
917 1.1 leo tmp5 = ZSWR5_TX_6;
918 1.1 leo break;
919 1.1 leo case CS7:
920 1.1 leo tmp = ZSWR3_RX_7;
921 1.1 leo tmp5 = ZSWR5_TX_7;
922 1.1 leo break;
923 1.1 leo case CS8:
924 1.1 leo default:
925 1.1 leo tmp = ZSWR3_RX_8;
926 1.1 leo tmp5 = ZSWR5_TX_8;
927 1.1 leo break;
928 1.1 leo }
929 1.1 leo
930 1.1 leo /*
931 1.1 leo * Output hardware flow control on the chip is horrendous: if
932 1.1 leo * carrier detect drops, the receiver is disabled. Hence we
933 1.1 leo * can only do this when the carrier is on.
934 1.1 leo */
935 1.1 leo if(cflag & CCTS_OFLOW && cs->cs_zc->zc_csr & ZSRR0_DCD)
936 1.1 leo tmp |= ZSWR3_HFC | ZSWR3_RX_ENABLE;
937 1.1 leo else tmp |= ZSWR3_RX_ENABLE;
938 1.1 leo cs->cs_preg[3] = tmp;
939 1.1 leo cs->cs_preg[5] = tmp5 | ZSWR5_TX_ENABLE | ZSWR5_DTR | ZSWR5_RTS;
940 1.1 leo
941 1.1 leo tmp = ZSWR4_CLK_X16 | (cflag & CSTOPB ? ZSWR4_TWOSB : ZSWR4_ONESB);
942 1.1 leo if((cflag & PARODD) == 0)
943 1.1 leo tmp |= ZSWR4_EVENP;
944 1.1 leo if (cflag & PARENB)
945 1.1 leo tmp |= ZSWR4_PARENB;
946 1.1 leo cs->cs_preg[4] = tmp;
947 1.1 leo cs->cs_preg[9] = ZSWR9_MASTER_IE | ZSWR9_VECTOR_INCL_STAT;
948 1.1 leo cs->cs_preg[10] = ZSWR10_NRZ;
949 1.1 leo cs->cs_preg[11] = ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD;
950 1.1 leo cs->cs_preg[14] = ZSWR14_BAUD_FROM_PCLK | ZSWR14_BAUD_ENA;
951 1.1 leo cs->cs_preg[15] = ZSWR15_BREAK_IE | ZSWR15_DCD_IE;
952 1.1 leo
953 1.1 leo /*
954 1.1 leo * If nothing is being transmitted, set up new current values,
955 1.1 leo * else mark them as pending.
956 1.1 leo */
957 1.1 leo if(cs->cs_heldchange == 0) {
958 1.1 leo if (cs->cs_ttyp->t_state & TS_BUSY) {
959 1.1 leo cs->cs_heldtbc = cs->cs_tbc;
960 1.1 leo cs->cs_tbc = 0;
961 1.1 leo cs->cs_heldchange = 1;
962 1.1 leo }
963 1.1 leo else {
964 1.1 leo bcopy((caddr_t)cs->cs_preg, (caddr_t)cs->cs_creg, 16);
965 1.1 leo zs_loadchannelregs(cs->cs_zc, cs->cs_creg);
966 1.1 leo }
967 1.1 leo }
968 1.1 leo splx(s);
969 1.1 leo return (0);
970 1.1 leo }
971 1.1 leo
972 1.1 leo /*
973 1.1 leo * Raise or lower modem control (DTR/RTS) signals. If a character is
974 1.1 leo * in transmission, the change is deferred.
975 1.1 leo */
976 1.1 leo static int
977 1.1 leo zs_modem(cs, bits, how)
978 1.1 leo struct zs_chanstate *cs;
979 1.1 leo int bits, how;
980 1.1 leo {
981 1.1 leo int s, mbits;
982 1.1 leo
983 1.1 leo bits &= ZSWR5_DTR | ZSWR5_RTS;
984 1.1 leo
985 1.1 leo s = splzs();
986 1.1 leo mbits = cs->cs_preg[5] & (ZSWR5_DTR | ZSWR5_RTS);
987 1.1 leo
988 1.1 leo switch(how) {
989 1.1 leo case DMSET:
990 1.1 leo mbits = bits;
991 1.1 leo break;
992 1.1 leo case DMBIS:
993 1.1 leo mbits |= bits;
994 1.1 leo break;
995 1.1 leo case DMBIC:
996 1.1 leo mbits &= ~bits;
997 1.1 leo break;
998 1.1 leo case DMGET:
999 1.1 leo splx(s);
1000 1.1 leo return(mbits);
1001 1.1 leo }
1002 1.1 leo
1003 1.1 leo cs->cs_preg[5] = (cs->cs_preg[5] & ~(ZSWR5_DTR | ZSWR5_RTS)) | mbits;
1004 1.1 leo if(cs->cs_heldchange == 0) {
1005 1.1 leo if(cs->cs_ttyp->t_state & TS_BUSY) {
1006 1.1 leo cs->cs_heldtbc = cs->cs_tbc;
1007 1.1 leo cs->cs_tbc = 0;
1008 1.1 leo cs->cs_heldchange = 1;
1009 1.1 leo }
1010 1.1 leo else {
1011 1.1 leo ZS_WRITE(cs->cs_zc, 5, cs->cs_creg[5]);
1012 1.1 leo }
1013 1.1 leo }
1014 1.1 leo splx(s);
1015 1.1 leo return(0);
1016 1.1 leo }
1017 1.1 leo
1018 1.1 leo /*
1019 1.1 leo * Write the given register set to the given zs channel in the proper order.
1020 1.1 leo * The channel must not be transmitting at the time. The receiver will
1021 1.1 leo * be disabled for the time it takes to write all the registers.
1022 1.1 leo */
1023 1.1 leo static void
1024 1.1 leo zs_loadchannelregs(zc, reg)
1025 1.1 leo volatile struct zschan *zc;
1026 1.1 leo u_char *reg;
1027 1.1 leo {
1028 1.1 leo int i;
1029 1.1 leo
1030 1.1 leo zc->zc_csr = ZSM_RESET_ERR; /* reset error condition */
1031 1.1 leo i = zc->zc_data; /* drain fifo */
1032 1.1 leo i = zc->zc_data;
1033 1.1 leo i = zc->zc_data;
1034 1.1 leo ZS_WRITE(zc, 4, reg[4]);
1035 1.1 leo ZS_WRITE(zc, 10, reg[10]);
1036 1.1 leo ZS_WRITE(zc, 3, reg[3] & ~ZSWR3_RX_ENABLE);
1037 1.1 leo ZS_WRITE(zc, 5, reg[5] & ~ZSWR5_TX_ENABLE);
1038 1.1 leo ZS_WRITE(zc, 1, reg[1]);
1039 1.1 leo ZS_WRITE(zc, 9, reg[9]);
1040 1.1 leo ZS_WRITE(zc, 11, reg[11]);
1041 1.1 leo ZS_WRITE(zc, 12, reg[12]);
1042 1.1 leo ZS_WRITE(zc, 13, reg[13]);
1043 1.1 leo ZS_WRITE(zc, 14, reg[14]);
1044 1.1 leo ZS_WRITE(zc, 15, reg[15]);
1045 1.1 leo ZS_WRITE(zc, 3, reg[3]);
1046 1.1 leo ZS_WRITE(zc, 5, reg[5]);
1047 1.1 leo }
1048 1.1 leo #endif /* NZS > 1 */
1049