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