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