1 /* $NetBSD: nhpib.c,v 1.5 2005/12/11 12:17:19 christos Exp $ */
4 * Copyright (c) 1982, 1990, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
31 * @(#)nhpib.c 8.1 (Berkeley) 6/10/93
35 * Internal/98624 HPIB driver
38 #include <sys/param.h>
40 #include <hp300/dev/nhpibreg.h>
42 #include <hp300/stand/common/hpibvar.h>
43 #include <hp300/stand/common/samachdep.h>
45 static int nhpibiwait(struct nhpibdevice
*);
46 static int nhpibowait(struct nhpibdevice
*);
51 struct hpib_softc
*hs
= &hpib_softc
[unit
];
52 struct nhpibdevice
*hd
= (void *)hs
->sc_addr
;
54 if ((int)hd
== internalhpib
) {
58 else if (hd
->hpib_cid
== HPIBB
) {
60 hs
->sc_ba
= hd
->hpib_csa
& CSA_BA
;
71 struct hpib_softc
*hs
= &hpib_softc
[unit
];
72 struct nhpibdevice
*hd
;
74 hd
= (void *)hs
->sc_addr
;
75 hd
->hpib_acr
= AUX_SSWRST
;
76 hd
->hpib_ar
= hs
->sc_ba
;
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
;
92 hd
->hpib_acr
= AUX_CSIC
;
93 hd
->hpib_acr
= AUX_SSRE
;
94 hd
->hpib_data
= C_DCL
;
99 nhpibsend(int unit
, int slave
, int sec
, uint8_t *buf
, int cnt
)
101 struct hpib_softc
*hs
= &hpib_softc
[unit
];
102 struct nhpibdevice
*hd
;
105 hd
= (void *)hs
->sc_addr
;
106 hd
->hpib_acr
= AUX_TCA
;
107 hd
->hpib_data
= C_UNL
;
109 hd
->hpib_data
= C_TAG
+ hs
->sc_ba
;
110 hd
->hpib_acr
= AUX_STON
;
112 hd
->hpib_data
= C_LAG
+ slave
;
115 hd
->hpib_data
= C_SCG
+ sec
;
118 hd
->hpib_acr
= AUX_GTS
;
121 hd
->hpib_data
= *buf
++;
122 if (nhpibowait(hd
) < 0)
125 hd
->hpib_acr
= AUX_EOI
;
126 hd
->hpib_data
= *buf
;
127 if (nhpibowait(hd
) < 0)
129 hd
->hpib_acr
= AUX_TCA
;
131 return origcnt
- cnt
;
135 nhpibrecv(int unit
, int slave
, int sec
, uint8_t *buf
, int cnt
)
137 struct hpib_softc
*hs
= &hpib_softc
[unit
];
138 struct nhpibdevice
*hd
;
141 hd
= (void *)hs
->sc_addr
;
142 hd
->hpib_acr
= AUX_TCA
;
143 hd
->hpib_data
= C_UNL
;
145 hd
->hpib_data
= C_LAG
+ hs
->sc_ba
;
146 hd
->hpib_acr
= AUX_SLON
;
148 hd
->hpib_data
= C_TAG
+ slave
;
151 hd
->hpib_data
= C_SCG
+ sec
;
154 hd
->hpib_acr
= AUX_RHDF
;
155 hd
->hpib_acr
= AUX_GTS
;
158 if (nhpibiwait(hd
) < 0)
160 *buf
++ = hd
->hpib_data
;
163 hd
->hpib_acr
= AUX_TCA
;
165 return origcnt
- cnt
;
171 struct hpib_softc
*hs
= &hpib_softc
[unit
];
172 struct nhpibdevice
*hd
;
175 hd
= (void *)hs
->sc_addr
;
176 hd
->hpib_acr
= AUX_SPP
;
178 ppoll
= hd
->hpib_cpt
;
179 hd
->hpib_acr
= AUX_CPP
;
184 nhpibowait(struct nhpibdevice
*hd
)
188 while ((hd
->hpib_mis
& MIS_BO
) == 0 && --timo
)
196 nhpibiwait(struct nhpibdevice
*hd
)
200 while ((hd
->hpib_mis
& MIS_BI
) == 0 && --timo
)