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