1 /* 2 * Copyright (c) 1982, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)hpib.c 8.2 (Berkeley) 01/12/94 8 */ 9 10 /* 11 * HPIB driver 12 */ 13 #include "hpib.h" 14 #if NHPIB > 0 15 16 #include <sys/param.h> 17 #include <sys/systm.h> 18 #include <sys/buf.h> 19 20 #include <hp/dev/device.h> 21 #include <hp300/dev/hpibvar.h> 22 #include <hp300/dev/dmavar.h> 23 24 #include <machine/cpu.h> 25 #include <hp300/hp300/isr.h> 26 27 int hpibinit(), hpibstart(), hpibgo(), hpibintr(), hpibdone(); 28 struct driver hpibdriver = { 29 hpibinit, "hpib", hpibstart, hpibgo, hpibintr, hpibdone, 30 }; 31 32 struct hpib_softc hpib_softc[NHPIB]; 33 struct isr hpib_isr[NHPIB]; 34 int nhpibppoll(), fhpibppoll(); 35 36 int hpibtimeout = 100000; /* # of status tests before we give up */ 37 int hpibidtimeout = 10000; /* # of status tests for hpibid() calls */ 38 int hpibdmathresh = 3; /* byte count beyond which to attempt dma */ 39 40 hpibinit(hc) 41 register struct hp_ctlr *hc; 42 { 43 register struct hpib_softc *hs = &hpib_softc[hc->hp_unit]; 44 45 if (!nhpibtype(hc) && !fhpibtype(hc)) 46 return(0); 47 hs->sc_hc = hc; 48 hs->sc_dq.dq_unit = hc->hp_unit; 49 hs->sc_dq.dq_driver = &hpibdriver; 50 hs->sc_sq.dq_forw = hs->sc_sq.dq_back = &hs->sc_sq; 51 hpib_isr[hc->hp_unit].isr_intr = hpibintr; 52 hpib_isr[hc->hp_unit].isr_ipl = hc->hp_ipl; 53 hpib_isr[hc->hp_unit].isr_arg = hc->hp_unit; 54 isrlink(&hpib_isr[hc->hp_unit]); 55 hpibreset(hc->hp_unit); 56 return(1); 57 } 58 59 hpibreset(unit) 60 register int unit; 61 { 62 if (hpib_softc[unit].sc_type == HPIBC) 63 fhpibreset(unit); 64 else 65 nhpibreset(unit); 66 } 67 68 hpibreq(dq) 69 register struct devqueue *dq; 70 { 71 register struct devqueue *hq; 72 73 hq = &hpib_softc[dq->dq_ctlr].sc_sq; 74 insque(dq, hq->dq_back); 75 if (dq->dq_back == hq) 76 return(1); 77 return(0); 78 } 79 80 hpibfree(dq) 81 register struct devqueue *dq; 82 { 83 register struct devqueue *hq; 84 85 hq = &hpib_softc[dq->dq_ctlr].sc_sq; 86 remque(dq); 87 if ((dq = hq->dq_forw) != hq) 88 (dq->dq_driver->d_start)(dq->dq_unit); 89 } 90 91 hpibid(unit, slave) 92 int unit, slave; 93 { 94 short id; 95 int ohpibtimeout; 96 97 /* 98 * XXX shorten timeout value so autoconfig doesn't 99 * take forever on slow CPUs. 100 */ 101 ohpibtimeout = hpibtimeout; 102 hpibtimeout = hpibidtimeout * cpuspeed; 103 if (hpibrecv(unit, 31, slave, &id, 2) != 2) 104 id = 0; 105 hpibtimeout = ohpibtimeout; 106 return(id); 107 } 108 109 hpibsend(unit, slave, sec, addr, cnt) 110 register int unit; 111 int slave, sec, addr, cnt; 112 { 113 if (hpib_softc[unit].sc_type == HPIBC) 114 return(fhpibsend(unit, slave, sec, addr, cnt)); 115 else 116 return(nhpibsend(unit, slave, sec, addr, cnt)); 117 } 118 119 hpibrecv(unit, slave, sec, addr, cnt) 120 register int unit; 121 int slave, sec, addr, cnt; 122 { 123 if (hpib_softc[unit].sc_type == HPIBC) 124 return(fhpibrecv(unit, slave, sec, addr, cnt)); 125 else 126 return(nhpibrecv(unit, slave, sec, addr, cnt)); 127 } 128 129 hpibpptest(unit, slave) 130 register int unit; 131 int slave; 132 { 133 int (*ppoll)(); 134 135 ppoll = (hpib_softc[unit].sc_type == HPIBC) ? fhpibppoll : nhpibppoll; 136 return((*ppoll)(unit) & (0x80 >> slave)); 137 } 138 139 hpibawait(unit) 140 int unit; 141 { 142 register struct hpib_softc *hs = &hpib_softc[unit]; 143 144 hs->sc_flags |= HPIBF_PPOLL; 145 if (hs->sc_type == HPIBC) 146 fhpibppwatch((void *)unit); 147 else 148 nhpibppwatch((void *)unit); 149 } 150 151 hpibswait(unit, slave) 152 register int unit; 153 int slave; 154 { 155 register int timo = hpibtimeout; 156 register int mask, (*ppoll)(); 157 158 ppoll = (hpib_softc[unit].sc_type == HPIBC) ? fhpibppoll : nhpibppoll; 159 mask = 0x80 >> slave; 160 while (((ppoll)(unit) & mask) == 0) 161 if (--timo == 0) { 162 printf("hpib%d: swait timeout\n", unit); 163 return(-1); 164 } 165 return(0); 166 } 167 168 hpibustart(unit) 169 int unit; 170 { 171 register struct hpib_softc *hs = &hpib_softc[unit]; 172 173 if (hs->sc_type == HPIBA) 174 hs->sc_dq.dq_ctlr = DMA0; 175 else 176 hs->sc_dq.dq_ctlr = DMA0 | DMA1; 177 if (dmareq(&hs->sc_dq)) 178 return(1); 179 return(0); 180 } 181 182 hpibstart(unit) 183 int unit; 184 { 185 register struct devqueue *dq; 186 187 dq = hpib_softc[unit].sc_sq.dq_forw; 188 (dq->dq_driver->d_go)(dq->dq_unit); 189 } 190 191 hpibgo(unit, slave, sec, addr, count, rw) 192 register int unit; 193 int slave, sec, addr, count, rw; 194 { 195 if (hpib_softc[unit].sc_type == HPIBC) 196 fhpibgo(unit, slave, sec, addr, count, rw); 197 else 198 nhpibgo(unit, slave, sec, addr, count, rw); 199 } 200 201 hpibdone(unit) 202 register int unit; 203 { 204 if (hpib_softc[unit].sc_type == HPIBC) 205 fhpibdone(unit); 206 else 207 nhpibdone(unit); 208 } 209 210 hpibintr(unit) 211 register int unit; 212 { 213 int found; 214 215 if (hpib_softc[unit].sc_type == HPIBC) 216 found = fhpibintr(unit); 217 else 218 found = nhpibintr(unit); 219 return(found); 220 } 221 #endif 222