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