nhpib.c revision 1.3 1 /* $NetBSD: nhpib.c,v 1.3 2003/11/14 16:52:40 tsutsui 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 * @(#)nhpib.c 8.1 (Berkeley) 6/10/93
32 */
33
34 /*
35 * Internal/98624 HPIB driver
36 */
37
38 #include <sys/param.h>
39
40 #include <hp300/dev/nhpibreg.h>
41
42 #include <hp300/stand/common/hpibvar.h>
43 #include <hp300/stand/common/samachdep.h>
44
45 static int nhpibiwait(struct nhpibdevice *);
46 static int nhpibowait(struct nhpibdevice *);
47
48 int
49 nhpibinit(unit)
50 {
51 struct hpib_softc *hs = &hpib_softc[unit];
52 struct nhpibdevice *hd = (void *)hs->sc_addr;
53
54 if ((int)hd == internalhpib) {
55 hs->sc_type = HPIBA;
56 hs->sc_ba = HPIBA_BA;
57 }
58 else if (hd->hpib_cid == HPIBB) {
59 hs->sc_type = HPIBB;
60 hs->sc_ba = hd->hpib_csa & CSA_BA;
61 }
62 else
63 return 0;
64 nhpibreset(unit);
65 return 1;
66 }
67
68 void
69 nhpibreset(unit)
70 {
71 struct hpib_softc *hs = &hpib_softc[unit];
72 struct nhpibdevice *hd;
73
74 hd = (void *)hs->sc_addr;
75 hd->hpib_acr = AUX_SSWRST;
76 hd->hpib_ar = hs->sc_ba;
77 hd->hpib_lim = 0;
78 hd->hpib_mim = 0;
79 hd->hpib_acr = AUX_CDAI;
80 hd->hpib_acr = AUX_CSHDW;
81 hd->hpib_acr = AUX_SSTD1;
82 hd->hpib_acr = AUX_SVSTD1;
83 hd->hpib_acr = AUX_CPP;
84 hd->hpib_acr = AUX_CHDFA;
85 hd->hpib_acr = AUX_CHDFE;
86 hd->hpib_acr = AUX_RHDF;
87 hd->hpib_acr = AUX_CSWRST;
88 hd->hpib_acr = AUX_TCA;
89 hd->hpib_acr = AUX_CSRE;
90 hd->hpib_acr = AUX_SSIC;
91 DELAY(100);
92 hd->hpib_acr = AUX_CSIC;
93 hd->hpib_acr = AUX_SSRE;
94 hd->hpib_data = C_DCL;
95 DELAY(100000);
96 }
97
98 int
99 nhpibsend(unit, slave, sec, buf, cnt)
100 int unit, slave, sec;
101 char *buf;
102 int cnt;
103 {
104 struct hpib_softc *hs = &hpib_softc[unit];
105 struct nhpibdevice *hd;
106 int origcnt = cnt;
107
108 hd = (void *)hs->sc_addr;
109 hd->hpib_acr = AUX_TCA;
110 hd->hpib_data = C_UNL;
111 nhpibowait(hd);
112 hd->hpib_data = C_TAG + hs->sc_ba;
113 hd->hpib_acr = AUX_STON;
114 nhpibowait(hd);
115 hd->hpib_data = C_LAG + slave;
116 nhpibowait(hd);
117 if (sec != -1) {
118 hd->hpib_data = C_SCG + sec;
119 nhpibowait(hd);
120 }
121 hd->hpib_acr = AUX_GTS;
122 if (cnt) {
123 while (--cnt) {
124 hd->hpib_data = *buf++;
125 if (nhpibowait(hd) < 0)
126 break;
127 }
128 hd->hpib_acr = AUX_EOI;
129 hd->hpib_data = *buf;
130 if (nhpibowait(hd) < 0)
131 cnt++;
132 hd->hpib_acr = AUX_TCA;
133 }
134 return origcnt - cnt;
135 }
136
137 int
138 nhpibrecv(unit, slave, sec, buf, cnt)
139 int unit, slave, sec;
140 char *buf;
141 int cnt;
142 {
143 struct hpib_softc *hs = &hpib_softc[unit];
144 struct nhpibdevice *hd;
145 int origcnt = cnt;
146
147 hd = (void *)hs->sc_addr;
148 hd->hpib_acr = AUX_TCA;
149 hd->hpib_data = C_UNL;
150 nhpibowait(hd);
151 hd->hpib_data = C_LAG + hs->sc_ba;
152 hd->hpib_acr = AUX_SLON;
153 nhpibowait(hd);
154 hd->hpib_data = C_TAG + slave;
155 nhpibowait(hd);
156 if (sec != -1) {
157 hd->hpib_data = C_SCG + sec;
158 nhpibowait(hd);
159 }
160 hd->hpib_acr = AUX_RHDF;
161 hd->hpib_acr = AUX_GTS;
162 if (cnt) {
163 while (--cnt >= 0) {
164 if (nhpibiwait(hd) < 0)
165 break;
166 *buf++ = hd->hpib_data;
167 }
168 cnt++;
169 hd->hpib_acr = AUX_TCA;
170 }
171 return origcnt - cnt;
172 }
173
174 int
175 nhpibppoll(unit)
176 int unit;
177 {
178 struct hpib_softc *hs = &hpib_softc[unit];
179 struct nhpibdevice *hd;
180 int ppoll;
181
182 hd = (void *)hs->sc_addr;
183 hd->hpib_acr = AUX_SPP;
184 DELAY(25);
185 ppoll = hd->hpib_cpt;
186 hd->hpib_acr = AUX_CPP;
187 return ppoll;
188 }
189
190 static int
191 nhpibowait(hd)
192 struct nhpibdevice *hd;
193 {
194 int timo = 100000;
195
196 while ((hd->hpib_mis & MIS_BO) == 0 && --timo)
197 ;
198 if (timo == 0)
199 return -1;
200 return 0;
201 }
202
203 static int
204 nhpibiwait(hd)
205 struct nhpibdevice *hd;
206 {
207 int timo = 100000;
208
209 while ((hd->hpib_mis & MIS_BI) == 0 && --timo)
210 ;
211 if (timo == 0)
212 return -1;
213 return 0;
214 }
215