par.c revision 1.8 1 1.1 mw /*
2 1.1 mw * Copyright (c) 1982, 1990 The Regents of the University of California.
3 1.1 mw * All rights reserved.
4 1.1 mw *
5 1.1 mw * Redistribution and use in source and binary forms, with or without
6 1.1 mw * modification, are permitted provided that the following conditions
7 1.1 mw * are met:
8 1.1 mw * 1. Redistributions of source code must retain the above copyright
9 1.1 mw * notice, this list of conditions and the following disclaimer.
10 1.1 mw * 2. Redistributions in binary form must reproduce the above copyright
11 1.1 mw * notice, this list of conditions and the following disclaimer in the
12 1.1 mw * documentation and/or other materials provided with the distribution.
13 1.1 mw * 3. All advertising materials mentioning features or use of this software
14 1.1 mw * must display the following acknowledgement:
15 1.1 mw * This product includes software developed by the University of
16 1.1 mw * California, Berkeley and its contributors.
17 1.1 mw * 4. Neither the name of the University nor the names of its contributors
18 1.1 mw * may be used to endorse or promote products derived from this software
19 1.1 mw * without specific prior written permission.
20 1.1 mw *
21 1.1 mw * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 1.1 mw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 1.1 mw * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.1 mw * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 1.1 mw * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.1 mw * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.1 mw * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.1 mw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.1 mw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.1 mw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.1 mw * SUCH DAMAGE.
32 1.1 mw *
33 1.1 mw * from: @(#)ppi.c 7.3 (Berkeley) 12/16/90
34 1.8 chopps * $Id: par.c,v 1.8 1994/05/31 03:11:44 chopps Exp $
35 1.1 mw */
36 1.1 mw
37 1.1 mw /*
38 1.1 mw * parallel port interface
39 1.1 mw */
40 1.1 mw
41 1.2 mw #include "par.h"
42 1.1 mw #if NPAR > 0
43 1.1 mw
44 1.6 chopps #include <sys/param.h>
45 1.6 chopps #include <sys/errno.h>
46 1.6 chopps #include <sys/uio.h>
47 1.7 chopps #include <sys/device.h>
48 1.6 chopps #include <sys/malloc.h>
49 1.6 chopps #include <sys/file.h>
50 1.6 chopps #include <sys/systm.h>
51 1.1 mw
52 1.7 chopps #include <amiga/amiga/device.h>
53 1.7 chopps #include <amiga/amiga/cia.h>
54 1.6 chopps #include <amiga/dev/parioctl.h>
55 1.1 mw
56 1.1 mw
57 1.1 mw struct par_softc {
58 1.1 mw int sc_flags;
59 1.1 mw struct parparam sc_param;
60 1.1 mw #define sc_burst sc_param.burst
61 1.1 mw #define sc_timo sc_param.timo
62 1.1 mw #define sc_delay sc_param.delay
63 1.7 chopps } *par_softcp;
64 1.7 chopps
65 1.7 chopps #define getparsp(x) (x > 0 ? NULL : par_softcp)
66 1.1 mw
67 1.1 mw /* sc_flags values */
68 1.1 mw #define PARF_ALIVE 0x01
69 1.1 mw #define PARF_OPEN 0x02
70 1.1 mw #define PARF_UIO 0x04
71 1.1 mw #define PARF_TIMO 0x08
72 1.1 mw #define PARF_DELAY 0x10
73 1.1 mw #define PARF_OREAD 0x40
74 1.1 mw #define PARF_OWRITE 0x80
75 1.1 mw
76 1.1 mw #define UNIT(x) minor(x)
77 1.1 mw
78 1.1 mw #ifdef DEBUG
79 1.2 mw int pardebug = 0;
80 1.1 mw #define PDB_FOLLOW 0x01
81 1.1 mw #define PDB_IO 0x02
82 1.2 mw #define PDB_INTERRUPT 0x04
83 1.1 mw #define PDB_NOCHECK 0x80
84 1.1 mw #endif
85 1.1 mw
86 1.7 chopps void partimo __P((void *));
87 1.7 chopps void parstart __P((void *));
88 1.7 chopps void parintr __P((void *));
89 1.7 chopps
90 1.7 chopps void parattach __P((struct device *, struct device *, void *));
91 1.7 chopps int parmatch __P((struct device *, struct cfdata *, void *));
92 1.7 chopps
93 1.7 chopps struct cfdriver parcd = {
94 1.7 chopps NULL, "par", parmatch, parattach, DV_DULL,
95 1.7 chopps sizeof(struct device), NULL, 0 };
96 1.7 chopps
97 1.7 chopps /*ARGSUSED*/
98 1.7 chopps int
99 1.7 chopps parmatch(pdp, cfp, auxp)
100 1.7 chopps struct device *pdp;
101 1.7 chopps struct cfdata *cfp;
102 1.7 chopps void *auxp;
103 1.7 chopps {
104 1.7 chopps if (matchname((char *)auxp, "par") && cfp->cf_unit == 0)
105 1.7 chopps return(1);
106 1.7 chopps return(0);
107 1.7 chopps }
108 1.7 chopps
109 1.7 chopps void
110 1.7 chopps parattach(pdp, dp, auxp)
111 1.7 chopps struct device *pdp, *dp;
112 1.7 chopps void *auxp;
113 1.1 mw {
114 1.7 chopps par_softcp = (struct par_softc *)dp;
115 1.1 mw
116 1.1 mw #ifdef DEBUG
117 1.7 chopps if ((pardebug & PDB_NOCHECK) == 0)
118 1.1 mw #endif
119 1.7 chopps par_softcp->sc_flags = PARF_ALIVE;
120 1.7 chopps printf("\n");
121 1.1 mw }
122 1.1 mw
123 1.1 mw paropen(dev, flags)
124 1.7 chopps dev_t dev;
125 1.1 mw {
126 1.7 chopps int unit = UNIT(dev);
127 1.7 chopps struct par_softc *sc = getparsp(unit);
128 1.1 mw
129 1.7 chopps if (unit >= NPAR || (sc->sc_flags & PARF_ALIVE) == 0)
130 1.7 chopps return(ENXIO);
131 1.1 mw #ifdef DEBUG
132 1.7 chopps if (pardebug & PDB_FOLLOW) {
133 1.7 chopps printf("paropen(%x, %x): flags %x, ",
134 1.7 chopps dev, flags, sc->sc_flags);
135 1.7 chopps printf ("port = $%x\n", ((ciab.pra ^ CIAB_PRA_SEL)
136 1.7 chopps & (CIAB_PRA_SEL|CIAB_PRA_BUSY|CIAB_PRA_POUT)));
137 1.7 chopps }
138 1.1 mw #endif
139 1.7 chopps if (sc->sc_flags & PARF_OPEN)
140 1.7 chopps return(EBUSY);
141 1.7 chopps /* can either read or write, but not both */
142 1.7 chopps if ((flags & (FREAD|FWRITE)) == (FREAD|FWRITE))
143 1.7 chopps return EINVAL;
144 1.1 mw
145 1.7 chopps sc->sc_flags |= PARF_OPEN;
146 1.7 chopps
147 1.7 chopps if (flags & FREAD)
148 1.7 chopps sc->sc_flags |= PARF_OREAD;
149 1.7 chopps else
150 1.7 chopps sc->sc_flags |= PARF_OWRITE;
151 1.7 chopps
152 1.7 chopps sc->sc_burst = PAR_BURST;
153 1.7 chopps sc->sc_timo = parmstohz(PAR_TIMO);
154 1.7 chopps sc->sc_delay = parmstohz(PAR_DELAY);
155 1.7 chopps /* enable interrupts for CIAA-FLG */
156 1.7 chopps ciaa.icr = CIA_ICR_IR_SC | CIA_ICR_FLG;
157 1.7 chopps return(0);
158 1.1 mw }
159 1.1 mw
160 1.1 mw parclose(dev, flags)
161 1.1 mw dev_t dev;
162 1.1 mw {
163 1.7 chopps int unit = UNIT(dev);
164 1.7 chopps struct par_softc *sc = getparsp(unit);
165 1.1 mw
166 1.1 mw #ifdef DEBUG
167 1.1 mw if (pardebug & PDB_FOLLOW)
168 1.1 mw printf("parclose(%x, %x): flags %x\n",
169 1.1 mw dev, flags, sc->sc_flags);
170 1.1 mw #endif
171 1.1 mw sc->sc_flags &= ~(PARF_OPEN|PARF_OREAD|PARF_OWRITE);
172 1.1 mw /* don't allow interrupts for CIAA-FLG any longer */
173 1.1 mw ciaa.icr = CIA_ICR_FLG;
174 1.1 mw return(0);
175 1.1 mw }
176 1.1 mw
177 1.7 chopps void
178 1.7 chopps parstart(arg)
179 1.7 chopps void *arg;
180 1.1 mw {
181 1.7 chopps struct par_softc *sc;
182 1.7 chopps int unit;
183 1.7 chopps
184 1.7 chopps unit = (int)arg;
185 1.7 chopps sc = getparsp(unit);
186 1.1 mw #ifdef DEBUG
187 1.7 chopps if (pardebug & PDB_FOLLOW)
188 1.7 chopps printf("parstart(%x)\n", unit);
189 1.1 mw #endif
190 1.7 chopps sc->sc_flags &= ~PARF_DELAY;
191 1.7 chopps wakeup(sc);
192 1.1 mw }
193 1.1 mw
194 1.7 chopps void
195 1.7 chopps partimo(arg)
196 1.7 chopps void *arg;
197 1.1 mw {
198 1.7 chopps struct par_softc *sc;
199 1.7 chopps int unit;
200 1.7 chopps
201 1.7 chopps unit = (int) arg;
202 1.7 chopps sc = getparsp(unit);
203 1.1 mw #ifdef DEBUG
204 1.7 chopps if (pardebug & PDB_FOLLOW)
205 1.7 chopps printf("partimo(%x)\n", unit);
206 1.1 mw #endif
207 1.7 chopps sc->sc_flags &= ~(PARF_UIO|PARF_TIMO);
208 1.7 chopps wakeup(sc);
209 1.1 mw }
210 1.1 mw
211 1.1 mw parread(dev, uio)
212 1.1 mw dev_t dev;
213 1.1 mw struct uio *uio;
214 1.1 mw {
215 1.1 mw
216 1.1 mw #ifdef DEBUG
217 1.1 mw if (pardebug & PDB_FOLLOW)
218 1.1 mw printf("parread(%x, %x)\n", dev, uio);
219 1.1 mw #endif
220 1.1 mw return (parrw(dev, uio));
221 1.1 mw }
222 1.1 mw
223 1.1 mw parwrite(dev, uio)
224 1.1 mw dev_t dev;
225 1.1 mw struct uio *uio;
226 1.1 mw {
227 1.1 mw
228 1.1 mw #ifdef DEBUG
229 1.1 mw if (pardebug & PDB_FOLLOW)
230 1.1 mw printf("parwrite(%x, %x)\n", dev, uio);
231 1.1 mw #endif
232 1.1 mw return (parrw(dev, uio));
233 1.1 mw }
234 1.1 mw
235 1.1 mw parrw(dev, uio)
236 1.1 mw dev_t dev;
237 1.1 mw register struct uio *uio;
238 1.1 mw {
239 1.1 mw int unit = UNIT(dev);
240 1.7 chopps register struct par_softc *sc = getparsp(unit);
241 1.1 mw register int s, len, cnt;
242 1.1 mw register char *cp;
243 1.1 mw int error = 0, gotdata = 0;
244 1.1 mw int buflen;
245 1.1 mw char *buf;
246 1.1 mw
247 1.2 mw if (!!(sc->sc_flags & PARF_OREAD) ^ (uio->uio_rw == UIO_READ))
248 1.1 mw return EINVAL;
249 1.1 mw
250 1.1 mw if (uio->uio_resid == 0)
251 1.1 mw return(0);
252 1.1 mw
253 1.1 mw #ifdef DEBUG
254 1.1 mw if (pardebug & (PDB_FOLLOW|PDB_IO))
255 1.1 mw printf("parrw(%x, %x, %c): burst %d, timo %d, resid %x\n",
256 1.1 mw dev, uio, uio->uio_rw == UIO_READ ? 'R' : 'W',
257 1.1 mw sc->sc_burst, sc->sc_timo, uio->uio_resid);
258 1.1 mw #endif
259 1.8 chopps buflen = min(sc->sc_burst, uio->uio_resid);
260 1.1 mw buf = (char *)malloc(buflen, M_DEVBUF, M_WAITOK);
261 1.1 mw sc->sc_flags |= PARF_UIO;
262 1.2 mw if (sc->sc_timo > 0)
263 1.2 mw {
264 1.2 mw sc->sc_flags |= PARF_TIMO;
265 1.7 chopps timeout(partimo, (void *)unit, sc->sc_timo);
266 1.1 mw }
267 1.2 mw while (uio->uio_resid > 0)
268 1.2 mw {
269 1.8 chopps len = min(buflen, uio->uio_resid);
270 1.2 mw cp = buf;
271 1.2 mw if (uio->uio_rw == UIO_WRITE)
272 1.2 mw {
273 1.2 mw error = uiomove(cp, len, uio);
274 1.2 mw if (error)
275 1.2 mw break;
276 1.2 mw }
277 1.2 mw again:
278 1.2 mw s = splbio();
279 1.2 mw #if 0
280 1.2 mw if ((sc->sc_flags & PARF_UIO) && hpibreq(&sc->sc_dq) == 0)
281 1.2 mw sleep(sc, PRIBIO+1);
282 1.2 mw #endif
283 1.2 mw /*
284 1.2 mw * Check if we timed out during sleep or uiomove
285 1.2 mw */
286 1.2 mw (void) splsoftclock();
287 1.2 mw if ((sc->sc_flags & PARF_UIO) == 0)
288 1.2 mw {
289 1.2 mw #ifdef DEBUG
290 1.2 mw if (pardebug & PDB_IO)
291 1.2 mw printf("parrw: uiomove/sleep timo, flags %x\n",
292 1.2 mw sc->sc_flags);
293 1.2 mw #endif
294 1.2 mw if (sc->sc_flags & PARF_TIMO)
295 1.2 mw {
296 1.7 chopps untimeout(partimo, (void *)unit);
297 1.2 mw sc->sc_flags &= ~PARF_TIMO;
298 1.2 mw }
299 1.2 mw splx(s);
300 1.2 mw break;
301 1.2 mw }
302 1.2 mw splx(s);
303 1.2 mw /*
304 1.2 mw * Perform the operation
305 1.2 mw */
306 1.2 mw if (uio->uio_rw == UIO_WRITE)
307 1.2 mw cnt = parsend (cp, len);
308 1.2 mw else
309 1.2 mw cnt = parreceive (cp, len);
310 1.2 mw
311 1.2 mw if (cnt < 0)
312 1.2 mw {
313 1.2 mw error = -cnt;
314 1.2 mw break;
315 1.2 mw }
316 1.2 mw
317 1.2 mw s = splbio();
318 1.1 mw #if 0
319 1.2 mw hpibfree(&sc->sc_dq);
320 1.1 mw #endif
321 1.1 mw #ifdef DEBUG
322 1.1 mw if (pardebug & PDB_IO)
323 1.2 mw printf("parrw: %s(%x, %d) -> %d\n",
324 1.2 mw uio->uio_rw == UIO_READ ? "recv" : "send", cp, len, cnt);
325 1.1 mw #endif
326 1.1 mw splx(s);
327 1.2 mw if (uio->uio_rw == UIO_READ)
328 1.2 mw {
329 1.2 mw if (cnt)
330 1.2 mw {
331 1.2 mw error = uiomove(cp, cnt, uio);
332 1.2 mw if (error)
333 1.2 mw break;
334 1.2 mw gotdata++;
335 1.2 mw }
336 1.2 mw /*
337 1.2 mw * Didn't get anything this time, but did in the past.
338 1.2 mw * Consider us done.
339 1.2 mw */
340 1.2 mw else if (gotdata)
341 1.2 mw break;
342 1.2 mw }
343 1.2 mw s = splsoftclock();
344 1.1 mw /*
345 1.2 mw * Operation timeout (or non-blocking), quit now.
346 1.1 mw */
347 1.2 mw if ((sc->sc_flags & PARF_UIO) == 0)
348 1.2 mw {
349 1.1 mw #ifdef DEBUG
350 1.2 mw if (pardebug & PDB_IO)
351 1.2 mw printf("parrw: timeout/done\n");
352 1.1 mw #endif
353 1.2 mw splx(s);
354 1.2 mw break;
355 1.2 mw }
356 1.2 mw /*
357 1.2 mw * Implement inter-read delay
358 1.2 mw */
359 1.2 mw if (sc->sc_delay > 0)
360 1.2 mw {
361 1.2 mw sc->sc_flags |= PARF_DELAY;
362 1.7 chopps timeout(parstart, (void *)unit, sc->sc_delay);
363 1.7 chopps error = tsleep(sc, PCATCH|PZERO-1, "par-cdelay", 0);
364 1.2 mw if (error)
365 1.2 mw {
366 1.2 mw splx(s);
367 1.2 mw break;
368 1.2 mw }
369 1.2 mw }
370 1.1 mw splx(s);
371 1.2 mw /*
372 1.2 mw * Must not call uiomove again til we've used all data
373 1.2 mw * that we already grabbed.
374 1.2 mw */
375 1.2 mw if (uio->uio_rw == UIO_WRITE && cnt != len)
376 1.2 mw {
377 1.2 mw cp += cnt;
378 1.2 mw len -= cnt;
379 1.2 mw cnt = 0;
380 1.2 mw goto again;
381 1.2 mw }
382 1.1 mw }
383 1.2 mw s = splsoftclock();
384 1.2 mw if (sc->sc_flags & PARF_TIMO)
385 1.2 mw {
386 1.7 chopps untimeout(partimo, (void *)unit);
387 1.2 mw sc->sc_flags &= ~PARF_TIMO;
388 1.1 mw }
389 1.2 mw if (sc->sc_flags & PARF_DELAY)
390 1.2 mw {
391 1.7 chopps untimeout(parstart, (void *)unit);
392 1.2 mw sc->sc_flags &= ~PARF_DELAY;
393 1.1 mw }
394 1.1 mw splx(s);
395 1.1 mw /*
396 1.1 mw * Adjust for those chars that we uiomove'ed but never wrote
397 1.1 mw */
398 1.2 mw if (uio->uio_rw == UIO_WRITE && cnt != len)
399 1.2 mw {
400 1.2 mw uio->uio_resid += (len - cnt);
401 1.1 mw #ifdef DEBUG
402 1.2 mw if (pardebug & PDB_IO)
403 1.2 mw printf("parrw: short write, adjust by %d\n",
404 1.2 mw len-cnt);
405 1.1 mw #endif
406 1.2 mw }
407 1.1 mw free(buf, M_DEVBUF);
408 1.1 mw #ifdef DEBUG
409 1.1 mw if (pardebug & (PDB_FOLLOW|PDB_IO))
410 1.1 mw printf("parrw: return %d, resid %d\n", error, uio->uio_resid);
411 1.1 mw #endif
412 1.1 mw return (error);
413 1.1 mw }
414 1.1 mw
415 1.2 mw int
416 1.5 chopps parioctl(dev, cmd, data, flag, p)
417 1.5 chopps dev_t dev;
418 1.5 chopps int cmd;
419 1.5 chopps caddr_t data;
420 1.5 chopps int flag;
421 1.5 chopps struct proc *p;
422 1.1 mw {
423 1.7 chopps struct par_softc *sc = getparsp(UNIT(dev));
424 1.1 mw struct parparam *pp, *upp;
425 1.1 mw int error = 0;
426 1.1 mw
427 1.2 mw switch (cmd)
428 1.2 mw {
429 1.2 mw case PARIOCGPARAM:
430 1.2 mw pp = &sc->sc_param;
431 1.2 mw upp = (struct parparam *)data;
432 1.2 mw upp->burst = pp->burst;
433 1.2 mw upp->timo = parhztoms(pp->timo);
434 1.2 mw upp->delay = parhztoms(pp->delay);
435 1.2 mw break;
436 1.2 mw
437 1.2 mw case PARIOCSPARAM:
438 1.2 mw pp = &sc->sc_param;
439 1.2 mw upp = (struct parparam *)data;
440 1.2 mw if (upp->burst < PAR_BURST_MIN || upp->burst > PAR_BURST_MAX ||
441 1.2 mw upp->delay < PAR_DELAY_MIN || upp->delay > PAR_DELAY_MAX)
442 1.2 mw return(EINVAL);
443 1.2 mw pp->burst = upp->burst;
444 1.2 mw pp->timo = parmstohz(upp->timo);
445 1.2 mw pp->delay = parmstohz(upp->delay);
446 1.2 mw break;
447 1.2 mw
448 1.2 mw default:
449 1.1 mw return(EINVAL);
450 1.2 mw }
451 1.1 mw return (error);
452 1.1 mw }
453 1.1 mw
454 1.2 mw int
455 1.1 mw parhztoms(h)
456 1.2 mw int h;
457 1.1 mw {
458 1.1 mw extern int hz;
459 1.1 mw register int m = h;
460 1.1 mw
461 1.1 mw if (m > 0)
462 1.1 mw m = m * 1000 / hz;
463 1.1 mw return(m);
464 1.1 mw }
465 1.1 mw
466 1.2 mw int
467 1.1 mw parmstohz(m)
468 1.2 mw int m;
469 1.1 mw {
470 1.1 mw extern int hz;
471 1.1 mw register int h = m;
472 1.1 mw
473 1.1 mw if (h > 0) {
474 1.1 mw h = h * hz / 1000;
475 1.1 mw if (h == 0)
476 1.1 mw h = 1000 / hz;
477 1.1 mw }
478 1.1 mw return(h);
479 1.1 mw }
480 1.1 mw
481 1.2 mw /* stuff below here if for interrupt driven output of data thru
482 1.2 mw the parallel port. */
483 1.2 mw
484 1.2 mw int partimeout_pending;
485 1.2 mw int parsend_pending;
486 1.2 mw
487 1.1 mw void
488 1.7 chopps parintr(arg)
489 1.7 chopps void *arg;
490 1.1 mw {
491 1.7 chopps int s, mask;
492 1.7 chopps
493 1.7 chopps mask = (int)arg;
494 1.7 chopps s = splclock();
495 1.7 chopps
496 1.2 mw #ifdef DEBUG
497 1.7 chopps if (pardebug & PDB_INTERRUPT)
498 1.7 chopps printf("parintr %s\n", mask ? "FLG" : "tout");
499 1.7 chopps #endif
500 1.7 chopps /*
501 1.7 chopps * if invoked from timeout handler, mask will be 0,
502 1.7 chopps * if from interrupt, it will contain the cia-icr mask,
503 1.7 chopps * which is != 0
504 1.7 chopps */
505 1.7 chopps if (mask) {
506 1.7 chopps if (partimeout_pending)
507 1.7 chopps untimeout(parintr, 0);
508 1.7 chopps if (parsend_pending)
509 1.7 chopps parsend_pending = 0;
510 1.7 chopps }
511 1.2 mw
512 1.7 chopps /* either way, there won't be a timeout pending any longer */
513 1.7 chopps partimeout_pending = 0;
514 1.2 mw
515 1.7 chopps wakeup(parintr);
516 1.7 chopps splx(s);
517 1.2 mw }
518 1.2 mw
519 1.2 mw int
520 1.2 mw parsendch (ch)
521 1.2 mw u_char ch;
522 1.2 mw {
523 1.2 mw int error = 0;
524 1.2 mw int s;
525 1.2 mw
526 1.2 mw /* if either offline, busy or out of paper, wait for that
527 1.2 mw condition to clear */
528 1.2 mw s = splclock();
529 1.2 mw while (!error
530 1.2 mw && (parsend_pending
531 1.2 mw || ((ciab.pra ^ CIAB_PRA_SEL)
532 1.2 mw & (CIAB_PRA_SEL|CIAB_PRA_BUSY|CIAB_PRA_POUT))))
533 1.2 mw {
534 1.2 mw extern int hz;
535 1.2 mw
536 1.2 mw #ifdef DEBUG
537 1.2 mw if (pardebug & PDB_INTERRUPT)
538 1.2 mw printf ("parsendch, port = $%x\n",
539 1.2 mw ((ciab.pra ^ CIAB_PRA_SEL)
540 1.2 mw & (CIAB_PRA_SEL|CIAB_PRA_BUSY|CIAB_PRA_POUT)));
541 1.2 mw #endif
542 1.2 mw /* wait a second, and try again */
543 1.7 chopps timeout(parintr, 0, hz);
544 1.2 mw partimeout_pending = 1;
545 1.2 mw /* this is essentially a flipflop to have us wait for the
546 1.2 mw first character being transmitted when trying to transmit
547 1.2 mw the second, etc. */
548 1.2 mw parsend_pending = 0;
549 1.2 mw /* it's quite important that a parallel putc can be
550 1.2 mw interrupted, given the possibility to lock a printer
551 1.2 mw in an offline condition.. */
552 1.7 chopps if (error = tsleep(parintr, PCATCH|PZERO-1, "parsendch", 0))
553 1.2 mw {
554 1.2 mw #ifdef DEBUG
555 1.2 mw if (pardebug & PDB_INTERRUPT)
556 1.2 mw printf ("parsendch interrupted, error = %d\n", error);
557 1.2 mw #endif
558 1.2 mw if (partimeout_pending)
559 1.7 chopps untimeout(parintr, 0);
560 1.2 mw
561 1.2 mw partimeout_pending = 0;
562 1.2 mw }
563 1.2 mw }
564 1.2 mw
565 1.2 mw if (! error)
566 1.2 mw {
567 1.2 mw #ifdef DEBUG
568 1.2 mw if (pardebug & PDB_INTERRUPT)
569 1.2 mw printf ("#%d", ch);
570 1.2 mw #endif
571 1.2 mw ciaa.prb = ch;
572 1.2 mw parsend_pending = 1;
573 1.2 mw }
574 1.2 mw
575 1.2 mw splx (s);
576 1.2 mw
577 1.2 mw return error;
578 1.1 mw }
579 1.1 mw
580 1.2 mw
581 1.1 mw int
582 1.1 mw parsend (buf, len)
583 1.1 mw u_char *buf;
584 1.1 mw int len;
585 1.1 mw {
586 1.2 mw int err, orig_len = len;
587 1.2 mw
588 1.1 mw /* make sure I/O lines are setup right for output */
589 1.1 mw
590 1.1 mw /* control lines set to input */
591 1.1 mw ciab.ddra &= ~(CIAB_PRA_SEL|CIAB_PRA_POUT|CIAB_PRA_BUSY);
592 1.1 mw /* data lines to output */
593 1.1 mw ciaa.ddrb = 0xff;
594 1.1 mw
595 1.2 mw for (; len; len--, buf++)
596 1.2 mw if (err = parsendch (*buf))
597 1.2 mw return err < 0 ? -EINTR : -err;
598 1.2 mw
599 1.2 mw /* either all or nothing.. */
600 1.2 mw return orig_len;
601 1.1 mw }
602 1.1 mw
603 1.1 mw
604 1.1 mw
605 1.2 mw int
606 1.2 mw parreceive (buf, len)
607 1.2 mw u_char *buf;
608 1.2 mw int len;
609 1.2 mw {
610 1.2 mw /* oh deary me, something's gotta be left to be implemented
611 1.2 mw later... */
612 1.2 mw return 0;
613 1.2 mw }
614 1.1 mw
615 1.1 mw
616 1.1 mw #endif
617