xref: /csrg-svn/sys/vax/uba/ct.c (revision 3201)
1 /*	ct.c	4.4	81/03/11	*/
2 
3 #include "ct.h"
4 #if NCT > 0
5 /*
6  * GP DR11C driver used for C/A/T
7  */
8 
9 #include "../h/param.h"
10 #include "../h/systm.h"
11 #include "../h/tty.h"
12 #include "../h/pte.h"
13 #include "../h/map.h"
14 #include "../h/buf.h"
15 #include "../h/ubareg.h"
16 #include "../h/ubavar.h"
17 #include "../h/conf.h"
18 #include "../h/dir.h"
19 #include "../h/user.h"
20 
21 #define	PCAT	(PZERO+9)
22 #define	CATHIWAT	100
23 #define	CATLOWAT	30
24 
25 struct ct_softc {
26 	int	sc_openf;
27 	struct	clist sc_oq;
28 } ct_softc[NCT];
29 
30 struct ctdevice {
31 	short	ctcsr;
32 	short	ctbuf;
33 };
34 
35 int	ctprobe(), ctattach(), ctintr();
36 struct	uba_device *ctdinfo[NCT];
37 u_short	ctstd[] = { 0 };
38 struct	uba_driver ctdriver =
39     { ctprobe, 0, ctattach, 0, ctstd, "ct", ctdinfo };
40 
41 ctprobe(reg)
42 	caddr_t reg;
43 {
44 	register struct ctdevice *ctaddr = (struct ctdevice *)reg;
45 
46 	ctaddr->ctcsr = IENABLE;
47 	DELAY(10000);
48 	ctaddr->ctcsr = 0;
49 }
50 
51 ctopen(dev)
52 	dev_t dev;
53 {
54 	register struct ct_softc *sc;
55 	register struct uba_device *ui;
56 	register struct ctdevice *ctaddr;
57 
58 	if (CTUNIT(dev) >= NCT || (ui = ctdinfo[CTUNIT(dev)]) == 0 ||
59 	    ui->ui_alive == 0 || (sc = &ct_softc[CTUNIT(dev)])->sc_openf) {
60 		u.u_error = ENXIO;
61 		return;
62 	}
63 	sc->sc_openf = 1;
64 	ctaddr->ctcsr |= IENABLE;
65 }
66 
67 ctclose(dev)
68 	dev_t dev;
69 {
70 
71 	ct_softc[CTUNIT(dev)].sc_openf = 0;
72 	ctintr(dev);
73 }
74 
75 ctwrite(dev)
76 	dev_t dev;
77 {
78 	register struct ct_softc *sc = &ct_softc[CTUNIT(dev)];
79 	register int c;
80 
81 	while ((c=cpass()) >= 0) {
82 		(void) spl5();
83 		while (sc->sc_oq.c_cc > CATHIWAT)
84 			sleep((caddr_t)&sc->sc_oq, PCAT);
85 		while (putc(c, &sc->sc_oq) < 0)
86 			sleep((caddr_t)&lbolt, PCAT);
87 		ctintr(dev);
88 		(void) spl0();
89 	}
90 }
91 
92 ctintr(dev)
93 	dev_t dev;
94 {
95 	register int c;
96 	register struct ct_softc *sc = &ct_softc[CTUNIT(dev)];
97 	register struct ctdevice *ctaddr =
98 	    (struct ctdevice *)ctdinfo[CTUNIT(dev)]->ui_addr;
99 
100 	if (ctaddr->ctcsr&DONE) {
101 		if ((c = getc(&sc->sc_oq)) >= 0) {
102 #if MH135A
103 			c |= (c & 01) << 8;	/* for dr11c bug */
104 #endif
105 			ctaddr->ctbuf = c;
106 			if (sc->sc_oq.c_cc==0 || sc->sc_oq.c_cc==CATLOWAT)
107 				wakeup(&sc->sc_oq);
108 		} else {
109 			if (sc->sc_openf==0)
110 				ctaddr->ctcsr = 0;
111 		}
112 	}
113 
114 }
115 #endif
116