1 /* $NetBSD: fhpib.c,v 1.1 1997/02/04 03:52:24 thorpej Exp $ */ 2 3 /* 4 * Copyright (c) 1982, 1990, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by the University of 18 * California, Berkeley and its contributors. 19 * 4. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 * @(#)fhpib.c 8.1 (Berkeley) 6/10/93 36 */ 37 38 /* 39 * 98625A/B HPIB driver 40 */ 41 42 #include <sys/param.h> 43 44 #include <hp300/dev/fhpibreg.h> 45 46 #include <hp300/stand/common/hpibvar.h> 47 #include <hp300/stand/common/samachdep.h> 48 49 fhpibinit(unit) 50 register int unit; 51 { 52 register struct hpib_softc *hs = &hpib_softc[unit]; 53 register struct fhpibdevice *hd = (struct fhpibdevice *)hs->sc_addr; 54 55 if (hd->hpib_cid != HPIBC) 56 return(0); 57 hs->sc_type = HPIBC; 58 hs->sc_ba = HPIBC_BA; 59 fhpibreset(unit); 60 return(1); 61 } 62 63 fhpibreset(unit) 64 { 65 register struct hpib_softc *hs = &hpib_softc[unit]; 66 register struct fhpibdevice *hd; 67 68 hd = (struct fhpibdevice *)hs->sc_addr; 69 hd->hpib_cid = 0xFF; 70 DELAY(100); 71 hd->hpib_cmd = CT_8BIT; 72 hd->hpib_ar = AR_ARONC; 73 hd->hpib_cmd |= CT_IFC; 74 hd->hpib_cmd |= CT_INITFIFO; 75 DELAY(100); 76 hd->hpib_cmd &= ~CT_IFC; 77 hd->hpib_cmd |= CT_REN; 78 hd->hpib_stat = ST_ATN; 79 hd->hpib_data = C_DCL; 80 DELAY(100000); 81 } 82 83 fhpibsend(unit, slave, sec, buf, cnt) 84 register char *buf; 85 register int cnt; 86 { 87 register struct hpib_softc *hs = &hpib_softc[unit]; 88 register struct fhpibdevice *hd; 89 int origcnt = cnt; 90 91 hd = (struct fhpibdevice *)hs->sc_addr; 92 hd->hpib_stat = 0; 93 hd->hpib_imask = IM_IDLE | IM_ROOM; 94 fhpibwait(hd, IM_IDLE); 95 hd->hpib_stat = ST_ATN; 96 hd->hpib_data = C_UNL; 97 hd->hpib_data = C_TAG + hs->sc_ba; 98 hd->hpib_data = C_LAG + slave; 99 if (sec != -1) 100 hd->hpib_data = C_SCG + sec; 101 fhpibwait(hd, IM_IDLE); 102 hd->hpib_stat = ST_WRITE; 103 if (cnt) { 104 while (--cnt) { 105 hd->hpib_data = *buf++; 106 if (fhpibwait(hd, IM_ROOM) < 0) 107 break; 108 } 109 hd->hpib_stat = ST_EOI; 110 hd->hpib_data = *buf; 111 if (fhpibwait(hd, IM_ROOM) < 0) 112 cnt++; 113 hd->hpib_stat = ST_ATN; 114 /* XXX: HP-UX claims bug with CS80 transparent messages */ 115 if (sec == 0x12) 116 DELAY(150); 117 hd->hpib_data = C_UNL; 118 fhpibwait(hd, IM_IDLE); 119 } 120 hd->hpib_imask = 0; 121 return(origcnt - cnt); 122 } 123 124 fhpibrecv(unit, slave, sec, buf, cnt) 125 register char *buf; 126 register int cnt; 127 { 128 register struct hpib_softc *hs = &hpib_softc[unit]; 129 register struct fhpibdevice *hd; 130 int origcnt = cnt; 131 132 hd = (struct fhpibdevice *)hs->sc_addr; 133 hd->hpib_stat = 0; 134 hd->hpib_imask = IM_IDLE | IM_ROOM | IM_BYTE; 135 fhpibwait(hd, IM_IDLE); 136 hd->hpib_stat = ST_ATN; 137 hd->hpib_data = C_UNL; 138 hd->hpib_data = C_LAG + hs->sc_ba; 139 hd->hpib_data = C_TAG + slave; 140 if (sec != -1) 141 hd->hpib_data = C_SCG + sec; 142 fhpibwait(hd, IM_IDLE); 143 hd->hpib_stat = ST_READ0; 144 hd->hpib_data = 0; 145 if (cnt) { 146 while (--cnt >= 0) { 147 if (fhpibwait(hd, IM_BYTE) < 0) 148 break; 149 *buf++ = hd->hpib_data; 150 } 151 cnt++; 152 fhpibwait(hd, IM_ROOM); 153 hd->hpib_stat = ST_ATN; 154 hd->hpib_data = (slave == 31) ? C_UNA : C_UNT; 155 fhpibwait(hd, IM_IDLE); 156 } 157 hd->hpib_imask = 0; 158 return(origcnt - cnt); 159 } 160 161 fhpibppoll(unit) 162 register int unit; 163 { 164 register struct hpib_softc *hs = &hpib_softc[unit]; 165 register struct fhpibdevice *hd; 166 register int ppoll; 167 168 hd = (struct fhpibdevice *)hs->sc_addr; 169 hd->hpib_stat = 0; 170 hd->hpib_psense = 0; 171 hd->hpib_pmask = 0xFF; 172 hd->hpib_imask = IM_PPRESP | IM_PABORT; 173 DELAY(25); 174 hd->hpib_intr = IM_PABORT; 175 ppoll = hd->hpib_data; 176 if (hd->hpib_intr & IM_PABORT) 177 ppoll = 0; 178 hd->hpib_imask = 0; 179 hd->hpib_pmask = 0; 180 hd->hpib_stat = ST_IENAB; 181 return(ppoll); 182 } 183 184 fhpibwait(hd, x) 185 register struct fhpibdevice *hd; 186 { 187 register int timo = 100000; 188 189 while ((hd->hpib_intr & x) == 0 && --timo) 190 ; 191 if (timo == 0) 192 return(-1); 193 return(0); 194 } 195