1*17073Sbloom /* ct.c 6.2 84/08/29 */ 22621Swnj 33201Swnj #include "ct.h" 42621Swnj #if NCT > 0 52621Swnj /* 62621Swnj * GP DR11C driver used for C/A/T 73936Sbugs * 83936Sbugs * BUGS: 93936Sbugs * This driver hasn't been tested in 4.1bsd 102621Swnj */ 119771Ssam #include "../machine/pte.h" 122621Swnj 13*17073Sbloom #include "param.h" 14*17073Sbloom #include "systm.h" 15*17073Sbloom #include "tty.h" 16*17073Sbloom #include "map.h" 17*17073Sbloom #include "buf.h" 18*17073Sbloom #include "conf.h" 19*17073Sbloom #include "dir.h" 20*17073Sbloom #include "user.h" 212621Swnj 22*17073Sbloom #include "ubareg.h" 23*17073Sbloom #include "ubavar.h" 248472Sroot 252621Swnj #define PCAT (PZERO+9) 262621Swnj #define CATHIWAT 100 272621Swnj #define CATLOWAT 30 282621Swnj 293201Swnj struct ct_softc { 303201Swnj int sc_openf; 313201Swnj struct clist sc_oq; 323201Swnj } ct_softc[NCT]; 332621Swnj 343201Swnj struct ctdevice { 353201Swnj short ctcsr; 363201Swnj short ctbuf; 372621Swnj }; 382621Swnj 393201Swnj int ctprobe(), ctattach(), ctintr(); 403201Swnj struct uba_device *ctdinfo[NCT]; 413201Swnj u_short ctstd[] = { 0 }; 423201Swnj struct uba_driver ctdriver = 433201Swnj { ctprobe, 0, ctattach, 0, ctstd, "ct", ctdinfo }; 442621Swnj 453217Swnj #define CTUNIT(dev) (minor(dev)) 463217Swnj 473201Swnj ctprobe(reg) 483201Swnj caddr_t reg; 493201Swnj { 503936Sbugs register int br, cvec; /* value-result */ 513201Swnj register struct ctdevice *ctaddr = (struct ctdevice *)reg; 523201Swnj 534932Swnj #ifdef lint 544932Swnj br = 0; cvec = br; br = cvec; 554932Swnj ctintr(0); 564932Swnj #endif 573201Swnj ctaddr->ctcsr = IENABLE; 583201Swnj DELAY(10000); 593201Swnj ctaddr->ctcsr = 0; 607409Skre return (sizeof (struct ctdevice)); 613201Swnj } 623201Swnj 633217Swnj /*ARGSUSED*/ 643217Swnj ctattach(ui) 653217Swnj register struct uba_device *ui; 663217Swnj { 673217Swnj 683217Swnj } 693217Swnj 702621Swnj ctopen(dev) 713201Swnj dev_t dev; 722621Swnj { 733201Swnj register struct ct_softc *sc; 743201Swnj register struct uba_device *ui; 753201Swnj register struct ctdevice *ctaddr; 763201Swnj 773201Swnj if (CTUNIT(dev) >= NCT || (ui = ctdinfo[CTUNIT(dev)]) == 0 || 788566Sroot ui->ui_alive == 0 || (sc = &ct_softc[CTUNIT(dev)])->sc_openf) 798566Sroot return (ENXIO); 803201Swnj sc->sc_openf = 1; 813201Swnj ctaddr->ctcsr |= IENABLE; 828566Sroot return (0); 832621Swnj } 842621Swnj 853201Swnj ctclose(dev) 863201Swnj dev_t dev; 872621Swnj { 883201Swnj 893201Swnj ct_softc[CTUNIT(dev)].sc_openf = 0; 903201Swnj ctintr(dev); 912621Swnj } 922621Swnj 937831Sroot ctwrite(dev, uio) 943201Swnj dev_t dev; 957831Sroot struct uio *uio; 962621Swnj { 973201Swnj register struct ct_softc *sc = &ct_softc[CTUNIT(dev)]; 983201Swnj register int c; 992621Swnj 1007831Sroot while ((c=cupass(uio)) >= 0) { 1013101Swnj (void) spl5(); 1023201Swnj while (sc->sc_oq.c_cc > CATHIWAT) 1033201Swnj sleep((caddr_t)&sc->sc_oq, PCAT); 1043201Swnj while (putc(c, &sc->sc_oq) < 0) 1052621Swnj sleep((caddr_t)&lbolt, PCAT); 1063201Swnj ctintr(dev); 1073101Swnj (void) spl0(); 1082621Swnj } 1092621Swnj } 1102621Swnj 1113201Swnj ctintr(dev) 1123201Swnj dev_t dev; 1132621Swnj { 1142621Swnj register int c; 1153201Swnj register struct ct_softc *sc = &ct_softc[CTUNIT(dev)]; 1163201Swnj register struct ctdevice *ctaddr = 1173201Swnj (struct ctdevice *)ctdinfo[CTUNIT(dev)]->ui_addr; 1182621Swnj 1193201Swnj if (ctaddr->ctcsr&DONE) { 1203201Swnj if ((c = getc(&sc->sc_oq)) >= 0) { 1213201Swnj ctaddr->ctbuf = c; 1223201Swnj if (sc->sc_oq.c_cc==0 || sc->sc_oq.c_cc==CATLOWAT) 1233201Swnj wakeup(&sc->sc_oq); 1242621Swnj } else { 1253201Swnj if (sc->sc_openf==0) 1263201Swnj ctaddr->ctcsr = 0; 1272621Swnj } 1282621Swnj } 1292621Swnj 1302621Swnj } 1312621Swnj #endif 132