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