xref: /netbsd/sys/arch/hp300/stand/common/nhpib.c (revision bf9ec67e)
1 /*	$NetBSD: nhpib.c,v 1.1 1997/02/04 03:52:43 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  *	@(#)nhpib.c	8.1 (Berkeley) 6/10/93
36  */
37 
38 /*
39  * Internal/98624 HPIB driver
40  */
41 
42 #include <sys/param.h>
43 
44 #include <hp300/dev/nhpibreg.h>
45 
46 #include <hp300/stand/common/hpibvar.h>
47 #include <hp300/stand/common/samachdep.h>
48 
49 nhpibinit(unit)
50 {
51 	register struct hpib_softc *hs = &hpib_softc[unit];
52 	register struct nhpibdevice *hd = (struct nhpibdevice *)hs->sc_addr;
53 	extern int internalhpib;
54 
55 	if ((int)hd == internalhpib) {
56 		hs->sc_type = HPIBA;
57 		hs->sc_ba = HPIBA_BA;
58 	}
59 	else if (hd->hpib_cid == HPIBB) {
60 		hs->sc_type = HPIBB;
61 		hs->sc_ba = hd->hpib_csa & CSA_BA;
62 	}
63 	else
64 		return(0);
65 	nhpibreset(unit);
66 	return(1);
67 }
68 
69 nhpibreset(unit)
70 {
71 	register struct hpib_softc *hs = &hpib_softc[unit];
72 	register struct nhpibdevice *hd;
73 
74 	hd = (struct nhpibdevice *)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 nhpibsend(unit, slave, sec, buf, cnt)
99 	register char *buf;
100 	register int cnt;
101 {
102 	register struct hpib_softc *hs = &hpib_softc[unit];
103 	register struct nhpibdevice *hd;
104 	register int origcnt = cnt;
105 
106 	hd = (struct nhpibdevice *)hs->sc_addr;
107 	hd->hpib_acr = AUX_TCA;
108 	hd->hpib_data = C_UNL;
109 	nhpibowait(hd);
110 	hd->hpib_data = C_TAG + hs->sc_ba;
111 	hd->hpib_acr = AUX_STON;
112 	nhpibowait(hd);
113 	hd->hpib_data = C_LAG + slave;
114 	nhpibowait(hd);
115 	if (sec != -1) {
116 		hd->hpib_data = C_SCG + sec;
117 		nhpibowait(hd);
118 	}
119 	hd->hpib_acr = AUX_GTS;
120 	if (cnt) {
121 		while (--cnt) {
122 			hd->hpib_data = *buf++;
123 			if (nhpibowait(hd) < 0)
124 				break;
125 		}
126 		hd->hpib_acr = AUX_EOI;
127 		hd->hpib_data = *buf;
128 		if (nhpibowait(hd) < 0)
129 			cnt++;
130 		hd->hpib_acr = AUX_TCA;
131 	}
132 	return(origcnt - cnt);
133 }
134 
135 nhpibrecv(unit, slave, sec, buf, cnt)
136 	register char *buf;
137 	register int cnt;
138 {
139 	register struct hpib_softc *hs = &hpib_softc[unit];
140 	register struct nhpibdevice *hd;
141 	register int origcnt = cnt;
142 
143 	hd = (struct nhpibdevice *)hs->sc_addr;
144 	hd->hpib_acr = AUX_TCA;
145 	hd->hpib_data = C_UNL;
146 	nhpibowait(hd);
147 	hd->hpib_data = C_LAG + hs->sc_ba;
148 	hd->hpib_acr = AUX_SLON;
149 	nhpibowait(hd);
150 	hd->hpib_data = C_TAG + slave;
151 	nhpibowait(hd);
152 	if (sec != -1) {
153 		hd->hpib_data = C_SCG + sec;
154 		nhpibowait(hd);
155 	}
156 	hd->hpib_acr = AUX_RHDF;
157 	hd->hpib_acr = AUX_GTS;
158 	if (cnt) {
159 		while (--cnt >= 0) {
160 			if (nhpibiwait(hd) < 0)
161 				break;
162 			*buf++ = hd->hpib_data;
163 		}
164 		cnt++;
165 		hd->hpib_acr = AUX_TCA;
166 	}
167 	return(origcnt - cnt);
168 }
169 
170 nhpibppoll(unit)
171 	register int unit;
172 {
173 	register struct hpib_softc *hs = &hpib_softc[unit];
174 	register struct nhpibdevice *hd;
175 	register int ppoll;
176 
177 	hd = (struct nhpibdevice *)hs->sc_addr;
178 	hd->hpib_acr = AUX_SPP;
179 	DELAY(25);
180 	ppoll = hd->hpib_cpt;
181 	hd->hpib_acr = AUX_CPP;
182 	return(ppoll);
183 }
184 
185 nhpibowait(hd)
186 	register struct nhpibdevice *hd;
187 {
188 	register int timo = 100000;
189 
190 	while ((hd->hpib_mis & MIS_BO) == 0 && --timo)
191 		;
192 	if (timo == 0)
193 		return(-1);
194 	return(0);
195 }
196 
197 nhpibiwait(hd)
198 	register struct nhpibdevice *hd;
199 {
200 	register int timo = 100000;
201 
202 	while ((hd->hpib_mis & MIS_BI) == 0 && --timo)
203 		;
204 	if (timo == 0)
205 		return(-1);
206 	return(0);
207 }
208