dz.c revision 1.1.2.4 1 1.1.2.4 nathanw /* $NetBSD: dz.c,v 1.1.2.4 2002/09/17 21:19:30 nathanw Exp $ */
2 1.1.2.2 nathanw /*
3 1.1.2.2 nathanw * Copyright (c) 1996 Ken C. Wellsch. All rights reserved.
4 1.1.2.2 nathanw * Copyright (c) 1992, 1993
5 1.1.2.2 nathanw * The Regents of the University of California. All rights reserved.
6 1.1.2.2 nathanw *
7 1.1.2.2 nathanw * This code is derived from software contributed to Berkeley by
8 1.1.2.2 nathanw * Ralph Campbell and Rick Macklem.
9 1.1.2.2 nathanw *
10 1.1.2.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.1.2.2 nathanw * modification, are permitted provided that the following conditions
12 1.1.2.2 nathanw * are met:
13 1.1.2.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.1.2.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.1.2.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.2.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.1.2.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.1.2.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.1.2.2 nathanw * must display the following acknowledgement:
20 1.1.2.2 nathanw * This product includes software developed by the University of
21 1.1.2.2 nathanw * California, Berkeley and its contributors.
22 1.1.2.2 nathanw * 4. Neither the name of the University nor the names of its contributors
23 1.1.2.2 nathanw * may be used to endorse or promote products derived from this software
24 1.1.2.2 nathanw * without specific prior written permission.
25 1.1.2.2 nathanw *
26 1.1.2.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 1.1.2.2 nathanw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 1.1.2.2 nathanw * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 1.1.2.2 nathanw * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 1.1.2.2 nathanw * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 1.1.2.2 nathanw * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 1.1.2.2 nathanw * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 1.1.2.2 nathanw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 1.1.2.2 nathanw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 1.1.2.2 nathanw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 1.1.2.2 nathanw * SUCH DAMAGE.
37 1.1.2.2 nathanw */
38 1.1.2.2 nathanw
39 1.1.2.2 nathanw #include <sys/cdefs.h>
40 1.1.2.4 nathanw __KERNEL_RCSID(0, "$NetBSD: dz.c,v 1.1.2.4 2002/09/17 21:19:30 nathanw Exp $");
41 1.1.2.2 nathanw
42 1.1.2.2 nathanw #include "opt_ddb.h"
43 1.1.2.2 nathanw
44 1.1.2.2 nathanw #include <sys/param.h>
45 1.1.2.2 nathanw #include <sys/systm.h>
46 1.1.2.2 nathanw #include <sys/callout.h>
47 1.1.2.2 nathanw #include <sys/ioctl.h>
48 1.1.2.2 nathanw #include <sys/tty.h>
49 1.1.2.2 nathanw #include <sys/proc.h>
50 1.1.2.2 nathanw #include <sys/map.h>
51 1.1.2.2 nathanw #include <sys/buf.h>
52 1.1.2.2 nathanw #include <sys/conf.h>
53 1.1.2.2 nathanw #include <sys/file.h>
54 1.1.2.2 nathanw #include <sys/uio.h>
55 1.1.2.2 nathanw #include <sys/kernel.h>
56 1.1.2.2 nathanw #include <sys/syslog.h>
57 1.1.2.2 nathanw #include <sys/device.h>
58 1.1.2.2 nathanw
59 1.1.2.2 nathanw #include <machine/bus.h>
60 1.1.2.2 nathanw
61 1.1.2.2 nathanw #include <dev/dec/dzreg.h>
62 1.1.2.2 nathanw #include <dev/dec/dzvar.h>
63 1.1.2.2 nathanw
64 1.1.2.2 nathanw #define DZ_READ_BYTE(adr) \
65 1.1.2.2 nathanw bus_space_read_1(sc->sc_iot, sc->sc_ioh, sc->sc_dr.adr)
66 1.1.2.2 nathanw #define DZ_READ_WORD(adr) \
67 1.1.2.2 nathanw bus_space_read_2(sc->sc_iot, sc->sc_ioh, sc->sc_dr.adr)
68 1.1.2.2 nathanw #define DZ_WRITE_BYTE(adr, val) \
69 1.1.2.2 nathanw bus_space_write_1(sc->sc_iot, sc->sc_ioh, sc->sc_dr.adr, val)
70 1.1.2.2 nathanw #define DZ_WRITE_WORD(adr, val) \
71 1.1.2.2 nathanw bus_space_write_2(sc->sc_iot, sc->sc_ioh, sc->sc_dr.adr, val)
72 1.1.2.2 nathanw
73 1.1.2.2 nathanw #include "ioconf.h"
74 1.1.2.2 nathanw
75 1.1.2.2 nathanw /* A DZ-11 has 8 ports while a DZV/DZQ-11 has only 4. We use 8 by default */
76 1.1.2.2 nathanw
77 1.1.2.2 nathanw #define NDZLINE 8
78 1.1.2.2 nathanw
79 1.1.2.2 nathanw #define DZ_C2I(c) ((c)<<3) /* convert controller # to index */
80 1.1.2.2 nathanw #define DZ_I2C(c) ((c)>>3) /* convert minor to controller # */
81 1.1.2.2 nathanw #define DZ_PORT(u) ((u)&07) /* extract the port # */
82 1.1.2.2 nathanw
83 1.1.2.2 nathanw /* Flags used to monitor modem bits, make them understood outside driver */
84 1.1.2.2 nathanw
85 1.1.2.2 nathanw #define DML_DTR TIOCM_DTR
86 1.1.2.2 nathanw #define DML_DCD TIOCM_CD
87 1.1.2.2 nathanw #define DML_RI TIOCM_RI
88 1.1.2.2 nathanw #define DML_BRK 0100000 /* no equivalent, we will mask */
89 1.1.2.2 nathanw
90 1.1.2.2 nathanw static struct speedtab dzspeedtab[] =
91 1.1.2.2 nathanw {
92 1.1.2.2 nathanw { 0, 0 },
93 1.1.2.2 nathanw { 50, DZ_LPR_B50 },
94 1.1.2.2 nathanw { 75, DZ_LPR_B75 },
95 1.1.2.2 nathanw { 110, DZ_LPR_B110 },
96 1.1.2.2 nathanw { 134, DZ_LPR_B134 },
97 1.1.2.2 nathanw { 150, DZ_LPR_B150 },
98 1.1.2.2 nathanw { 300, DZ_LPR_B300 },
99 1.1.2.2 nathanw { 600, DZ_LPR_B600 },
100 1.1.2.2 nathanw { 1200, DZ_LPR_B1200 },
101 1.1.2.2 nathanw { 1800, DZ_LPR_B1800 },
102 1.1.2.2 nathanw { 2000, DZ_LPR_B2000 },
103 1.1.2.2 nathanw { 2400, DZ_LPR_B2400 },
104 1.1.2.2 nathanw { 3600, DZ_LPR_B3600 },
105 1.1.2.2 nathanw { 4800, DZ_LPR_B4800 },
106 1.1.2.2 nathanw { 7200, DZ_LPR_B7200 },
107 1.1.2.2 nathanw { 9600, DZ_LPR_B9600 },
108 1.1.2.2 nathanw { 19200, DZ_LPR_B19200 },
109 1.1.2.2 nathanw { -1, -1 }
110 1.1.2.2 nathanw };
111 1.1.2.2 nathanw
112 1.1.2.2 nathanw static void dzstart(struct tty *);
113 1.1.2.2 nathanw static int dzparam(struct tty *, struct termios *);
114 1.1.2.2 nathanw static unsigned dzmctl(struct dz_softc *, int, int, int);
115 1.1.2.2 nathanw static void dzscan(void *);
116 1.1.2.4 nathanw
117 1.1.2.4 nathanw dev_type_open(dzopen);
118 1.1.2.4 nathanw dev_type_close(dzclose);
119 1.1.2.4 nathanw dev_type_read(dzread);
120 1.1.2.4 nathanw dev_type_write(dzwrite);
121 1.1.2.4 nathanw dev_type_ioctl(dzioctl);
122 1.1.2.4 nathanw dev_type_stop(dzstop);
123 1.1.2.4 nathanw dev_type_tty(dztty);
124 1.1.2.4 nathanw dev_type_poll(dzpoll);
125 1.1.2.4 nathanw
126 1.1.2.4 nathanw const struct cdevsw dz_cdevsw = {
127 1.1.2.4 nathanw dzopen, dzclose, dzread, dzwrite, dzioctl,
128 1.1.2.4 nathanw dzstop, dztty, dzpoll, nommap, D_TTY
129 1.1.2.4 nathanw };
130 1.1.2.2 nathanw
131 1.1.2.2 nathanw /*
132 1.1.2.2 nathanw * The DZ series doesn't interrupt on carrier transitions,
133 1.1.2.2 nathanw * so we have to use a timer to watch it.
134 1.1.2.2 nathanw */
135 1.1.2.2 nathanw int dz_timer; /* true if timer started */
136 1.1.2.2 nathanw struct callout dzscan_ch;
137 1.1.2.2 nathanw
138 1.1.2.2 nathanw #define DZ_DZ 8 /* Unibus DZ-11 board linecount */
139 1.1.2.2 nathanw #define DZ_DZV 4 /* Q-bus DZV-11 or DZQ-11 */
140 1.1.2.2 nathanw
141 1.1.2.2 nathanw void
142 1.1.2.2 nathanw dzattach(struct dz_softc *sc, struct evcnt *parent_evcnt)
143 1.1.2.2 nathanw {
144 1.1.2.2 nathanw int n;
145 1.1.2.2 nathanw
146 1.1.2.2 nathanw sc->sc_rxint = sc->sc_brk = 0;
147 1.1.2.2 nathanw
148 1.1.2.2 nathanw sc->sc_dr.dr_tcrw = sc->sc_dr.dr_tcr;
149 1.1.2.2 nathanw DZ_WRITE_WORD(dr_csr, DZ_CSR_MSE | DZ_CSR_RXIE | DZ_CSR_TXIE);
150 1.1.2.2 nathanw DZ_WRITE_BYTE(dr_dtr, 0);
151 1.1.2.2 nathanw DZ_WRITE_BYTE(dr_break, 0);
152 1.1.2.2 nathanw
153 1.1.2.2 nathanw /* Initialize our softc structure. Should be done in open? */
154 1.1.2.2 nathanw
155 1.1.2.2 nathanw for (n = 0; n < sc->sc_type; n++)
156 1.1.2.2 nathanw sc->sc_dz[n].dz_tty = ttymalloc();
157 1.1.2.2 nathanw
158 1.1.2.2 nathanw evcnt_attach_dynamic(&sc->sc_rintrcnt, EVCNT_TYPE_INTR, parent_evcnt,
159 1.1.2.2 nathanw sc->sc_dev.dv_xname, "rintr");
160 1.1.2.2 nathanw evcnt_attach_dynamic(&sc->sc_tintrcnt, EVCNT_TYPE_INTR, parent_evcnt,
161 1.1.2.2 nathanw sc->sc_dev.dv_xname, "tintr");
162 1.1.2.2 nathanw
163 1.1.2.2 nathanw /* Alas no interrupt on modem bit changes, so we manually scan */
164 1.1.2.2 nathanw
165 1.1.2.2 nathanw if (dz_timer == 0) {
166 1.1.2.2 nathanw dz_timer = 1;
167 1.1.2.2 nathanw callout_init(&dzscan_ch);
168 1.1.2.2 nathanw callout_reset(&dzscan_ch, hz, dzscan, NULL);
169 1.1.2.2 nathanw }
170 1.1.2.2 nathanw printf("\n");
171 1.1.2.2 nathanw return;
172 1.1.2.2 nathanw }
173 1.1.2.2 nathanw
174 1.1.2.2 nathanw /* Receiver Interrupt */
175 1.1.2.2 nathanw
176 1.1.2.2 nathanw void
177 1.1.2.2 nathanw dzrint(void *arg)
178 1.1.2.2 nathanw {
179 1.1.2.2 nathanw struct dz_softc *sc = arg;
180 1.1.2.2 nathanw struct tty *tp;
181 1.1.2.2 nathanw int cc, line;
182 1.1.2.2 nathanw unsigned c;
183 1.1.2.2 nathanw int overrun = 0;
184 1.1.2.2 nathanw
185 1.1.2.2 nathanw sc->sc_rxint++;
186 1.1.2.2 nathanw
187 1.1.2.2 nathanw while ((c = DZ_READ_WORD(dr_rbuf)) & DZ_RBUF_DATA_VALID) {
188 1.1.2.2 nathanw cc = c & 0xFF;
189 1.1.2.2 nathanw line = DZ_PORT(c>>8);
190 1.1.2.2 nathanw tp = sc->sc_dz[line].dz_tty;
191 1.1.2.2 nathanw
192 1.1.2.2 nathanw /* Must be caught early */
193 1.1.2.2 nathanw if (sc->sc_dz[line].dz_catch &&
194 1.1.2.2 nathanw (*sc->sc_dz[line].dz_catch)(sc->sc_dz[line].dz_private, cc))
195 1.1.2.2 nathanw continue;
196 1.1.2.2 nathanw
197 1.1.2.2 nathanw if (!(tp->t_state & TS_ISOPEN)) {
198 1.1.2.2 nathanw wakeup((caddr_t)&tp->t_rawq);
199 1.1.2.2 nathanw continue;
200 1.1.2.2 nathanw }
201 1.1.2.2 nathanw
202 1.1.2.2 nathanw if ((c & DZ_RBUF_OVERRUN_ERR) && overrun == 0) {
203 1.1.2.2 nathanw log(LOG_WARNING, "%s: silo overflow, line %d\n",
204 1.1.2.2 nathanw sc->sc_dev.dv_xname, line);
205 1.1.2.2 nathanw overrun = 1;
206 1.1.2.2 nathanw }
207 1.1.2.2 nathanw
208 1.1.2.2 nathanw /* A BREAK key will appear as a NULL with a framing error */
209 1.1.2.2 nathanw if (c & DZ_RBUF_FRAMING_ERR)
210 1.1.2.2 nathanw cc |= TTY_FE;
211 1.1.2.2 nathanw if (c & DZ_RBUF_PARITY_ERR)
212 1.1.2.2 nathanw cc |= TTY_PE;
213 1.1.2.2 nathanw
214 1.1.2.2 nathanw (*tp->t_linesw->l_rint)(cc, tp);
215 1.1.2.2 nathanw }
216 1.1.2.2 nathanw }
217 1.1.2.2 nathanw
218 1.1.2.2 nathanw /* Transmitter Interrupt */
219 1.1.2.2 nathanw
220 1.1.2.2 nathanw void
221 1.1.2.2 nathanw dzxint(void *arg)
222 1.1.2.2 nathanw {
223 1.1.2.2 nathanw struct dz_softc *sc = arg;
224 1.1.2.2 nathanw struct tty *tp;
225 1.1.2.2 nathanw struct clist *cl;
226 1.1.2.2 nathanw int line, ch, csr;
227 1.1.2.2 nathanw u_char tcr;
228 1.1.2.2 nathanw
229 1.1.2.2 nathanw /*
230 1.1.2.2 nathanw * Switch to POLLED mode.
231 1.1.2.2 nathanw * Some simple measurements indicated that even on
232 1.1.2.2 nathanw * one port, by freeing the scanner in the controller
233 1.1.2.2 nathanw * by either providing a character or turning off
234 1.1.2.2 nathanw * the port when output is complete, the transmitter
235 1.1.2.2 nathanw * was ready to accept more output when polled again.
236 1.1.2.2 nathanw * With just two ports running the game "worms,"
237 1.1.2.2 nathanw * almost every interrupt serviced both transmitters!
238 1.1.2.2 nathanw * Each UART is double buffered, so if the scanner
239 1.1.2.2 nathanw * is quick enough and timing works out, we can even
240 1.1.2.2 nathanw * feed the same port twice.
241 1.1.2.2 nathanw *
242 1.1.2.2 nathanw * Ragge 980517:
243 1.1.2.2 nathanw * Do not need to turn off interrupts, already at interrupt level.
244 1.1.2.2 nathanw * Remove the pdma stuff; no great need of it right now.
245 1.1.2.2 nathanw */
246 1.1.2.2 nathanw
247 1.1.2.2 nathanw while (((csr = DZ_READ_WORD(dr_csr)) & DZ_CSR_TX_READY) != 0) {
248 1.1.2.2 nathanw
249 1.1.2.2 nathanw line = DZ_PORT(csr>>8);
250 1.1.2.2 nathanw
251 1.1.2.2 nathanw tp = sc->sc_dz[line].dz_tty;
252 1.1.2.2 nathanw cl = &tp->t_outq;
253 1.1.2.2 nathanw tp->t_state &= ~TS_BUSY;
254 1.1.2.2 nathanw
255 1.1.2.2 nathanw /* Just send out a char if we have one */
256 1.1.2.2 nathanw /* As long as we can fill the chip buffer, we just loop here */
257 1.1.2.2 nathanw if (cl->c_cc) {
258 1.1.2.2 nathanw tp->t_state |= TS_BUSY;
259 1.1.2.2 nathanw ch = getc(cl);
260 1.1.2.2 nathanw DZ_WRITE_BYTE(dr_tbuf, ch);
261 1.1.2.2 nathanw continue;
262 1.1.2.2 nathanw }
263 1.1.2.2 nathanw /* Nothing to send; clear the scan bit */
264 1.1.2.2 nathanw /* Clear xmit scanner bit; dzstart may set it again */
265 1.1.2.2 nathanw tcr = DZ_READ_WORD(dr_tcrw);
266 1.1.2.2 nathanw tcr &= 255;
267 1.1.2.2 nathanw tcr &= ~(1 << line);
268 1.1.2.2 nathanw DZ_WRITE_BYTE(dr_tcr, tcr);
269 1.1.2.2 nathanw if (sc->sc_dz[line].dz_catch)
270 1.1.2.2 nathanw continue;
271 1.1.2.2 nathanw
272 1.1.2.2 nathanw if (tp->t_state & TS_FLUSH)
273 1.1.2.2 nathanw tp->t_state &= ~TS_FLUSH;
274 1.1.2.2 nathanw else
275 1.1.2.2 nathanw ndflush (&tp->t_outq, cl->c_cc);
276 1.1.2.2 nathanw
277 1.1.2.2 nathanw (*tp->t_linesw->l_start)(tp);
278 1.1.2.2 nathanw }
279 1.1.2.2 nathanw }
280 1.1.2.2 nathanw
281 1.1.2.2 nathanw int
282 1.1.2.2 nathanw dzopen(dev_t dev, int flag, int mode, struct proc *p)
283 1.1.2.2 nathanw {
284 1.1.2.2 nathanw struct tty *tp;
285 1.1.2.2 nathanw int unit, line;
286 1.1.2.2 nathanw struct dz_softc *sc;
287 1.1.2.2 nathanw int s, error = 0;
288 1.1.2.2 nathanw
289 1.1.2.2 nathanw unit = DZ_I2C(minor(dev));
290 1.1.2.2 nathanw line = DZ_PORT(minor(dev));
291 1.1.2.2 nathanw if (unit >= dz_cd.cd_ndevs || dz_cd.cd_devs[unit] == NULL)
292 1.1.2.2 nathanw return (ENXIO);
293 1.1.2.2 nathanw
294 1.1.2.2 nathanw sc = dz_cd.cd_devs[unit];
295 1.1.2.2 nathanw
296 1.1.2.2 nathanw if (line >= sc->sc_type)
297 1.1.2.2 nathanw return ENXIO;
298 1.1.2.2 nathanw
299 1.1.2.2 nathanw /* if some other device is using the line, it's busy */
300 1.1.2.2 nathanw if (sc->sc_dz[line].dz_catch)
301 1.1.2.2 nathanw return EBUSY;
302 1.1.2.2 nathanw
303 1.1.2.2 nathanw tp = sc->sc_dz[line].dz_tty;
304 1.1.2.2 nathanw if (tp == NULL)
305 1.1.2.2 nathanw return (ENODEV);
306 1.1.2.2 nathanw tp->t_oproc = dzstart;
307 1.1.2.2 nathanw tp->t_param = dzparam;
308 1.1.2.2 nathanw tp->t_dev = dev;
309 1.1.2.2 nathanw if ((tp->t_state & TS_ISOPEN) == 0) {
310 1.1.2.2 nathanw ttychars(tp);
311 1.1.2.2 nathanw if (tp->t_ispeed == 0) {
312 1.1.2.2 nathanw tp->t_iflag = TTYDEF_IFLAG;
313 1.1.2.2 nathanw tp->t_oflag = TTYDEF_OFLAG;
314 1.1.2.2 nathanw tp->t_cflag = TTYDEF_CFLAG;
315 1.1.2.2 nathanw tp->t_lflag = TTYDEF_LFLAG;
316 1.1.2.2 nathanw tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
317 1.1.2.2 nathanw }
318 1.1.2.2 nathanw (void) dzparam(tp, &tp->t_termios);
319 1.1.2.2 nathanw ttsetwater(tp);
320 1.1.2.2 nathanw } else if ((tp->t_state & TS_XCLUDE) && p->p_ucred->cr_uid != 0)
321 1.1.2.2 nathanw return (EBUSY);
322 1.1.2.2 nathanw /* Use DMBIS and *not* DMSET or else we clobber incoming bits */
323 1.1.2.2 nathanw if (dzmctl(sc, line, DML_DTR, DMBIS) & DML_DCD)
324 1.1.2.2 nathanw tp->t_state |= TS_CARR_ON;
325 1.1.2.2 nathanw s = spltty();
326 1.1.2.2 nathanw while (!(flag & O_NONBLOCK) && !(tp->t_cflag & CLOCAL) &&
327 1.1.2.2 nathanw !(tp->t_state & TS_CARR_ON)) {
328 1.1.2.2 nathanw tp->t_wopen++;
329 1.1.2.2 nathanw error = ttysleep(tp, (caddr_t)&tp->t_rawq,
330 1.1.2.2 nathanw TTIPRI | PCATCH, ttopen, 0);
331 1.1.2.2 nathanw tp->t_wopen--;
332 1.1.2.2 nathanw if (error)
333 1.1.2.2 nathanw break;
334 1.1.2.2 nathanw }
335 1.1.2.2 nathanw (void) splx(s);
336 1.1.2.2 nathanw if (error)
337 1.1.2.2 nathanw return (error);
338 1.1.2.2 nathanw return ((*tp->t_linesw->l_open)(dev, tp));
339 1.1.2.2 nathanw }
340 1.1.2.2 nathanw
341 1.1.2.2 nathanw /*ARGSUSED*/
342 1.1.2.2 nathanw int
343 1.1.2.2 nathanw dzclose(dev_t dev, int flag, int mode, struct proc *p)
344 1.1.2.2 nathanw {
345 1.1.2.2 nathanw struct dz_softc *sc;
346 1.1.2.2 nathanw struct tty *tp;
347 1.1.2.2 nathanw int unit, line;
348 1.1.2.2 nathanw
349 1.1.2.2 nathanw
350 1.1.2.2 nathanw unit = DZ_I2C(minor(dev));
351 1.1.2.2 nathanw line = DZ_PORT(minor(dev));
352 1.1.2.2 nathanw sc = dz_cd.cd_devs[unit];
353 1.1.2.2 nathanw
354 1.1.2.2 nathanw tp = sc->sc_dz[line].dz_tty;
355 1.1.2.2 nathanw
356 1.1.2.2 nathanw (*tp->t_linesw->l_close)(tp, flag);
357 1.1.2.2 nathanw
358 1.1.2.2 nathanw /* Make sure a BREAK state is not left enabled. */
359 1.1.2.2 nathanw (void) dzmctl(sc, line, DML_BRK, DMBIC);
360 1.1.2.2 nathanw
361 1.1.2.2 nathanw /* Do a hangup if so required. */
362 1.1.2.2 nathanw if ((tp->t_cflag & HUPCL) || tp->t_wopen || !(tp->t_state & TS_ISOPEN))
363 1.1.2.2 nathanw (void) dzmctl(sc, line, 0, DMSET);
364 1.1.2.2 nathanw
365 1.1.2.2 nathanw return (ttyclose(tp));
366 1.1.2.2 nathanw }
367 1.1.2.2 nathanw
368 1.1.2.2 nathanw int
369 1.1.2.2 nathanw dzread(dev_t dev, struct uio *uio, int flag)
370 1.1.2.2 nathanw {
371 1.1.2.2 nathanw struct tty *tp;
372 1.1.2.2 nathanw struct dz_softc *sc;
373 1.1.2.2 nathanw
374 1.1.2.2 nathanw sc = dz_cd.cd_devs[DZ_I2C(minor(dev))];
375 1.1.2.2 nathanw
376 1.1.2.2 nathanw tp = sc->sc_dz[DZ_PORT(minor(dev))].dz_tty;
377 1.1.2.2 nathanw return ((*tp->t_linesw->l_read)(tp, uio, flag));
378 1.1.2.2 nathanw }
379 1.1.2.2 nathanw
380 1.1.2.2 nathanw int
381 1.1.2.2 nathanw dzwrite(dev_t dev, struct uio *uio, int flag)
382 1.1.2.2 nathanw {
383 1.1.2.2 nathanw struct tty *tp;
384 1.1.2.2 nathanw struct dz_softc *sc;
385 1.1.2.2 nathanw
386 1.1.2.2 nathanw sc = dz_cd.cd_devs[DZ_I2C(minor(dev))];
387 1.1.2.2 nathanw
388 1.1.2.2 nathanw tp = sc->sc_dz[DZ_PORT(minor(dev))].dz_tty;
389 1.1.2.2 nathanw return ((*tp->t_linesw->l_write)(tp, uio, flag));
390 1.1.2.2 nathanw }
391 1.1.2.2 nathanw
392 1.1.2.2 nathanw int
393 1.1.2.2 nathanw dzpoll(dev, events, p)
394 1.1.2.2 nathanw dev_t dev;
395 1.1.2.2 nathanw int events;
396 1.1.2.2 nathanw struct proc *p;
397 1.1.2.2 nathanw {
398 1.1.2.2 nathanw struct tty *tp;
399 1.1.2.2 nathanw struct dz_softc *sc;
400 1.1.2.2 nathanw
401 1.1.2.2 nathanw sc = dz_cd.cd_devs[DZ_I2C(minor(dev))];
402 1.1.2.2 nathanw
403 1.1.2.2 nathanw tp = sc->sc_dz[DZ_PORT(minor(dev))].dz_tty;
404 1.1.2.2 nathanw return ((*tp->t_linesw->l_poll)(tp, events, p));
405 1.1.2.2 nathanw }
406 1.1.2.2 nathanw
407 1.1.2.2 nathanw /*ARGSUSED*/
408 1.1.2.2 nathanw int
409 1.1.2.2 nathanw dzioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
410 1.1.2.2 nathanw {
411 1.1.2.2 nathanw struct dz_softc *sc;
412 1.1.2.2 nathanw struct tty *tp;
413 1.1.2.2 nathanw int unit, line;
414 1.1.2.2 nathanw int error;
415 1.1.2.2 nathanw
416 1.1.2.2 nathanw unit = DZ_I2C(minor(dev));
417 1.1.2.2 nathanw line = DZ_PORT(minor(dev));
418 1.1.2.2 nathanw sc = dz_cd.cd_devs[unit];
419 1.1.2.2 nathanw tp = sc->sc_dz[line].dz_tty;
420 1.1.2.2 nathanw
421 1.1.2.2 nathanw error = (*tp->t_linesw->l_ioctl)(tp, cmd, data, flag, p);
422 1.1.2.2 nathanw if (error >= 0)
423 1.1.2.2 nathanw return (error);
424 1.1.2.3 nathanw
425 1.1.2.2 nathanw error = ttioctl(tp, cmd, data, flag, p);
426 1.1.2.2 nathanw if (error >= 0)
427 1.1.2.2 nathanw return (error);
428 1.1.2.2 nathanw
429 1.1.2.2 nathanw switch (cmd) {
430 1.1.2.2 nathanw
431 1.1.2.2 nathanw case TIOCSBRK:
432 1.1.2.2 nathanw (void) dzmctl(sc, line, DML_BRK, DMBIS);
433 1.1.2.2 nathanw break;
434 1.1.2.2 nathanw
435 1.1.2.2 nathanw case TIOCCBRK:
436 1.1.2.2 nathanw (void) dzmctl(sc, line, DML_BRK, DMBIC);
437 1.1.2.2 nathanw break;
438 1.1.2.2 nathanw
439 1.1.2.2 nathanw case TIOCSDTR:
440 1.1.2.2 nathanw (void) dzmctl(sc, line, DML_DTR, DMBIS);
441 1.1.2.2 nathanw break;
442 1.1.2.2 nathanw
443 1.1.2.2 nathanw case TIOCCDTR:
444 1.1.2.2 nathanw (void) dzmctl(sc, line, DML_DTR, DMBIC);
445 1.1.2.2 nathanw break;
446 1.1.2.2 nathanw
447 1.1.2.2 nathanw case TIOCMSET:
448 1.1.2.2 nathanw (void) dzmctl(sc, line, *(int *)data, DMSET);
449 1.1.2.2 nathanw break;
450 1.1.2.2 nathanw
451 1.1.2.2 nathanw case TIOCMBIS:
452 1.1.2.2 nathanw (void) dzmctl(sc, line, *(int *)data, DMBIS);
453 1.1.2.2 nathanw break;
454 1.1.2.2 nathanw
455 1.1.2.2 nathanw case TIOCMBIC:
456 1.1.2.2 nathanw (void) dzmctl(sc, line, *(int *)data, DMBIC);
457 1.1.2.2 nathanw break;
458 1.1.2.2 nathanw
459 1.1.2.2 nathanw case TIOCMGET:
460 1.1.2.2 nathanw *(int *)data = (dzmctl(sc, line, 0, DMGET) & ~DML_BRK);
461 1.1.2.2 nathanw break;
462 1.1.2.2 nathanw
463 1.1.2.2 nathanw default:
464 1.1.2.3 nathanw return (EPASSTHROUGH);
465 1.1.2.2 nathanw }
466 1.1.2.2 nathanw return (0);
467 1.1.2.2 nathanw }
468 1.1.2.2 nathanw
469 1.1.2.2 nathanw struct tty *
470 1.1.2.2 nathanw dztty(dev_t dev)
471 1.1.2.2 nathanw {
472 1.1.2.2 nathanw struct dz_softc *sc = dz_cd.cd_devs[DZ_I2C(minor(dev))];
473 1.1.2.2 nathanw struct tty *tp = sc->sc_dz[DZ_PORT(minor(dev))].dz_tty;
474 1.1.2.2 nathanw
475 1.1.2.2 nathanw return (tp);
476 1.1.2.2 nathanw }
477 1.1.2.2 nathanw
478 1.1.2.2 nathanw /*ARGSUSED*/
479 1.1.2.2 nathanw void
480 1.1.2.2 nathanw dzstop(struct tty *tp, int flag)
481 1.1.2.2 nathanw {
482 1.1.2.2 nathanw if (tp->t_state & TS_BUSY)
483 1.1.2.2 nathanw if (!(tp->t_state & TS_TTSTOP))
484 1.1.2.2 nathanw tp->t_state |= TS_FLUSH;
485 1.1.2.2 nathanw }
486 1.1.2.2 nathanw
487 1.1.2.2 nathanw void
488 1.1.2.2 nathanw dzstart(struct tty *tp)
489 1.1.2.2 nathanw {
490 1.1.2.2 nathanw struct dz_softc *sc;
491 1.1.2.2 nathanw struct clist *cl;
492 1.1.2.2 nathanw int unit, line, s;
493 1.1.2.2 nathanw char state;
494 1.1.2.2 nathanw
495 1.1.2.2 nathanw unit = DZ_I2C(minor(tp->t_dev));
496 1.1.2.2 nathanw line = DZ_PORT(minor(tp->t_dev));
497 1.1.2.2 nathanw sc = dz_cd.cd_devs[unit];
498 1.1.2.2 nathanw
499 1.1.2.2 nathanw s = spltty();
500 1.1.2.2 nathanw if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP))
501 1.1.2.2 nathanw return;
502 1.1.2.2 nathanw cl = &tp->t_outq;
503 1.1.2.2 nathanw if (cl->c_cc <= tp->t_lowat) {
504 1.1.2.2 nathanw if (tp->t_state & TS_ASLEEP) {
505 1.1.2.2 nathanw tp->t_state &= ~TS_ASLEEP;
506 1.1.2.2 nathanw wakeup((caddr_t)cl);
507 1.1.2.2 nathanw }
508 1.1.2.2 nathanw selwakeup(&tp->t_wsel);
509 1.1.2.2 nathanw }
510 1.1.2.2 nathanw if (cl->c_cc == 0)
511 1.1.2.2 nathanw return;
512 1.1.2.2 nathanw
513 1.1.2.2 nathanw tp->t_state |= TS_BUSY;
514 1.1.2.2 nathanw
515 1.1.2.2 nathanw state = DZ_READ_WORD(dr_tcrw) & 255;
516 1.1.2.2 nathanw if ((state & (1 << line)) == 0) {
517 1.1.2.2 nathanw DZ_WRITE_BYTE(dr_tcr, state | (1 << line));
518 1.1.2.2 nathanw }
519 1.1.2.2 nathanw dzxint(sc);
520 1.1.2.2 nathanw splx(s);
521 1.1.2.2 nathanw }
522 1.1.2.2 nathanw
523 1.1.2.2 nathanw static int
524 1.1.2.2 nathanw dzparam(struct tty *tp, struct termios *t)
525 1.1.2.2 nathanw {
526 1.1.2.2 nathanw struct dz_softc *sc;
527 1.1.2.2 nathanw int cflag = t->c_cflag;
528 1.1.2.2 nathanw int unit, line;
529 1.1.2.2 nathanw int ispeed = ttspeedtab(t->c_ispeed, dzspeedtab);
530 1.1.2.2 nathanw int ospeed = ttspeedtab(t->c_ospeed, dzspeedtab);
531 1.1.2.2 nathanw unsigned lpr;
532 1.1.2.2 nathanw int s;
533 1.1.2.2 nathanw
534 1.1.2.2 nathanw unit = DZ_I2C(minor(tp->t_dev));
535 1.1.2.2 nathanw line = DZ_PORT(minor(tp->t_dev));
536 1.1.2.2 nathanw sc = dz_cd.cd_devs[unit];
537 1.1.2.2 nathanw
538 1.1.2.2 nathanw /* check requested parameters */
539 1.1.2.2 nathanw if (ospeed < 0 || ispeed < 0 || ispeed != ospeed)
540 1.1.2.2 nathanw return (EINVAL);
541 1.1.2.2 nathanw
542 1.1.2.2 nathanw tp->t_ispeed = t->c_ispeed;
543 1.1.2.2 nathanw tp->t_ospeed = t->c_ospeed;
544 1.1.2.2 nathanw tp->t_cflag = cflag;
545 1.1.2.2 nathanw
546 1.1.2.2 nathanw if (ospeed == 0) {
547 1.1.2.2 nathanw (void) dzmctl(sc, line, 0, DMSET); /* hang up line */
548 1.1.2.2 nathanw return (0);
549 1.1.2.2 nathanw }
550 1.1.2.2 nathanw
551 1.1.2.2 nathanw s = spltty();
552 1.1.2.2 nathanw
553 1.1.2.2 nathanw lpr = DZ_LPR_RX_ENABLE | ((ispeed&0xF)<<8) | line;
554 1.1.2.2 nathanw
555 1.1.2.2 nathanw switch (cflag & CSIZE)
556 1.1.2.2 nathanw {
557 1.1.2.2 nathanw case CS5:
558 1.1.2.2 nathanw lpr |= DZ_LPR_5_BIT_CHAR;
559 1.1.2.2 nathanw break;
560 1.1.2.2 nathanw case CS6:
561 1.1.2.2 nathanw lpr |= DZ_LPR_6_BIT_CHAR;
562 1.1.2.2 nathanw break;
563 1.1.2.2 nathanw case CS7:
564 1.1.2.2 nathanw lpr |= DZ_LPR_7_BIT_CHAR;
565 1.1.2.2 nathanw break;
566 1.1.2.2 nathanw default:
567 1.1.2.2 nathanw lpr |= DZ_LPR_8_BIT_CHAR;
568 1.1.2.2 nathanw break;
569 1.1.2.2 nathanw }
570 1.1.2.2 nathanw if (cflag & PARENB)
571 1.1.2.2 nathanw lpr |= DZ_LPR_PARENB;
572 1.1.2.2 nathanw if (cflag & PARODD)
573 1.1.2.2 nathanw lpr |= DZ_LPR_OPAR;
574 1.1.2.2 nathanw if (cflag & CSTOPB)
575 1.1.2.2 nathanw lpr |= DZ_LPR_2_STOP;
576 1.1.2.2 nathanw
577 1.1.2.2 nathanw DZ_WRITE_WORD(dr_lpr, lpr);
578 1.1.2.2 nathanw
579 1.1.2.2 nathanw (void) splx(s);
580 1.1.2.2 nathanw return (0);
581 1.1.2.2 nathanw }
582 1.1.2.2 nathanw
583 1.1.2.2 nathanw static unsigned
584 1.1.2.2 nathanw dzmctl(struct dz_softc *sc, int line, int bits, int how)
585 1.1.2.2 nathanw {
586 1.1.2.2 nathanw unsigned status;
587 1.1.2.2 nathanw unsigned mbits;
588 1.1.2.2 nathanw unsigned bit;
589 1.1.2.2 nathanw int s;
590 1.1.2.2 nathanw
591 1.1.2.2 nathanw s = spltty();
592 1.1.2.2 nathanw
593 1.1.2.2 nathanw mbits = 0;
594 1.1.2.2 nathanw
595 1.1.2.2 nathanw bit = (1 << line);
596 1.1.2.2 nathanw
597 1.1.2.2 nathanw /* external signals as seen from the port */
598 1.1.2.2 nathanw
599 1.1.2.2 nathanw status = DZ_READ_BYTE(dr_dcd) | sc->sc_dsr;
600 1.1.2.2 nathanw
601 1.1.2.2 nathanw if (status & bit)
602 1.1.2.2 nathanw mbits |= DML_DCD;
603 1.1.2.2 nathanw
604 1.1.2.2 nathanw status = DZ_READ_BYTE(dr_ring);
605 1.1.2.2 nathanw
606 1.1.2.2 nathanw if (status & bit)
607 1.1.2.2 nathanw mbits |= DML_RI;
608 1.1.2.2 nathanw
609 1.1.2.2 nathanw /* internal signals/state delivered to port */
610 1.1.2.2 nathanw
611 1.1.2.2 nathanw status = DZ_READ_BYTE(dr_dtr);
612 1.1.2.2 nathanw
613 1.1.2.2 nathanw if (status & bit)
614 1.1.2.2 nathanw mbits |= DML_DTR;
615 1.1.2.2 nathanw
616 1.1.2.2 nathanw if (sc->sc_brk & bit)
617 1.1.2.2 nathanw mbits |= DML_BRK;
618 1.1.2.2 nathanw
619 1.1.2.2 nathanw switch (how)
620 1.1.2.2 nathanw {
621 1.1.2.2 nathanw case DMSET:
622 1.1.2.2 nathanw mbits = bits;
623 1.1.2.2 nathanw break;
624 1.1.2.2 nathanw
625 1.1.2.2 nathanw case DMBIS:
626 1.1.2.2 nathanw mbits |= bits;
627 1.1.2.2 nathanw break;
628 1.1.2.2 nathanw
629 1.1.2.2 nathanw case DMBIC:
630 1.1.2.2 nathanw mbits &= ~bits;
631 1.1.2.2 nathanw break;
632 1.1.2.2 nathanw
633 1.1.2.2 nathanw case DMGET:
634 1.1.2.2 nathanw (void) splx(s);
635 1.1.2.2 nathanw return (mbits);
636 1.1.2.2 nathanw }
637 1.1.2.2 nathanw
638 1.1.2.2 nathanw if (mbits & DML_DTR) {
639 1.1.2.2 nathanw DZ_WRITE_BYTE(dr_dtr, DZ_READ_BYTE(dr_dtr) | bit);
640 1.1.2.2 nathanw } else {
641 1.1.2.2 nathanw DZ_WRITE_BYTE(dr_dtr, DZ_READ_BYTE(dr_dtr) & ~bit);
642 1.1.2.2 nathanw }
643 1.1.2.2 nathanw
644 1.1.2.2 nathanw if (mbits & DML_BRK) {
645 1.1.2.2 nathanw sc->sc_brk |= bit;
646 1.1.2.2 nathanw DZ_WRITE_BYTE(dr_break, sc->sc_brk);
647 1.1.2.2 nathanw } else {
648 1.1.2.2 nathanw sc->sc_brk &= ~bit;
649 1.1.2.2 nathanw DZ_WRITE_BYTE(dr_break, sc->sc_brk);
650 1.1.2.2 nathanw }
651 1.1.2.2 nathanw
652 1.1.2.2 nathanw (void) splx(s);
653 1.1.2.2 nathanw return (mbits);
654 1.1.2.2 nathanw }
655 1.1.2.2 nathanw
656 1.1.2.2 nathanw /*
657 1.1.2.2 nathanw * This is called by timeout() periodically.
658 1.1.2.2 nathanw * Check to see if modem status bits have changed.
659 1.1.2.2 nathanw */
660 1.1.2.2 nathanw static void
661 1.1.2.2 nathanw dzscan(void *arg)
662 1.1.2.2 nathanw {
663 1.1.2.2 nathanw struct dz_softc *sc;
664 1.1.2.2 nathanw struct tty *tp;
665 1.1.2.2 nathanw int n, bit, port;
666 1.1.2.2 nathanw unsigned csr;
667 1.1.2.2 nathanw int s;
668 1.1.2.2 nathanw
669 1.1.2.2 nathanw s = spltty();
670 1.1.2.2 nathanw
671 1.1.2.2 nathanw for (n = 0; n < dz_cd.cd_ndevs; n++) {
672 1.1.2.2 nathanw
673 1.1.2.2 nathanw if (dz_cd.cd_devs[n] == NULL)
674 1.1.2.2 nathanw continue;
675 1.1.2.2 nathanw
676 1.1.2.2 nathanw sc = dz_cd.cd_devs[n];
677 1.1.2.2 nathanw
678 1.1.2.2 nathanw for (port = 0; port < sc->sc_type; port++) {
679 1.1.2.2 nathanw
680 1.1.2.2 nathanw tp = sc->sc_dz[port].dz_tty;
681 1.1.2.2 nathanw bit = (1 << port);
682 1.1.2.2 nathanw
683 1.1.2.2 nathanw if ((DZ_READ_BYTE(dr_dcd) | sc->sc_dsr) & bit) {
684 1.1.2.2 nathanw if (!(tp->t_state & TS_CARR_ON))
685 1.1.2.2 nathanw (*tp->t_linesw->l_modem) (tp, 1);
686 1.1.2.2 nathanw } else if ((tp->t_state & TS_CARR_ON) &&
687 1.1.2.2 nathanw (*tp->t_linesw->l_modem)(tp, 0) == 0) {
688 1.1.2.2 nathanw DZ_WRITE_BYTE(dr_tcr,
689 1.1.2.2 nathanw (DZ_READ_WORD(dr_tcrw) & 255) & ~bit);
690 1.1.2.2 nathanw }
691 1.1.2.2 nathanw }
692 1.1.2.2 nathanw
693 1.1.2.2 nathanw /*
694 1.1.2.2 nathanw * If the RX interrupt rate is this high, switch
695 1.1.2.2 nathanw * the controller to Silo Alarm - which means don't
696 1.1.2.2 nathanw * interrupt until the RX silo has 16 characters in
697 1.1.2.2 nathanw * it (the silo is 64 characters in all).
698 1.1.2.2 nathanw * Avoid oscillating SA on and off by not turning
699 1.1.2.2 nathanw * if off unless the rate is appropriately low.
700 1.1.2.2 nathanw */
701 1.1.2.2 nathanw
702 1.1.2.2 nathanw csr = DZ_READ_WORD(dr_csr);
703 1.1.2.2 nathanw
704 1.1.2.2 nathanw if (sc->sc_rxint > (16*10)) {
705 1.1.2.2 nathanw if ((csr & DZ_CSR_SAE) == 0)
706 1.1.2.2 nathanw DZ_WRITE_WORD(dr_csr, csr | DZ_CSR_SAE);
707 1.1.2.2 nathanw } else if ((csr & DZ_CSR_SAE) != 0)
708 1.1.2.2 nathanw if (sc->sc_rxint < 10)
709 1.1.2.2 nathanw DZ_WRITE_WORD(dr_csr, csr & ~(DZ_CSR_SAE));
710 1.1.2.2 nathanw
711 1.1.2.2 nathanw sc->sc_rxint = 0;
712 1.1.2.2 nathanw }
713 1.1.2.2 nathanw (void) splx(s);
714 1.1.2.2 nathanw callout_reset(&dzscan_ch, hz, dzscan, NULL);
715 1.1.2.2 nathanw return;
716 1.1.2.2 nathanw }
717 1.1.2.2 nathanw
718 1.1.2.2 nathanw /*
719 1.1.2.2 nathanw * Called after an ubareset. The DZ card is reset, but the only thing
720 1.1.2.2 nathanw * that must be done is to start the receiver and transmitter again.
721 1.1.2.2 nathanw * No DMA setup to care about.
722 1.1.2.2 nathanw */
723 1.1.2.2 nathanw void
724 1.1.2.2 nathanw dzreset(struct device *dev)
725 1.1.2.2 nathanw {
726 1.1.2.2 nathanw struct dz_softc *sc = (void *)dev;
727 1.1.2.2 nathanw struct tty *tp;
728 1.1.2.2 nathanw int i;
729 1.1.2.2 nathanw
730 1.1.2.2 nathanw for (i = 0; i < sc->sc_type; i++) {
731 1.1.2.2 nathanw tp = sc->sc_dz[i].dz_tty;
732 1.1.2.2 nathanw
733 1.1.2.2 nathanw if (((tp->t_state & TS_ISOPEN) == 0) || (tp->t_wopen == 0))
734 1.1.2.2 nathanw continue;
735 1.1.2.2 nathanw
736 1.1.2.2 nathanw dzparam(tp, &tp->t_termios);
737 1.1.2.2 nathanw dzmctl(sc, i, DML_DTR, DMSET);
738 1.1.2.2 nathanw tp->t_state &= ~TS_BUSY;
739 1.1.2.2 nathanw dzstart(tp); /* Kick off transmitter again */
740 1.1.2.2 nathanw }
741 1.1.2.2 nathanw }
742