msc.c revision 1.6.4.2 1 1.6.4.2 rat /* $NetBSD: msc.c,v 1.6.4.2 1997/01/26 01:49:47 rat Exp $ */
2 1.1 chopps
3 1.1 chopps /*
4 1.1 chopps * Copyright (c) 1993 Zik.
5 1.6.4.2 rat * Copyright (c) 1995 Jukka Marin <jmarin (at) jmp.fi>.
6 1.1 chopps * Copyright (c) 1995 Timo Rossi <trossi (at) jyu.fi>.
7 1.1 chopps * Copyright (c) 1995 Rob Healey <rhealey (at) kas.helios.mn.org>.
8 1.1 chopps * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
9 1.1 chopps * All rights reserved.
10 1.1 chopps *
11 1.1 chopps * Redistribution and use in source and binary forms, with or without
12 1.1 chopps * modification, are permitted provided that the following conditions
13 1.1 chopps * are met:
14 1.1 chopps * 1. Redistributions of source code must retain the above copyright
15 1.1 chopps * notice, this list of conditions and the following disclaimer.
16 1.1 chopps * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 chopps * notice, this list of conditions and the following disclaimer in the
18 1.1 chopps * documentation and/or other materials provided with the distribution.
19 1.1 chopps * 3. All advertising materials mentioning features or use of this software
20 1.1 chopps * must display the following acknowledgement:
21 1.1 chopps * This product includes software developed by the University of
22 1.1 chopps * California, Berkeley and its contributors.
23 1.1 chopps * 4. Neither the name of the University nor the names of its contributors
24 1.1 chopps * may be used to endorse or promote products derived from this software
25 1.1 chopps * without specific prior written permission.
26 1.1 chopps *
27 1.1 chopps * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 1.1 chopps * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 1.1 chopps * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 1.1 chopps * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 1.1 chopps * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 1.1 chopps * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 1.1 chopps * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 1.1 chopps * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 1.1 chopps * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 1.1 chopps * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 1.1 chopps * SUCH DAMAGE.
38 1.1 chopps *
39 1.1 chopps * - converted from NetBSD Amiga serial driver to A2232 serial driver
40 1.1 chopps * by zik 931207
41 1.1 chopps * - added ttyflags hooks rfh 940419
42 1.1 chopps * - added new style config support rfh 940601
43 1.1 chopps * - added code to halt board during memory load so board doesn't flip
44 1.1 chopps * out. /dev/reload works now. Also created mschwiflow function so BSD can
45 1.1 chopps * attempt to use board RTS flow control now. rfh 950108
46 1.1 chopps * - Integrated work from Jukka Marin <jmarin (at) jmp.fi> and
47 1.1 chopps * Timo Rossi <trossi (at) jyu.fi> The mscmint() code is Jukka's. 950916
48 1.1 chopps * Integrated more bug fixes by Jukka Marin <jmarin (at) jmp.fi> 950918
49 1.1 chopps * Also added Jukka's turbo board code. 950918
50 1.1 chopps * - Reformatted to NetBSD style format.
51 1.6.4.2 rat * - Rewritten the carrier detect system to prevent lock-ups (jm 951029)
52 1.1 chopps */
53 1.1 chopps
54 1.1 chopps #include "msc.h"
55 1.1 chopps
56 1.1 chopps #if NMSC > 0
57 1.1 chopps #include <sys/param.h>
58 1.1 chopps #include <sys/systm.h>
59 1.1 chopps #include <sys/ioctl.h>
60 1.1 chopps #include <sys/tty.h>
61 1.1 chopps #include <sys/proc.h>
62 1.1 chopps #include <sys/file.h>
63 1.1 chopps #include <sys/malloc.h>
64 1.1 chopps #include <sys/uio.h>
65 1.1 chopps #include <sys/kernel.h>
66 1.1 chopps #include <sys/syslog.h>
67 1.1 chopps #include <sys/device.h>
68 1.1 chopps
69 1.1 chopps #include <amiga/amiga/device.h>
70 1.1 chopps #include <amiga/dev/zbusvar.h>
71 1.1 chopps #include <amiga/dev/mscreg.h>
72 1.3 mycroft #include <machine/cpu.h>
73 1.1 chopps
74 1.1 chopps #include <amiga/amiga/custom.h>
75 1.1 chopps #include <amiga/amiga/cia.h>
76 1.1 chopps #include <amiga/amiga/cc.h>
77 1.1 chopps
78 1.6 veego #include <sys/conf.h>
79 1.6 veego #include <machine/conf.h>
80 1.6 veego
81 1.1 chopps /* 6502 code for A2232 card */
82 1.1 chopps #include "msc6502.h"
83 1.1 chopps
84 1.1 chopps /*
85 1.1 chopps * Note: These are Zik's original comments:
86 1.1 chopps * There is a bit of a "gotcha" concerning the numbering
87 1.1 chopps * of msc devices and the specification of the number of serial
88 1.1 chopps * lines in the kernel.
89 1.1 chopps *
90 1.1 chopps * Each board has seven lines, but for programming convenience
91 1.1 chopps * and compatibility with Amiga UNIX the boards' minor device
92 1.1 chopps * numbers are allocated in groups of sixteen:
93 1.1 chopps *
94 1.1 chopps * minor device numbers
95 1.1 chopps * First board 0 2 4 6 8 10 12
96 1.1 chopps * Second board 16 18 20 22 24 26 28
97 1.1 chopps * Third board 32 34 36 38 40 42 44
98 1.1 chopps *
99 1.1 chopps * The intermediate minor device numbers are dialin versions
100 1.1 chopps * of the same devices. ie. 10 is dialout line 6 and 11 is
101 1.1 chopps * the dialin version of line 6.
102 1.1 chopps *
103 1.1 chopps * On the other hand, I have made the NMSC config option refer
104 1.1 chopps * to the total number of a2232 cards, not the maximum
105 1.1 chopps * minor device number. So you might have NMSC=3, in which case
106 1.1 chopps * you have three boards with minor device numbers from 0 to 45.
107 1.1 chopps */
108 1.1 chopps
109 1.6 veego int mscparam __P((struct tty *, struct termios *));
110 1.6 veego void mscstart __P((struct tty *));
111 1.1 chopps int mschwiflow __P((struct tty *, int));
112 1.1 chopps int mscinitcard __P((struct zbus_args *));
113 1.1 chopps
114 1.1 chopps int mscdefaultrate = TTYDEF_SPEED;
115 1.1 chopps
116 1.1 chopps struct mscdevice mscdev[MSCSLOTS]; /* device structs for all lines */
117 1.1 chopps struct tty *msc_tty[MSCTTYS]; /* ttys for all lines */
118 1.1 chopps
119 1.1 chopps struct vbl_node msc_vbl_node[NMSC]; /* vbl interrupt node per board */
120 1.1 chopps
121 1.1 chopps struct speedtab mscspeedtab_normal[] = {
122 1.6 veego { 0, 0 },
123 1.6 veego { 50, MSCPARAM_B50 },
124 1.6.4.2 rat { 75, MSCPARAM_B75 },
125 1.6.4.2 rat { 110, MSCPARAM_B110 },
126 1.6 veego { 134, MSCPARAM_B134 },
127 1.6 veego { 150, MSCPARAM_B150 },
128 1.6 veego { 300, MSCPARAM_B300 },
129 1.6 veego { 600, MSCPARAM_B600 },
130 1.6 veego { 1200, MSCPARAM_B1200 },
131 1.6 veego { 1800, MSCPARAM_B1800 },
132 1.6 veego { 2400, MSCPARAM_B2400 },
133 1.6 veego { 3600, MSCPARAM_B3600 },
134 1.6 veego { 4800, MSCPARAM_B4800 },
135 1.6 veego { 7200, MSCPARAM_B7200 },
136 1.6 veego { 9600, MSCPARAM_B9600 },
137 1.6 veego { 19200, MSCPARAM_B19200 },
138 1.6 veego { 115200, MSCPARAM_B115200 },
139 1.6 veego { -1, -1 }
140 1.1 chopps };
141 1.1 chopps
142 1.1 chopps struct speedtab mscspeedtab_turbo[] = {
143 1.6 veego { 0, 0 },
144 1.6 veego { 100, MSCPARAM_B50 },
145 1.6 veego { 150, MSCPARAM_B75 },
146 1.6 veego { 220, MSCPARAM_B110 },
147 1.6 veego { 269, MSCPARAM_B134 },
148 1.6 veego { 300, MSCPARAM_B150 },
149 1.6 veego { 600, MSCPARAM_B300 },
150 1.6 veego { 1200, MSCPARAM_B600 },
151 1.6 veego { 2400, MSCPARAM_B1200 },
152 1.6 veego { 3600, MSCPARAM_B1800 },
153 1.6 veego { 4800, MSCPARAM_B2400 },
154 1.6 veego { 7200, MSCPARAM_B3600 },
155 1.6 veego { 9600, MSCPARAM_B4800 },
156 1.6 veego { 14400, MSCPARAM_B7200 },
157 1.6 veego { 19200, MSCPARAM_B9600 },
158 1.6 veego { 38400, MSCPARAM_B19200 },
159 1.6 veego { 230400, MSCPARAM_B115200 },
160 1.6 veego { -1, -1 }
161 1.1 chopps };
162 1.1 chopps
163 1.1 chopps struct speedtab *mscspeedtab;
164 1.1 chopps
165 1.1 chopps int mscmctl __P((dev_t dev, int bits, int howto));
166 1.1 chopps void mscmint __P((register void *data));
167 1.1 chopps
168 1.4 thorpej int mscmatch __P((struct device *, void *, void *));
169 1.1 chopps void mscattach __P((struct device *, struct device *, void *));
170 1.1 chopps
171 1.1 chopps #define SWFLAGS(dev) (msc->openflags | (MSCDIALIN(dev) ? 0 : TIOCFLAG_SOFTCAR))
172 1.6.4.2 rat #define DEBUG_CD 1
173 1.1 chopps
174 1.4 thorpej struct cfattach msc_ca = {
175 1.4 thorpej sizeof(struct device), mscmatch, mscattach
176 1.4 thorpej };
177 1.4 thorpej
178 1.4 thorpej struct cfdriver msc_cd = {
179 1.5 mhitch NULL, "msc",DV_TTY, NULL, 0
180 1.1 chopps };
181 1.1 chopps
182 1.2 chopps
183 1.1 chopps int
184 1.4 thorpej mscmatch(pdp, match, auxp)
185 1.1 chopps struct device *pdp;
186 1.4 thorpej void *match, *auxp;
187 1.1 chopps {
188 1.1 chopps struct zbus_args *zap;
189 1.1 chopps
190 1.1 chopps zap = auxp;
191 1.1 chopps if (zap->manid == 514 && (zap->prodid == 70 || zap->prodid == 69))
192 1.1 chopps return(1);
193 1.1 chopps
194 1.1 chopps return (0);
195 1.1 chopps }
196 1.1 chopps
197 1.1 chopps void
198 1.1 chopps mscattach(pdp, dp, auxp)
199 1.1 chopps struct device *pdp, *dp;
200 1.1 chopps void *auxp;
201 1.1 chopps {
202 1.6.4.2 rat volatile struct mscmemory *mscmem;
203 1.6.4.2 rat struct mscdevice *msc;
204 1.6.4.2 rat struct zbus_args *zap;
205 1.6.4.2 rat int unit;
206 1.6.4.2 rat int Count;
207 1.6.4.2 rat
208 1.6.4.2 rat zap = (struct zbus_args *)auxp;
209 1.6.4.2 rat unit = dp->dv_unit;
210 1.6.4.2 rat
211 1.6.4.2 rat /*
212 1.6.4.2 rat * Make config msgs look nicer.
213 1.6.4.2 rat */
214 1.6.4.2 rat printf("\n");
215 1.6.4.2 rat
216 1.6.4.2 rat if (mscinitcard(zap) != 0) {
217 1.6.4.2 rat printf("msc%d: Board initialize failed, bad download code.\n", unit);
218 1.6.4.2 rat return;
219 1.6.4.2 rat }
220 1.6.4.2 rat
221 1.6.4.2 rat printf("msc%d: Board successfully initialized.\n", unit);
222 1.6.4.2 rat
223 1.6.4.2 rat mscmem = (struct mscmemory *) zap->va;
224 1.6.4.2 rat
225 1.6.4.2 rat if (mscmem->Common.Crystal == MSC_UNKNOWN) {
226 1.6.4.2 rat printf("msc%d: Unable to detect crystal frequency.\n", unit);
227 1.6.4.2 rat return;
228 1.6.4.2 rat }
229 1.6.4.2 rat
230 1.6.4.2 rat if (mscmem->Common.Crystal == MSC_TURBO) {
231 1.6.4.2 rat printf("msc%d: Turbo version detected (%02x%02x:%d)\n", unit,
232 1.6.4.2 rat mscmem->Common.TimerH, mscmem->Common.TimerL,
233 1.6.4.2 rat mscmem->Common.Pad_a);
234 1.6.4.2 rat mscspeedtab = mscspeedtab_turbo;
235 1.6.4.2 rat } else {
236 1.6.4.2 rat printf("msc%d: Normal version detected (%02x%02x:%d)\n", unit,
237 1.6.4.2 rat mscmem->Common.TimerH, mscmem->Common.TimerL,
238 1.6.4.2 rat mscmem->Common.Pad_a);
239 1.6.4.2 rat mscspeedtab = mscspeedtab_normal;
240 1.6.4.2 rat }
241 1.6.4.2 rat
242 1.6.4.2 rat mscmem->Common.CDStatus = 0; /* common status for all 7 ports */
243 1.6.4.2 rat
244 1.6.4.2 rat /* XXX 8 is a constant */
245 1.6.4.2 rat for (Count = 0; Count < 8 && MSCSLOTUL(unit, Count) < MSCSLOTS; Count++) {
246 1.6.4.2 rat msc = &mscdev[MSCSLOTUL(unit, Count)];
247 1.6.4.2 rat msc->board = mscmem;
248 1.6.4.2 rat msc->port = Count;
249 1.6.4.2 rat msc->flags = 0;
250 1.6.4.2 rat msc->openflags = 0;
251 1.6.4.2 rat msc->active = 1;
252 1.6.4.2 rat msc->unit = unit;
253 1.6.4.2 rat msc->closing = FALSE;
254 1.6.4.2 rat msc_tty[MSCTTYSLOT(MSCSLOTUL(unit, Count))] = NULL;
255 1.6.4.2 rat msc_tty[MSCTTYSLOT(MSCSLOTUL(unit, Count)) + 1] = NULL;
256 1.6.4.2 rat }
257 1.1 chopps
258 1.6.4.2 rat /* disable the non-existant eighth port */
259 1.6.4.2 rat if (MSCSLOTUL(unit, NUMLINES) < MSCSLOTS)
260 1.6.4.2 rat mscdev[MSCSLOTUL(unit, NUMLINES)].active = 0;
261 1.1 chopps
262 1.6.4.2 rat msc_vbl_node[unit].function = (void (*) (void *)) mscmint;
263 1.6.4.2 rat msc_vbl_node[unit].data = (void *) unit;
264 1.1 chopps
265 1.6.4.2 rat add_vbl_function (&msc_vbl_node[unit], MSC_VBL_PRIORITY, (void *)unit);
266 1.6.4.2 rat
267 1.6.4.2 rat return;
268 1.1 chopps }
269 1.1 chopps
270 1.1 chopps /* ARGSUSED */
271 1.1 chopps int
272 1.1 chopps mscopen(dev, flag, mode, p)
273 1.1 chopps dev_t dev;
274 1.1 chopps int flag, mode;
275 1.1 chopps struct proc *p;
276 1.1 chopps {
277 1.6.4.2 rat register struct tty *tp;
278 1.6.4.2 rat struct mscdevice *msc;
279 1.6.4.2 rat volatile struct mscstatus *ms;
280 1.6.4.2 rat int error = 0;
281 1.6.4.2 rat int s, slot, ttyn;
282 1.1 chopps
283 1.6.4.2 rat /* get the device structure */
284 1.6.4.2 rat slot = MSCSLOT(dev);
285 1.6.4.2 rat ttyn = MSCTTY(dev);
286 1.6.4.2 rat
287 1.6.4.2 rat if (slot >= MSCSLOTS)
288 1.6.4.2 rat return ENXIO;
289 1.6.4.2 rat
290 1.6.4.2 rat if (MSCLINE(dev) >= NUMLINES)
291 1.6.4.2 rat return ENXIO;
292 1.6.4.2 rat
293 1.6.4.2 rat msc = &mscdev[slot];
294 1.6.4.2 rat ms = &msc->board->Status[msc->port];
295 1.6.4.2 rat
296 1.6.4.2 rat if (!msc->active)
297 1.6.4.2 rat return ENXIO;
298 1.6.4.2 rat
299 1.6.4.2 rat /*
300 1.6.4.2 rat * RFH: WHY here? Put down by while like other serial drivers
301 1.6.4.2 rat * But if we do that it makes things bomb.
302 1.6.4.2 rat */
303 1.6.4.2 rat s = spltty();
304 1.1 chopps
305 1.6.4.2 rat if (!msc_tty[ttyn]) {
306 1.1 chopps
307 1.6.4.2 rat tp = ttymalloc();
308 1.6.4.2 rat tty_attach(tp);
309 1.6.4.2 rat msc_tty[ttyn] = tp;
310 1.6.4.2 rat msc_tty[ttyn+1] = (struct tty *)NULL;
311 1.6.4.2 rat
312 1.6.4.2 rat #if 0
313 1.6.4.2 rat /* default values are not optimal for this device, increase buffers. */
314 1.6.4.2 rat clfree(&tp->t_rawq);
315 1.6.4.2 rat clfree(&tp->t_canq);
316 1.6.4.2 rat clfree(&tp->t_outq);
317 1.6.4.2 rat clalloc(&tp->t_rawq, 8192, 1);
318 1.6.4.2 rat clalloc(&tp->t_canq, 8192, 1);
319 1.6.4.2 rat clalloc(&tp->t_outq, 8192, 0);
320 1.6.4.2 rat #endif
321 1.6.4.2 rat
322 1.6.4.2 rat } else
323 1.6.4.2 rat tp = msc_tty[ttyn];
324 1.6.4.2 rat
325 1.6.4.2 rat tp->t_oproc = (void (*) (struct tty *)) mscstart;
326 1.6.4.2 rat tp->t_param = mscparam;
327 1.6.4.2 rat tp->t_dev = dev;
328 1.6.4.2 rat tp->t_hwiflow = mschwiflow;
329 1.1 chopps
330 1.6.4.2 rat /* if port is still closing, just bitbucket remaining characters */
331 1.6.4.2 rat if (msc->closing) {
332 1.6.4.2 rat ms->OutFlush = TRUE;
333 1.6.4.2 rat msc->closing = FALSE;
334 1.6.4.2 rat }
335 1.1 chopps
336 1.6.4.2 rat /* initialize tty */
337 1.6.4.2 rat if ((tp->t_state & TS_ISOPEN) == 0) {
338 1.6.4.2 rat tp->t_state |= TS_WOPEN;
339 1.6.4.2 rat ttychars(tp);
340 1.6.4.2 rat if (tp->t_ispeed == 0) {
341 1.6.4.2 rat tp->t_iflag = TTYDEF_IFLAG;
342 1.6.4.2 rat tp->t_oflag = TTYDEF_OFLAG;
343 1.6.4.2 rat tp->t_cflag = TTYDEF_CFLAG;
344 1.6.4.2 rat tp->t_lflag = TTYDEF_LFLAG;
345 1.6.4.2 rat tp->t_ispeed = tp->t_ospeed = mscdefaultrate;
346 1.6.4.2 rat }
347 1.1 chopps
348 1.6.4.2 rat /* flags changed to be private to every unit by JM */
349 1.6.4.2 rat if (msc->openflags & TIOCFLAG_CLOCAL)
350 1.6.4.2 rat tp->t_cflag |= CLOCAL;
351 1.6.4.2 rat if (msc->openflags & TIOCFLAG_CRTSCTS)
352 1.6.4.2 rat tp->t_cflag |= CRTSCTS;
353 1.6.4.2 rat if (msc->openflags & TIOCFLAG_MDMBUF)
354 1.6.4.2 rat tp->t_cflag |= MDMBUF;
355 1.6.4.2 rat
356 1.6.4.2 rat mscparam(tp, &tp->t_termios);
357 1.6.4.2 rat ttsetwater(tp);
358 1.6.4.2 rat
359 1.6.4.2 rat (void) mscmctl(dev, TIOCM_DTR | TIOCM_RTS, DMSET);
360 1.6.4.2 rat
361 1.6.4.2 rat if ((SWFLAGS(dev) & TIOCFLAG_SOFTCAR) ||
362 1.6.4.2 rat (mscmctl(dev, 0, DMGET) & TIOCM_CD))
363 1.6.4.2 rat tp->t_state |= TS_CARR_ON;
364 1.6.4.2 rat else
365 1.6.4.2 rat tp->t_state &= ~TS_CARR_ON;
366 1.6.4.2 rat
367 1.6.4.2 rat } else {
368 1.6.4.2 rat if (tp->t_state & TS_XCLUDE && p->p_ucred->cr_uid != 0) {
369 1.6.4.2 rat splx(s);
370 1.6.4.2 rat return (EBUSY);
371 1.6.4.2 rat }
372 1.6.4.2 rat }
373 1.6.4.2 rat
374 1.6.4.2 rat /*
375 1.6.4.2 rat * if NONBLOCK requested, ignore carrier
376 1.6.4.2 rat */
377 1.6.4.2 rat if (flag & O_NONBLOCK) {
378 1.6.4.2 rat #if DEBUG_CD
379 1.6.4.2 rat printf("msc%d: %d open nonblock\n", msc->unit, MSCLINE(dev));
380 1.6.4.2 rat #endif
381 1.6.4.2 rat goto done;
382 1.6.4.2 rat }
383 1.6.4.2 rat
384 1.6.4.2 rat /*
385 1.6.4.2 rat * s = spltty();
386 1.6.4.2 rat *
387 1.6.4.2 rat * This causes hangs when put here, like other TTY drivers do, rather than
388 1.6.4.2 rat * above, WHY? RFH
389 1.6.4.2 rat *
390 1.6.4.2 rat */
391 1.1 chopps
392 1.6.4.2 rat while ((tp->t_state & TS_CARR_ON) == 0 && (tp->t_cflag & CLOCAL) == 0) {
393 1.6.4.2 rat tp->t_state |= TS_WOPEN;
394 1.1 chopps
395 1.2 chopps #if DEBUG_CD
396 1.6.4.2 rat printf("msc%d: %d waiting for CD\n", msc->unit, MSCLINE(dev));
397 1.2 chopps #endif
398 1.6.4.2 rat error = ttysleep(tp, (caddr_t)&tp->t_rawq, TTIPRI | PCATCH, ttopen, 0);
399 1.1 chopps
400 1.6.4.2 rat if (error) {
401 1.6.4.2 rat splx(s);
402 1.6.4.2 rat return(error);
403 1.6.4.2 rat }
404 1.6.4.2 rat }
405 1.1 chopps
406 1.1 chopps #if DEBUG_CD
407 1.6.4.2 rat printf("msc%d: %d got CD\n", msc->unit, MSCLINE(dev));
408 1.1 chopps #endif
409 1.1 chopps
410 1.6.4.2 rat done:
411 1.6.4.2 rat /* This is a way to handle lost XON characters */
412 1.6.4.2 rat if ((flag & O_TRUNC) && (tp->t_state & TS_TTSTOP)) {
413 1.6.4.2 rat tp->t_state &= ~TS_TTSTOP;
414 1.6.4.2 rat ttstart (tp);
415 1.6.4.2 rat }
416 1.6.4.2 rat
417 1.6.4.2 rat splx(s);
418 1.6.4.2 rat
419 1.6.4.2 rat /*
420 1.6.4.2 rat * Reset the tty pointer, as there could have been a dialout
421 1.6.4.2 rat * use of the tty with a dialin open waiting.
422 1.6.4.2 rat */
423 1.6.4.2 rat tp->t_dev = dev;
424 1.1 chopps
425 1.6.4.2 rat return((*linesw[tp->t_line].l_open)(dev, tp));
426 1.1 chopps }
427 1.1 chopps
428 1.6.4.2 rat
429 1.1 chopps int
430 1.1 chopps mscclose(dev, flag, mode, p)
431 1.1 chopps dev_t dev;
432 1.1 chopps int flag, mode;
433 1.1 chopps struct proc *p;
434 1.1 chopps {
435 1.6.4.2 rat register struct tty *tp;
436 1.6.4.2 rat int slot;
437 1.6.4.2 rat volatile struct mscstatus *ms;
438 1.6.4.2 rat struct mscdevice *msc;
439 1.1 chopps
440 1.6.4.2 rat /* get the device structure */
441 1.6.4.2 rat slot = MSCSLOT(dev);
442 1.1 chopps
443 1.6.4.2 rat if (slot >= MSCSLOTS)
444 1.6.4.2 rat return ENXIO;
445 1.1 chopps
446 1.6.4.2 rat msc = &mscdev[slot];
447 1.1 chopps
448 1.6.4.2 rat if (!msc->active)
449 1.6.4.2 rat return ENXIO;
450 1.1 chopps
451 1.6.4.2 rat ms = &msc->board->Status[msc->port];
452 1.1 chopps
453 1.6.4.2 rat tp = msc_tty[MSCTTY(dev)];
454 1.6.4.2 rat (*linesw[tp->t_line].l_close)(tp, flag);
455 1.1 chopps
456 1.6.4.2 rat (void) mscmctl(dev, 0, DMSET);
457 1.1 chopps
458 1.6.4.2 rat ttyclose(tp);
459 1.2 chopps
460 1.6.4.2 rat if (msc->flags & TIOCM_DTR)
461 1.6.4.2 rat msc->closing = TRUE; /* flush remaining characters before dropping DTR */
462 1.6.4.2 rat else
463 1.6.4.2 rat ms->OutFlush = TRUE; /* just bitbucket remaining characters */
464 1.1 chopps
465 1.6.4.2 rat return (0);
466 1.1 chopps }
467 1.1 chopps
468 1.6.4.2 rat
469 1.1 chopps int
470 1.1 chopps mscread(dev, uio, flag)
471 1.1 chopps dev_t dev;
472 1.1 chopps struct uio *uio;
473 1.1 chopps int flag;
474 1.1 chopps {
475 1.1 chopps register struct tty *tp;
476 1.1 chopps
477 1.1 chopps tp = msc_tty[MSCTTY(dev)];
478 1.1 chopps
479 1.1 chopps if (! tp)
480 1.1 chopps return ENXIO;
481 1.1 chopps
482 1.1 chopps return((*linesw[tp->t_line].l_read)(tp, uio, flag));
483 1.1 chopps }
484 1.1 chopps
485 1.6.4.2 rat
486 1.1 chopps int
487 1.1 chopps mscwrite(dev, uio, flag)
488 1.1 chopps dev_t dev;
489 1.1 chopps struct uio *uio;
490 1.1 chopps int flag;
491 1.1 chopps {
492 1.6.4.2 rat register struct tty *tp;
493 1.1 chopps
494 1.6.4.2 rat tp = msc_tty[MSCTTY(dev)];
495 1.1 chopps
496 1.6.4.2 rat if (! tp)
497 1.6.4.2 rat return ENXIO;
498 1.1 chopps
499 1.6.4.2 rat return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
500 1.1 chopps }
501 1.1 chopps
502 1.6.4.2 rat
503 1.1 chopps /*
504 1.1 chopps * This interrupt is periodically invoked in the vertical blank
505 1.1 chopps * interrupt. It's used to keep track of the modem control lines
506 1.1 chopps * and (new with the fast_int code) to move accumulated data up in
507 1.1 chopps * to the tty layer.
508 1.1 chopps *
509 1.1 chopps * NOTE: MSCCDHACK is an invention of mine for dubious purposes. If you
510 1.1 chopps * want to activate it add
511 1.1 chopps * options MSCCDHACK
512 1.1 chopps * in the kernel conf file. Basically it forces CD->Low transitions
513 1.1 chopps * to ALWAYS send a signal to the process, even if the device is in
514 1.1 chopps * clocal mode or an outdial device. RFH
515 1.1 chopps */
516 1.1 chopps void
517 1.1 chopps mscmint (data)
518 1.1 chopps register void *data;
519 1.1 chopps {
520 1.6.4.2 rat register struct tty *tp;
521 1.6.4.2 rat struct mscdevice *msc;
522 1.6.4.2 rat volatile struct mscstatus *ms;
523 1.6.4.2 rat volatile u_char *ibuf, *cbuf;
524 1.6.4.2 rat unsigned char newhead; /* was int */
525 1.6.4.2 rat unsigned char bufpos; /* was int */
526 1.6.4.2 rat unsigned char ncd, ocd, ccd;
527 1.6.4.2 rat int unit, slot, maxslot;
528 1.6.4.2 rat int s, i;
529 1.6.4.2 rat
530 1.6.4.2 rat unit = (int) data;
531 1.6.4.2 rat
532 1.6.4.2 rat /* check each line on this board */
533 1.6.4.2 rat maxslot = MSCSLOTUL(unit, NUMLINES);
534 1.6.4.2 rat if (maxslot > MSCSLOTS)
535 1.6.4.2 rat maxslot = MSCSLOTS;
536 1.6.4.2 rat
537 1.6.4.2 rat msc = &mscdev[MSCSLOTUL(unit, 0)];
538 1.6.4.2 rat
539 1.6.4.2 rat newhead = msc->board->Common.CDHead;
540 1.6.4.2 rat bufpos = msc->board->Common.CDTail;
541 1.6.4.2 rat if (newhead != bufpos) { /* CD events in queue */
542 1.6.4.2 rat /* set interrupt priority level */
543 1.6.4.2 rat s = spltty();
544 1.6.4.2 rat ocd = msc->board->Common.CDStatus; /* get old status bits */
545 1.6.4.2 rat while (newhead != bufpos) { /* read all events */
546 1.6.4.2 rat ncd = msc->board->CDBuf[bufpos++]; /* get one event */
547 1.6.4.2 rat ccd = ncd ^ ocd; /* mask of changed lines*/
548 1.6.4.2 rat ocd = ncd; /* save new status bits */
549 1.1 chopps #if DEBUG_CD
550 1.6.4.2 rat printf("ocd %02x ncd %02x ccd %02x\n", ocd, ncd, ccd);
551 1.1 chopps #endif
552 1.6.4.2 rat for(i = 0; i < NUMLINES; i++) { /* do for all lines */
553 1.6.4.2 rat if (ccd & 1) { /* this one changed */
554 1.6.4.2 rat msc = &mscdev[MSCSLOTUL(unit, i)];
555 1.6.4.2 rat if (ncd & 1) { /* CD is now OFF */
556 1.2 chopps #if DEBUG_CD
557 1.6.4.2 rat printf("msc%d: CD OFF %d\n", unit, msc->port);
558 1.2 chopps #endif
559 1.6.4.2 rat msc->flags &= ~TIOCM_CD;
560 1.6.4.2 rat if ((tp = msc_tty[MSCTTYSLOT(MSCSLOTUL(unit, i))]) &&
561 1.6.4.2 rat (tp->t_state & (TS_ISOPEN | TS_WOPEN))) {
562 1.2 chopps
563 1.2 chopps #ifndef MSCCDHACK
564 1.6.4.2 rat if (MSCDIALIN(tp->t_dev))
565 1.2 chopps #endif
566 1.6.4.2 rat {
567 1.6.4.2 rat if ((*linesw[tp->t_line].l_modem)(tp, 0) == 0) {
568 1.6.4.2 rat /* clear RTS and DTR, bitbucket output */
569 1.6.4.2 rat ms = &msc->board->Status[msc->port];
570 1.6.4.2 rat ms->Command = (ms->Command & ~MSCCMD_CMask) |
571 1.6.4.2 rat MSCCMD_Close;
572 1.6.4.2 rat ms->Setup = TRUE;
573 1.6.4.2 rat msc->flags &= ~(TIOCM_DTR | TIOCM_RTS);
574 1.6.4.2 rat ms->OutFlush = TRUE;
575 1.6.4.2 rat }
576 1.6.4.2 rat }
577 1.6.4.2 rat }
578 1.6.4.2 rat } else { /* CD is now ON */
579 1.6.4.2 rat #if DEBUG_CD
580 1.6.4.2 rat printf("msc%d: CD ON %d\n", unit, msc->port);
581 1.1 chopps #endif
582 1.6.4.2 rat msc->flags |= TIOCM_CD;
583 1.6.4.2 rat if ((tp = msc_tty[MSCTTYSLOT(MSCSLOTUL(unit, i))]) &&
584 1.6.4.2 rat (tp->t_state & (TS_ISOPEN | TS_WOPEN))) {
585 1.6.4.2 rat if (MSCDIALIN(tp->t_dev))
586 1.6.4.2 rat (*linesw[tp->t_line].l_modem)(tp, 1);
587 1.6.4.2 rat } /* if tp valid and port open */
588 1.6.4.2 rat } /* CD on/off */
589 1.6.4.2 rat } /* if CD changed for this line */
590 1.6.4.2 rat ccd >>= 1; ncd >>= 1; /* bit for next line */
591 1.6.4.2 rat } /* for every line */
592 1.6.4.2 rat } /* while events in queue */
593 1.6.4.2 rat msc->board->Common.CDStatus = ocd; /* save new status */
594 1.6.4.2 rat msc->board->Common.CDTail = bufpos; /* remove events */
595 1.6.4.2 rat splx(s);
596 1.6.4.2 rat } /* if events in CD queue */
597 1.1 chopps
598 1.6.4.2 rat for (slot = MSCSLOTUL(unit, 0); slot < maxslot; slot++) {
599 1.6.4.2 rat msc = &mscdev[slot];
600 1.1 chopps
601 1.6.4.2 rat if (!msc->active)
602 1.6.4.2 rat continue;
603 1.1 chopps
604 1.6.4.2 rat tp = msc_tty[MSCTTYSLOT(slot)];
605 1.6.4.2 rat ms = &msc->board->Status[msc->port];
606 1.1 chopps
607 1.6.4.2 rat newhead = ms->InHead; /* 65c02 write pointer */
608 1.1 chopps
609 1.6.4.2 rat /* yoohoo, is the port open? */
610 1.6.4.2 rat if (tp && (tp->t_state & (TS_ISOPEN|TS_WOPEN))) {
611 1.6.4.2 rat /* port is open, handle all type of events */
612 1.1 chopps
613 1.6.4.2 rat /* set interrupt priority level */
614 1.6.4.2 rat s = spltty();
615 1.1 chopps
616 1.6.4.2 rat /* check for input for this port */
617 1.6.4.2 rat if (newhead != (bufpos = ms->InTail)) {
618 1.6.4.2 rat /* buffer for input chars/events */
619 1.6.4.2 rat ibuf = &msc->board->InBuf[msc->port][0];
620 1.1 chopps
621 1.6.4.2 rat /* data types of bytes in ibuf */
622 1.6.4.2 rat cbuf = &msc->board->InCtl[msc->port][0];
623 1.1 chopps
624 1.6.4.2 rat /* do for all chars, if room */
625 1.6.4.2 rat while (bufpos != newhead) {
626 1.6.4.2 rat /* which type of input data? */
627 1.6.4.2 rat switch (cbuf[bufpos]) {
628 1.6.4.2 rat /* input event (CD, BREAK, etc.) */
629 1.6.4.2 rat case MSCINCTL_EVENT:
630 1.6.4.2 rat switch (ibuf[bufpos++]) {
631 1.6.4.2 rat case MSCEVENT_Break:
632 1.6.4.2 rat (*linesw[tp->t_line].l_rint)(TTY_FE, tp);
633 1.6.4.2 rat break;
634 1.6.4.2 rat
635 1.6.4.2 rat default:
636 1.6.4.2 rat printf("msc%d: unknown event type %d\n",
637 1.6.4.2 rat msc->unit, ibuf[(bufpos-1)&0xff]);
638 1.6.4.2 rat } /* event type switch */
639 1.6.4.2 rat break;
640 1.6.4.2 rat
641 1.6.4.2 rat case MSCINCTL_CHAR:
642 1.6.4.2 rat if (tp->t_state & TS_TBLOCK) {
643 1.6.4.2 rat goto NoRoomForYa;
644 1.6.4.2 rat }
645 1.6.4.2 rat (*linesw[tp->t_line].l_rint)((int)ibuf[bufpos++], tp);
646 1.6.4.2 rat break;
647 1.1 chopps
648 1.6.4.2 rat default:
649 1.6.4.2 rat printf("msc%d: unknown data type %d\n",
650 1.6.4.2 rat msc->unit, cbuf[bufpos]);
651 1.6.4.2 rat bufpos++;
652 1.6.4.2 rat } /* switch on input data type */
653 1.6.4.2 rat } /* while there's something in the buffer */
654 1.6.4.2 rat NoRoomForYa:
655 1.6.4.2 rat ms->InTail = bufpos; /* tell 65C02 what we've read */
656 1.6.4.2 rat } /* if there was something in the buffer */
657 1.1 chopps
658 1.6.4.2 rat /* we get here only when the port is open */
659 1.6.4.2 rat /* send output */
660 1.6.4.2 rat if (tp->t_state & (TS_BUSY|TS_FLUSH)) {
661 1.6.4.2 rat
662 1.6.4.2 rat bufpos = ms->OutHead - ms->OutTail;
663 1.6.4.2 rat
664 1.6.4.2 rat /* busy and below low water mark? */
665 1.6.4.2 rat if (tp->t_state & TS_BUSY) {
666 1.6.4.2 rat if (bufpos < IOBUFLOWWATER) {
667 1.6.4.2 rat tp->t_state &= ~TS_BUSY; /* not busy any more */
668 1.6.4.2 rat if (tp->t_line)
669 1.6.4.2 rat (*linesw[tp->t_line].l_start)(tp);
670 1.6.4.2 rat else
671 1.6.4.2 rat mscstart(tp);
672 1.6.4.2 rat }
673 1.6.4.2 rat }
674 1.1 chopps
675 1.6.4.2 rat /* waiting for flush and buffer empty? */
676 1.6.4.2 rat if (tp->t_state & TS_FLUSH) {
677 1.6.4.2 rat if (bufpos == 0)
678 1.6.4.2 rat tp->t_state &= ~TS_FLUSH; /* finished flushing */
679 1.6.4.2 rat }
680 1.6.4.2 rat } /* BUSY or FLUSH */
681 1.1 chopps
682 1.6.4.2 rat splx(s);
683 1.1 chopps
684 1.6.4.2 rat } else { /* End of port open */
685 1.6.4.2 rat /* port is closed, don't pass on the chars from it */
686 1.1 chopps
687 1.6.4.2 rat /* check for input for this port */
688 1.6.4.2 rat if (newhead != (bufpos = ms->InTail)) {
689 1.6.4.2 rat /* buffer for input chars/events */
690 1.6.4.2 rat ibuf = &msc->board->InBuf[msc->port][0];
691 1.1 chopps
692 1.6.4.2 rat /* data types of bytes in ibuf */
693 1.6.4.2 rat cbuf = &msc->board->InCtl[msc->port][0];
694 1.6.4.2 rat
695 1.6.4.2 rat /* do for all chars, if room */
696 1.6.4.2 rat while (bufpos != newhead) {
697 1.6.4.2 rat /* which type of input data? */
698 1.6.4.2 rat switch (cbuf[bufpos]) {
699 1.6.4.2 rat /* input event (BREAK, etc.) */
700 1.6.4.2 rat case MSCINCTL_EVENT:
701 1.6.4.2 rat switch (ibuf[bufpos++]) {
702 1.6.4.2 rat default:
703 1.6.4.2 rat printf("msc: unknown event type %d\n",
704 1.6.4.2 rat ibuf[(bufpos-1)&0xff]);
705 1.6.4.2 rat } /* event type switch */
706 1.6.4.2 rat break;
707 1.6.4.2 rat
708 1.6.4.2 rat default:
709 1.6.4.2 rat bufpos++;
710 1.6.4.2 rat } /* switch on input data type */
711 1.6.4.2 rat } /* while there's something in the buffer */
712 1.6.4.2 rat
713 1.6.4.2 rat ms->InTail = bufpos; /* tell 65C02 what we've read */
714 1.6.4.2 rat } /* if there was something in the buffer */
715 1.6.4.2 rat } /* End of port open/close */
716 1.6.4.2 rat
717 1.6.4.2 rat /* is this port closing? */
718 1.6.4.2 rat if (msc->closing) {
719 1.6.4.2 rat /* if DTR is off, just bitbucket remaining characters */
720 1.6.4.2 rat if ( (msc->flags & TIOCM_DTR) == 0) {
721 1.6.4.2 rat ms->OutFlush = TRUE;
722 1.6.4.2 rat msc->closing = FALSE;
723 1.6.4.2 rat }
724 1.6.4.2 rat /* if output has drained, drop DTR */
725 1.6.4.2 rat else if (ms->OutHead == ms->OutTail) {
726 1.6.4.2 rat (void) mscmctl(tp->t_dev, 0, DMSET);
727 1.6.4.2 rat msc->closing = FALSE;
728 1.6.4.2 rat }
729 1.1 chopps }
730 1.6.4.2 rat } /* For all ports */
731 1.1 chopps }
732 1.1 chopps
733 1.6.4.2 rat
734 1.1 chopps int
735 1.1 chopps mscioctl(dev, cmd, data, flag, p)
736 1.1 chopps dev_t dev;
737 1.6 veego u_long cmd;
738 1.1 chopps caddr_t data;
739 1.1 chopps int flag;
740 1.1 chopps struct proc *p;
741 1.1 chopps {
742 1.6.4.2 rat register struct tty *tp;
743 1.6.4.2 rat register int slot;
744 1.6.4.2 rat register int error;
745 1.6.4.2 rat struct mscdevice *msc;
746 1.6.4.2 rat volatile struct mscstatus *ms;
747 1.6.4.2 rat int s;
748 1.1 chopps
749 1.6.4.2 rat /* get the device structure */
750 1.6.4.2 rat slot = MSCSLOT(dev);
751 1.1 chopps
752 1.6.4.2 rat if (slot >= MSCSLOTS)
753 1.6.4.2 rat return ENXIO;
754 1.1 chopps
755 1.6.4.2 rat msc = &mscdev[slot];
756 1.1 chopps
757 1.6.4.2 rat if (!msc->active)
758 1.6.4.2 rat return ENXIO;
759 1.1 chopps
760 1.6.4.2 rat ms = &msc->board->Status[msc->port];
761 1.6.4.2 rat if (!(tp = msc_tty[MSCTTY(dev)]))
762 1.6.4.2 rat return ENXIO;
763 1.1 chopps
764 1.6.4.2 rat error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
765 1.1 chopps
766 1.6.4.2 rat if (error >= 0)
767 1.6.4.2 rat return (error);
768 1.1 chopps
769 1.6.4.2 rat error = ttioctl(tp, cmd, data, flag, p);
770 1.1 chopps
771 1.6.4.2 rat if (error >= 0)
772 1.6.4.2 rat return (error);
773 1.1 chopps
774 1.6.4.2 rat switch (cmd) {
775 1.1 chopps
776 1.6.4.2 rat /* send break */
777 1.6.4.2 rat case TIOCSBRK:
778 1.6.4.2 rat s = spltty();
779 1.6.4.2 rat ms->Command = (ms->Command & (~MSCCMD_RTSMask)) | MSCCMD_Break;
780 1.6.4.2 rat ms->Setup = TRUE;
781 1.6.4.2 rat splx(s);
782 1.6.4.2 rat break;
783 1.6.4.2 rat
784 1.6.4.2 rat /* clear break */
785 1.6.4.2 rat case TIOCCBRK:
786 1.6.4.2 rat s = spltty();
787 1.6.4.2 rat ms->Command = (ms->Command & (~MSCCMD_RTSMask)) | MSCCMD_RTSOn;
788 1.6.4.2 rat ms->Setup = TRUE;
789 1.6.4.2 rat splx(s);
790 1.6.4.2 rat break;
791 1.6.4.2 rat
792 1.6.4.2 rat case TIOCSDTR:
793 1.6.4.2 rat (void) mscmctl(dev, TIOCM_DTR | TIOCM_RTS, DMBIS);
794 1.6.4.2 rat break;
795 1.1 chopps
796 1.6.4.2 rat case TIOCCDTR:
797 1.6.4.2 rat if (!MSCDIALIN(dev)) /* don't let dialins drop DTR */
798 1.6.4.2 rat (void) mscmctl(dev, TIOCM_DTR | TIOCM_RTS, DMBIC);
799 1.6.4.2 rat break;
800 1.1 chopps
801 1.6.4.2 rat case TIOCMSET:
802 1.6.4.2 rat (void) mscmctl(dev, *(int *)data, DMSET);
803 1.6.4.2 rat break;
804 1.1 chopps
805 1.6.4.2 rat case TIOCMBIS:
806 1.6.4.2 rat (void) mscmctl(dev, *(int *)data, DMBIS);
807 1.6.4.2 rat break;
808 1.1 chopps
809 1.6.4.2 rat case TIOCMBIC:
810 1.6.4.2 rat if (MSCDIALIN(dev)) /* don't let dialins drop DTR */
811 1.6.4.2 rat (void) mscmctl(dev, *(int *)data & TIOCM_DTR, DMBIC);
812 1.6.4.2 rat else
813 1.6.4.2 rat (void) mscmctl(dev, *(int *)data, DMBIC);
814 1.6.4.2 rat break;
815 1.1 chopps
816 1.6.4.2 rat case TIOCMGET:
817 1.6.4.2 rat *(int *)data = mscmctl(dev, 0, DMGET);
818 1.6.4.2 rat break;
819 1.1 chopps
820 1.6.4.2 rat case TIOCGFLAGS:
821 1.6.4.2 rat *(int *)data = SWFLAGS(dev);
822 1.6.4.2 rat break;
823 1.1 chopps
824 1.6.4.2 rat case TIOCSFLAGS:
825 1.6.4.2 rat error = suser(p->p_ucred, &p->p_acflag);
826 1.6.4.2 rat if (error != 0)
827 1.6.4.2 rat return(EPERM);
828 1.6.4.2 rat msc->openflags = *(int *)data;
829 1.6.4.2 rat /* only allow valid flags */
830 1.6.4.2 rat msc->openflags &=
831 1.6.4.2 rat (TIOCFLAG_SOFTCAR | TIOCFLAG_CLOCAL | TIOCFLAG_CRTSCTS);
832 1.6.4.2 rat break;
833 1.1 chopps
834 1.6.4.2 rat default:
835 1.6.4.2 rat return (ENOTTY);
836 1.6.4.2 rat }
837 1.1 chopps
838 1.6.4.2 rat return (0);
839 1.1 chopps }
840 1.1 chopps
841 1.1 chopps
842 1.1 chopps int
843 1.1 chopps mscparam(tp, t)
844 1.1 chopps register struct tty *tp;
845 1.1 chopps register struct termios *t;
846 1.1 chopps {
847 1.6.4.2 rat register int cflag = t->c_cflag;
848 1.6.4.2 rat struct mscdevice *msc;
849 1.6.4.2 rat volatile struct mscstatus *ms;
850 1.6.4.2 rat int s, slot;
851 1.6.4.2 rat int ospeed = ttspeedtab(t->c_ospeed, mscspeedtab);
852 1.1 chopps
853 1.6.4.2 rat /* get the device structure */
854 1.6.4.2 rat slot = MSCSLOT(tp->t_dev);
855 1.1 chopps
856 1.6.4.2 rat if (slot >= MSCSLOTS)
857 1.6.4.2 rat return ENXIO;
858 1.1 chopps
859 1.6.4.2 rat msc = &mscdev[slot];
860 1.1 chopps
861 1.6.4.2 rat if (!msc->active)
862 1.6.4.2 rat return ENXIO;
863 1.1 chopps
864 1.6.4.2 rat ms = &msc->board->Status[msc->port];
865 1.1 chopps
866 1.6.4.2 rat /* check requested parameters */
867 1.6.4.2 rat if (ospeed < 0 || (t->c_ispeed && t->c_ispeed != t->c_ospeed))
868 1.6.4.2 rat return (EINVAL);
869 1.2 chopps
870 1.6.4.2 rat /* and copy to tty */
871 1.6.4.2 rat tp->t_ispeed = t->c_ispeed;
872 1.6.4.2 rat tp->t_ospeed = t->c_ospeed;
873 1.6.4.2 rat tp->t_cflag = cflag;
874 1.1 chopps
875 1.6.4.2 rat /* hang up if baud is zero */
876 1.6.4.2 rat if (t->c_ospeed == 0) {
877 1.6.4.2 rat if (!MSCDIALIN(tp->t_dev)) /* don't let dialins drop DTR */
878 1.6.4.2 rat (void) mscmctl(tp->t_dev, 0, DMSET);
879 1.6.4.2 rat } else {
880 1.6.4.2 rat /* set the baud rate */
881 1.6.4.2 rat s = spltty();
882 1.6.4.2 rat ms->Param = (ms->Param & ~MSCPARAM_BaudMask) | ospeed | MSCPARAM_RcvBaud;
883 1.6.4.2 rat
884 1.6.4.2 rat /*
885 1.6.4.2 rat * Make sure any previous hangup is undone, ie. reenable DTR.
886 1.6.4.2 rat * also mscmctl will cause the speed to be set
887 1.6.4.2 rat */
888 1.6.4.2 rat (void) mscmctl (tp->t_dev, TIOCM_DTR | TIOCM_RTS, DMSET);
889 1.1 chopps
890 1.6.4.2 rat splx(s);
891 1.6.4.2 rat }
892 1.6.4.2 rat
893 1.6.4.2 rat return(0);
894 1.1 chopps }
895 1.1 chopps
896 1.1 chopps
897 1.1 chopps /*
898 1.1 chopps * Jukka's code initializes alot of stuff that other drivers don't
899 1.1 chopps * I'm including it here so that this code is a common set of work
900 1.1 chopps * done by both of us. rfh
901 1.1 chopps */
902 1.1 chopps int
903 1.1 chopps mschwiflow(tp, flag)
904 1.1 chopps struct tty *tp;
905 1.1 chopps int flag;
906 1.1 chopps {
907 1.1 chopps
908 1.1 chopps /* Rob's version */
909 1.1 chopps #if 1
910 1.1 chopps if (flag)
911 1.6.4.2 rat mscmctl( tp->t_dev, TIOCM_RTS, DMBIC); /* Clear/Lower RTS */
912 1.1 chopps else
913 1.6.4.2 rat mscmctl( tp->t_dev, TIOCM_RTS, DMBIS); /* Set/Raise RTS */
914 1.1 chopps
915 1.6.4.2 rat #else /* Jukka's version */
916 1.1 chopps
917 1.6.4.2 rat int s, slot;
918 1.6.4.2 rat struct mscdevice *msc;
919 1.6.4.2 rat volatile struct mscstatus *ms;
920 1.1 chopps
921 1.6.4.2 rat /* get the device structure */
922 1.6.4.2 rat slot = MSCSLOT(tp->t_dev);
923 1.6.4.2 rat if (slot >= MSCSLOTS)
924 1.6.4.2 rat return ENXIO;
925 1.6.4.2 rat msc = &mscdev[slot];
926 1.6.4.2 rat if (!msc->active)
927 1.6.4.2 rat return ENXIO;
928 1.6.4.2 rat ms = &msc->board->Status[msc->port];
929 1.6.4.2 rat
930 1.6.4.2 rat /* Well, we should really _do_ something here, but the 65c02 code
931 1.6.4.2 rat * manages the RTS signal on its own now, so... This will probably
932 1.6.4.2 rat * change in the future.
933 1.6.4.2 rat */
934 1.1 chopps #endif
935 1.1 chopps return 1;
936 1.1 chopps }
937 1.1 chopps
938 1.6.4.2 rat
939 1.6 veego void
940 1.1 chopps mscstart(tp)
941 1.1 chopps register struct tty *tp;
942 1.1 chopps {
943 1.6.4.2 rat register int cc;
944 1.6.4.2 rat register char *cp;
945 1.6.4.2 rat register int mhead;
946 1.6.4.2 rat int s, slot;
947 1.6.4.2 rat struct mscdevice *msc;
948 1.6.4.2 rat volatile struct mscstatus *ms;
949 1.6.4.2 rat volatile char *mob;
950 1.6.4.2 rat int hiwat = 0;
951 1.6.4.2 rat int maxout;
952 1.1 chopps
953 1.6.4.2 rat if (! (tp->t_state & TS_ISOPEN))
954 1.6.4.2 rat return;
955 1.1 chopps
956 1.6.4.2 rat slot = MSCSLOT(tp->t_dev);
957 1.1 chopps
958 1.1 chopps #if 0
959 1.6.4.2 rat printf("starting msc%d\n", slot);
960 1.1 chopps #endif
961 1.1 chopps
962 1.6.4.2 rat s = spltty();
963 1.1 chopps
964 1.6.4.2 rat /* don't start if explicitly stopped */
965 1.6.4.2 rat if (tp->t_state & (TS_TIMEOUT|TS_TTSTOP))
966 1.6.4.2 rat goto out;
967 1.6.4.2 rat
968 1.6.4.2 rat /* wake up if below low water */
969 1.6.4.2 rat cc = tp->t_outq.c_cc;
970 1.6.4.2 rat
971 1.6.4.2 rat if (cc <= tp->t_lowat) {
972 1.6.4.2 rat if (tp->t_state & TS_ASLEEP) {
973 1.6.4.2 rat tp->t_state &= ~TS_ASLEEP;
974 1.6.4.2 rat wakeup((caddr_t)&tp->t_outq);
975 1.6.4.2 rat }
976 1.6.4.2 rat selwakeup(&tp->t_wsel);
977 1.1 chopps }
978 1.1 chopps
979 1.6.4.2 rat /* don't bother if no characters or busy */
980 1.6.4.2 rat if (cc == 0 || (tp->t_state & TS_BUSY))
981 1.6.4.2 rat goto out;
982 1.6.4.2 rat
983 1.6.4.2 rat /*
984 1.6.4.2 rat * Limit the amount of output we do in one burst
985 1.6.4.2 rat */
986 1.6.4.2 rat msc = &mscdev[slot];
987 1.6.4.2 rat ms = &msc->board->Status[msc->port];
988 1.6.4.2 rat mhead = ms->OutHead;
989 1.6.4.2 rat maxout = mhead - ms->OutTail;
990 1.6.4.2 rat
991 1.6.4.2 rat if (maxout < 0)
992 1.6.4.2 rat maxout += IOBUFLEN;
993 1.6.4.2 rat
994 1.6.4.2 rat maxout = IOBUFLEN - 1 - maxout;
995 1.6.4.2 rat
996 1.6.4.2 rat if (cc >= maxout) {
997 1.6.4.2 rat hiwat++;
998 1.6.4.2 rat cc = maxout;
999 1.6.4.2 rat }
1000 1.1 chopps
1001 1.6.4.2 rat cc = q_to_b (&tp->t_outq, msc->tmpbuf, cc);
1002 1.1 chopps
1003 1.6.4.2 rat if (cc > 0) {
1004 1.6.4.2 rat tp->t_state |= TS_BUSY;
1005 1.1 chopps
1006 1.6.4.2 rat mob = &msc->board->OutBuf[msc->port][0];
1007 1.6.4.2 rat cp = &msc->tmpbuf[0];
1008 1.1 chopps
1009 1.6.4.2 rat /* enable output */
1010 1.6.4.2 rat ms->OutDisable = FALSE;
1011 1.1 chopps
1012 1.1 chopps #if 0
1013 1.6.4.2 rat msc->tmpbuf[cc] = 0;
1014 1.6.4.2 rat printf("sending '%s'\n", msctmpbuf);
1015 1.1 chopps #endif
1016 1.1 chopps
1017 1.6.4.2 rat /* send the first char across to reduce latency */
1018 1.6.4.2 rat mob[mhead++] = *cp++;
1019 1.6.4.2 rat mhead &= IOBUFLENMASK;
1020 1.6.4.2 rat ms->OutHead = mhead;
1021 1.6.4.2 rat cc--;
1022 1.6.4.2 rat
1023 1.6.4.2 rat /* copy the rest of the chars across quickly */
1024 1.6.4.2 rat while (cc > 0) {
1025 1.6.4.2 rat mob[mhead++] = *cp++;
1026 1.6.4.2 rat mhead &= IOBUFLENMASK;
1027 1.6.4.2 rat cc--;
1028 1.6.4.2 rat }
1029 1.6.4.2 rat ms->OutHead = mhead;
1030 1.6.4.2 rat
1031 1.6.4.2 rat /* leave the device busy if we've filled the buffer */
1032 1.6.4.2 rat if (!hiwat)
1033 1.6.4.2 rat tp->t_state &= ~TS_BUSY;
1034 1.6.4.2 rat }
1035 1.1 chopps
1036 1.1 chopps out:
1037 1.6.4.2 rat splx(s);
1038 1.1 chopps }
1039 1.1 chopps
1040 1.6.4.2 rat
1041 1.1 chopps /* XXX */
1042 1.1 chopps /*
1043 1.1 chopps * Stop output on a line.
1044 1.1 chopps */
1045 1.1 chopps /*ARGSUSED*/
1046 1.1 chopps int
1047 1.1 chopps mscstop(tp, flag)
1048 1.1 chopps register struct tty *tp;
1049 1.1 chopps int flag; /* defaulted to int anyway */
1050 1.1 chopps {
1051 1.1 chopps register int s;
1052 1.6 veego #if 0
1053 1.1 chopps struct mscdevice *msc;
1054 1.1 chopps volatile struct mscstatus *ms;
1055 1.6 veego #endif
1056 1.1 chopps
1057 1.1 chopps s = spltty();
1058 1.1 chopps if (tp->t_state & TS_BUSY) {
1059 1.6 veego if ((tp->t_state & TS_TTSTOP) == 0) {
1060 1.1 chopps tp->t_state |= TS_FLUSH;
1061 1.1 chopps #if 0
1062 1.1 chopps msc = &mscdev[MSCSLOT(tp->t_dev)];
1063 1.1 chopps ms = &msc->board->Status[msc->port];
1064 1.1 chopps printf("stopped output on msc%d\n", MSCSLOT(tp->t_dev));
1065 1.1 chopps ms->OutDisable = TRUE;
1066 1.1 chopps #endif
1067 1.1 chopps }
1068 1.1 chopps }
1069 1.1 chopps splx(s);
1070 1.6.4.2 rat return(0);
1071 1.1 chopps }
1072 1.1 chopps
1073 1.6.4.2 rat
1074 1.1 chopps /*
1075 1.1 chopps * bits can be: TIOCM_DTR, TIOCM_RTS, TIOCM_CTS, TIOCM_CD, TIOCM_RI, TIOCM_DSR
1076 1.1 chopps */
1077 1.1 chopps int
1078 1.1 chopps mscmctl(dev, bits, how)
1079 1.1 chopps dev_t dev;
1080 1.1 chopps int bits, how;
1081 1.1 chopps {
1082 1.6.4.2 rat struct mscdevice *msc;
1083 1.6.4.2 rat volatile struct mscstatus *ms;
1084 1.6.4.2 rat int slot;
1085 1.6.4.2 rat int s;
1086 1.6.4.2 rat u_char newcmd;
1087 1.6.4.2 rat int OldFlags;
1088 1.1 chopps
1089 1.6.4.2 rat /* get the device structure */
1090 1.6.4.2 rat slot = MSCSLOT(dev);
1091 1.1 chopps
1092 1.6.4.2 rat if (slot >= MSCSLOTS)
1093 1.6.4.2 rat return ENXIO;
1094 1.1 chopps
1095 1.6.4.2 rat msc = &mscdev[slot];
1096 1.2 chopps
1097 1.6.4.2 rat if (!msc->active)
1098 1.6.4.2 rat return ENXIO;
1099 1.1 chopps
1100 1.6.4.2 rat s = spltty();
1101 1.6.4.2 rat
1102 1.6.4.2 rat if (how != DMGET) {
1103 1.6.4.2 rat OldFlags = msc->flags;
1104 1.6.4.2 rat bits &= TIOCM_DTR | TIOCM_RTS; /* can only modify DTR and RTS */
1105 1.6.4.2 rat
1106 1.6.4.2 rat switch (how) {
1107 1.6.4.2 rat case DMSET:
1108 1.6.4.2 rat msc->flags = (bits | (msc->flags & ~(TIOCM_DTR | TIOCM_RTS)));
1109 1.6.4.2 rat break;
1110 1.1 chopps
1111 1.6.4.2 rat case DMBIC:
1112 1.6.4.2 rat msc->flags &= ~bits;
1113 1.6.4.2 rat break;
1114 1.1 chopps
1115 1.6.4.2 rat case DMBIS:
1116 1.6.4.2 rat msc->flags |= bits;
1117 1.6.4.2 rat break;
1118 1.6.4.2 rat }
1119 1.1 chopps
1120 1.6.4.2 rat /* modify modem control state */
1121 1.6.4.2 rat ms = &msc->board->Status[msc->port];
1122 1.1 chopps
1123 1.6.4.2 rat if (msc->flags & TIOCM_RTS) /* was bits & */
1124 1.6.4.2 rat newcmd = MSCCMD_RTSOn;
1125 1.6.4.2 rat else /* this doesn't actually work now */
1126 1.6.4.2 rat newcmd = MSCCMD_RTSOff;
1127 1.6.4.2 rat
1128 1.6.4.2 rat if (msc->flags & TIOCM_DTR) /* was bits & */
1129 1.6.4.2 rat newcmd |= MSCCMD_Enable;
1130 1.6.4.2 rat
1131 1.6.4.2 rat ms->Command = (ms->Command & (~MSCCMD_RTSMask & ~MSCCMD_Enable)) | newcmd;
1132 1.6.4.2 rat ms->Setup = TRUE;
1133 1.6.4.2 rat
1134 1.6.4.2 rat /* if we've dropped DTR, bitbucket any pending output */
1135 1.6.4.2 rat if ( (OldFlags & TIOCM_DTR) && ((bits & TIOCM_DTR) == 0))
1136 1.6.4.2 rat ms->OutFlush = TRUE;
1137 1.6.4.2 rat }
1138 1.1 chopps
1139 1.6.4.2 rat bits = msc->flags;
1140 1.1 chopps
1141 1.6.4.2 rat (void) splx(s);
1142 1.1 chopps
1143 1.6.4.2 rat return(bits);
1144 1.1 chopps }
1145 1.1 chopps
1146 1.6.4.2 rat
1147 1.1 chopps struct tty *
1148 1.1 chopps msctty(dev)
1149 1.1 chopps dev_t dev;
1150 1.1 chopps {
1151 1.1 chopps return(msc_tty[MSCTTY(dev)]);
1152 1.1 chopps }
1153 1.1 chopps
1154 1.6.4.2 rat
1155 1.1 chopps /*
1156 1.1 chopps * Load JM's freely redistributable A2232 6502c code. Let turbo detector
1157 1.1 chopps * run for a while too.
1158 1.1 chopps */
1159 1.1 chopps
1160 1.1 chopps int
1161 1.1 chopps mscinitcard(zap)
1162 1.1 chopps struct zbus_args *zap;
1163 1.1 chopps {
1164 1.6.4.2 rat int bcount;
1165 1.6.4.2 rat short start;
1166 1.6.4.2 rat u_char *from;
1167 1.6.4.2 rat volatile u_char *to;
1168 1.6.4.2 rat volatile struct mscmemory *mlm;
1169 1.6.4.2 rat
1170 1.6.4.2 rat mlm = (volatile struct mscmemory *)zap->va;
1171 1.6.4.2 rat (void)mlm->Enable6502Reset;
1172 1.6.4.2 rat
1173 1.6.4.2 rat /* copy the code across to the board */
1174 1.6.4.2 rat to = (u_char *)mlm;
1175 1.6.4.2 rat from = msc6502code; bcount = sizeof(msc6502code) - 2;
1176 1.6.4.2 rat start = *(short *)from; from += sizeof(start);
1177 1.6.4.2 rat to += start;
1178 1.6.4.2 rat
1179 1.6.4.2 rat while(bcount--) *to++ = *from++;
1180 1.6.4.2 rat
1181 1.6.4.2 rat mlm->Common.Crystal = MSC_UNKNOWN; /* use automatic speed check */
1182 1.6.4.2 rat
1183 1.6.4.2 rat /* start 6502 running */
1184 1.6.4.2 rat (void)mlm->ResetBoard;
1185 1.6.4.2 rat
1186 1.6.4.2 rat /* wait until speed detector has finished */
1187 1.6.4.2 rat for (bcount = 0; bcount < 200; bcount++) {
1188 1.6.4.2 rat delay(10000);
1189 1.6.4.2 rat if (mlm->Common.Crystal)
1190 1.6.4.2 rat break;
1191 1.6.4.2 rat }
1192 1.1 chopps
1193 1.6.4.2 rat return(0);
1194 1.1 chopps }
1195 1.1 chopps
1196 1.1 chopps #endif /* NMSC > 0 */
1197