|
|
1.1 root 1: /*
2: * Mach Operating System
3: * Copyright (c) 1993-1990 Carnegie Mellon University
4: * All Rights Reserved.
5: *
6: * Permission to use, copy, modify and distribute this software and its
7: * documentation is hereby granted, provided that both the copyright
8: * notice and this permission notice appear in all copies of the
9: * software, derivative works or modified versions, and any portions
10: * thereof, and that both notices appear in supporting documentation.
11: *
12: * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13: * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14: * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15: *
16: * Carnegie Mellon requests users of this software to return to
17: *
18: * Software Distribution Coordinator or [email protected]
19: * School of Computer Science
20: * Carnegie Mellon University
21: * Pittsburgh PA 15213-3890
22: *
23: * any improvements or extensions that they make and grant Carnegie Mellon
24: * the rights to redistribute these changes.
25: */
26: /*
27: * Parallel port printer driver v1.0
28: * All rights reserved.
29: */
30:
31: #if NLPR > 0
32:
33: #include <mach/std_types.h>
34: #include <sys/types.h>
1.1.1.2 root 35: #include <kern/printf.h>
36: #include <kern/mach_clock.h>
1.1 root 37: #include <sys/time.h>
38: #include <device/conf.h>
1.1.1.2 root 39: #include <device/device_types.h>
1.1 root 40: #include <device/tty.h>
41: #include <device/io_req.h>
42:
43: #include <i386/ipl.h>
44: #include <i386/pio.h>
45: #include <chips/busses.h>
1.1.1.2 root 46: #include <i386at/autoconf.h>
1.1.1.3 ! root 47: #include <i386at/lpr.h>
1.1 root 48:
49: /*
50: * Driver information for auto-configuration stuff.
51: */
52:
53: struct bus_device *lprinfo[NLPR]; /* ??? */
54:
55: static vm_offset_t lpr_std[NLPR] = { 0 };
56: static struct bus_device *lpr_info[NLPR];
57: struct bus_driver lprdriver = {
58: lprprobe, 0, lprattach, 0, lpr_std, "lpr", lpr_info, 0, 0, 0};
59:
60: struct tty lpr_tty[NLPR];
61:
62: int lpr_alive[NLPR];
63:
1.1.1.2 root 64: int
1.1 root 65: lprprobe(port, dev)
1.1.1.3 ! root 66: vm_offset_t port;
! 67: struct bus_ctlr *dev;
1.1 root 68: {
69: u_short addr = (u_short) dev->address;
70: int unit = dev->unit;
71: int ret;
72:
73: if ((unit < 0) || (unit > NLPR)) {
74: printf("com %d out of range\n", unit);
75: return(0);
76: }
77:
78: outb(INTR_ENAB(addr),0x07);
79: outb(DATA(addr),0xaa);
80: ret = inb(DATA(addr)) == 0xaa;
81: if (ret) {
82: if (lpr_alive[unit]) {
83: printf("lpr: Multiple alive entries for unit %d.\n", unit);
84: printf("lpr: Ignoring entry with address = %x .\n", addr);
85: ret = 0;
86: } else
87: lpr_alive[unit]++;
88: }
89: return(ret);
90: }
91:
92: void lprattach(struct bus_device *dev)
93: {
94: u_char unit = dev->unit;
95: u_short addr = (u_short) dev->address;
96:
97: take_dev_irq(dev);
1.1.1.2 root 98: printf(", port = %lx, spl = %ld, pic = %d.",
1.1 root 99: dev->address, dev->sysdep, dev->sysdep1);
100: lprinfo[unit] = dev;
101:
102: outb(INTR_ENAB(addr), inb(INTR_ENAB(addr)) & 0x0f);
103:
104: return;
105: }
106:
1.1.1.2 root 107: int
1.1 root 108: lpropen(dev, flag, ior)
1.1.1.3 ! root 109: dev_t dev;
1.1 root 110: int flag;
111: io_req_t ior;
112: {
113: int unit = minor(dev);
114: struct bus_device *isai;
115: struct tty *tp;
116: u_short addr;
117:
118: if (unit >= NLPR || (isai = lprinfo[unit]) == 0 || isai->alive == 0)
1.1.1.2 root 119: return (D_NO_SUCH_DEVICE);
1.1 root 120: tp = &lpr_tty[unit];
121: addr = (u_short) isai->address;
122: tp->t_dev = dev;
123: tp->t_addr = *(caddr_t *)&addr;
124: tp->t_oproc = lprstart;
125: tp->t_state |= TS_WOPEN;
126: tp->t_stop = lprstop;
127: tp->t_getstat = lprgetstat;
128: tp->t_setstat = lprsetstat;
129: if ((tp->t_state & TS_ISOPEN) == 0)
130: ttychars(tp);
131: outb(INTR_ENAB(addr), inb(INTR_ENAB(addr)) | 0x10);
132: tp->t_state |= TS_CARR_ON;
133: return (char_open(dev, tp, flag, ior));
134: }
135:
1.1.1.2 root 136: void
1.1 root 137: lprclose(dev, flag)
1.1.1.3 ! root 138: dev_t dev;
1.1 root 139: int flag;
140: {
141: int unit = minor(dev);
142: struct tty *tp = &lpr_tty[unit];
143: u_short addr = (u_short) lprinfo[unit]->address;
144:
145: ttyclose(tp);
146: if (tp->t_state&TS_HUPCLS || (tp->t_state&TS_ISOPEN)==0) {
147: outb(INTR_ENAB(addr), inb(INTR_ENAB(addr)) & 0x0f);
148: tp->t_state &= ~TS_BUSY;
149: }
150: }
151:
1.1.1.2 root 152: int
1.1 root 153: lprread(dev, ior)
1.1.1.3 ! root 154: dev_t dev;
1.1 root 155: io_req_t ior;
156: {
157: return char_read(&lpr_tty[minor(dev)], ior);
158: }
159:
1.1.1.2 root 160: int
1.1 root 161: lprwrite(dev, ior)
1.1.1.3 ! root 162: dev_t dev;
1.1 root 163: io_req_t ior;
164: {
165: return char_write(&lpr_tty[minor(dev)], ior);
166: }
167:
1.1.1.2 root 168: int
1.1 root 169: lprportdeath(dev, port)
170: dev_t dev;
171: mach_port_t port;
172: {
1.1.1.2 root 173: return (tty_portdeath(&lpr_tty[minor(dev)], (ipc_port_t)port));
1.1 root 174: }
175:
176: io_return_t
177: lprgetstat(dev, flavor, data, count)
178: dev_t dev;
179: int flavor;
180: int *data; /* pointer to OUT array */
1.1.1.2 root 181: natural_t *count; /* out */
1.1 root 182: {
183: io_return_t result = D_SUCCESS;
184: int unit = minor(dev);
185:
186: switch (flavor) {
187: default:
188: result = tty_get_status(&lpr_tty[unit], flavor, data, count);
189: break;
190: }
191: return (result);
192: }
193:
194: io_return_t
1.1.1.3 ! root 195: lprsetstat(
! 196: dev_t dev,
! 197: int flavor,
! 198: int * data,
! 199: natural_t count)
1.1 root 200: {
201: io_return_t result = D_SUCCESS;
202: int unit = minor(dev);
203:
204: switch (flavor) {
205: default:
206: result = tty_set_status(&lpr_tty[unit], flavor, data, count);
207: /* if (result == D_SUCCESS && flavor == TTY_STATUS)
208: lprparam(unit);
209: */ return (result);
210: }
211: return (D_SUCCESS);
212: }
213:
1.1.1.3 ! root 214: void lprintr(int unit)
1.1 root 215: {
1.1.1.3 ! root 216: struct tty *tp = &lpr_tty[unit];
1.1 root 217:
218: if ((tp->t_state & TS_ISOPEN) == 0)
219: return;
220:
221: tp->t_state &= ~TS_BUSY;
222: if (tp->t_state&TS_FLUSH)
223: tp->t_state &=~TS_FLUSH;
224: tt_write_wakeup(tp);
225: lprstart(tp);
226: }
227:
1.1.1.3 ! root 228: void lprstart(struct tty *tp)
1.1 root 229: {
230: spl_t s = spltty();
231: u_short addr = (natural_t) tp->t_addr;
232: int status = inb(STATUS(addr));
233: char nch;
234:
235: if (tp->t_state & (TS_TIMEOUT|TS_TTSTOP|TS_BUSY)) {
236: splx(s);
1.1.1.2 root 237: return;
1.1 root 238: }
239:
240: if (status & 0x20) {
241: printf("Printer out of paper!\n");
242: splx(s);
1.1.1.2 root 243: return;
1.1 root 244: }
245:
246: if (tp->t_outq.c_cc <= TTLOWAT(tp)) {
247: tt_write_wakeup(tp);
248: }
249: if (tp->t_outq.c_cc == 0) {
250: splx(s);
1.1.1.2 root 251: return;
1.1 root 252: }
253: nch = getc(&tp->t_outq);
254: if ((tp->t_flags & LITOUT) == 0 && (nch & 0200)) {
1.1.1.2 root 255: timeout((timer_func_t *)ttrstrt, (char *)tp, (nch & 0x7f) + 6);
1.1 root 256: tp->t_state |= TS_TIMEOUT;
257: return;
258: }
259: outb(DATA(addr), nch);
260: outb(INTR_ENAB(addr),inb(INTR_ENAB(addr)) | 0x01);
261: outb(INTR_ENAB(addr),inb(INTR_ENAB(addr)) & 0x1e);
262: tp->t_state |= TS_BUSY;
263: splx(s);
1.1.1.2 root 264: return;
1.1 root 265: }
266:
1.1.1.2 root 267: void
1.1.1.3 ! root 268: lprstop(
! 269: struct tty *tp,
! 270: int flags)
1.1 root 271: {
272: if ((tp->t_state & TS_BUSY) && (tp->t_state & TS_TTSTOP) == 0)
273: tp->t_state |= TS_FLUSH;
274: }
1.1.1.2 root 275: int
1.1.1.3 ! root 276: lprpr(int unit)
1.1 root 277: {
278: lprpr_addr(lprinfo[unit]->address);
279: return 0;
280: }
281:
1.1.1.2 root 282: void
1.1.1.3 ! root 283: lprpr_addr(unsigned short addr)
1.1 root 284: {
285: printf("DATA(%x) %x, STATUS(%x) %x, INTR_ENAB(%x) %x\n",
286: DATA(addr), inb(DATA(addr)),
287: STATUS(addr), inb(STATUS(addr)),
288: INTR_ENAB(addr), inb(INTR_ENAB(addr)));
289: }
1.1.1.2 root 290: #endif /* NLPR */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.