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