1 /* $NetBSD: fhpib.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 * @(#)fhpib.c 8.1 (Berkeley) 6/10/93
35 * 98625A/B HPIB driver
38 #include <sys/param.h>
40 #include <hp300/dev/fhpibreg.h>
42 #include <hp300/stand/common/hpibvar.h>
43 #include <hp300/stand/common/samachdep.h>
45 static int fhpibwait(struct fhpibdevice
*, uint8_t);
50 struct hpib_softc
*hs
= &hpib_softc
[unit
];
51 struct fhpibdevice
*hd
= (void *)hs
->sc_addr
;
53 if (hd
->hpib_cid
!= HPIBC
)
64 struct hpib_softc
*hs
= &hpib_softc
[unit
];
65 struct fhpibdevice
*hd
;
67 hd
= (void *)hs
->sc_addr
;
70 hd
->hpib_cmd
= CT_8BIT
;
71 hd
->hpib_ar
= AR_ARONC
;
72 hd
->hpib_cmd
|= CT_IFC
;
73 hd
->hpib_cmd
|= CT_INITFIFO
;
75 hd
->hpib_cmd
&= ~CT_IFC
;
76 hd
->hpib_cmd
|= CT_REN
;
77 hd
->hpib_stat
= ST_ATN
;
78 hd
->hpib_data
= C_DCL
;
83 fhpibsend(int unit
, int slave
, int sec
, uint8_t *buf
, int cnt
)
85 struct hpib_softc
*hs
= &hpib_softc
[unit
];
86 struct fhpibdevice
*hd
;
89 hd
= (void *)hs
->sc_addr
;
91 hd
->hpib_imask
= IM_IDLE
| IM_ROOM
;
92 fhpibwait(hd
, IM_IDLE
);
93 hd
->hpib_stat
= ST_ATN
;
94 hd
->hpib_data
= C_UNL
;
95 hd
->hpib_data
= C_TAG
+ hs
->sc_ba
;
96 hd
->hpib_data
= C_LAG
+ slave
;
98 hd
->hpib_data
= C_SCG
+ sec
;
99 fhpibwait(hd
, IM_IDLE
);
100 hd
->hpib_stat
= ST_WRITE
;
103 hd
->hpib_data
= *buf
++;
104 if (fhpibwait(hd
, IM_ROOM
) < 0)
107 hd
->hpib_stat
= ST_EOI
;
108 hd
->hpib_data
= *buf
;
109 if (fhpibwait(hd
, IM_ROOM
) < 0)
111 hd
->hpib_stat
= ST_ATN
;
112 /* XXX: HP-UX claims bug with CS80 transparent messages */
115 hd
->hpib_data
= C_UNL
;
116 fhpibwait(hd
, IM_IDLE
);
119 return origcnt
- cnt
;
123 fhpibrecv(int unit
, int slave
, int sec
, uint8_t *buf
, int cnt
)
125 struct hpib_softc
*hs
= &hpib_softc
[unit
];
126 struct fhpibdevice
*hd
;
129 hd
= (void *)hs
->sc_addr
;
131 hd
->hpib_imask
= IM_IDLE
| IM_ROOM
| IM_BYTE
;
132 fhpibwait(hd
, IM_IDLE
);
133 hd
->hpib_stat
= ST_ATN
;
134 hd
->hpib_data
= C_UNL
;
135 hd
->hpib_data
= C_LAG
+ hs
->sc_ba
;
136 hd
->hpib_data
= C_TAG
+ slave
;
138 hd
->hpib_data
= C_SCG
+ sec
;
139 fhpibwait(hd
, IM_IDLE
);
140 hd
->hpib_stat
= ST_READ0
;
144 if (fhpibwait(hd
, IM_BYTE
) < 0)
146 *buf
++ = hd
->hpib_data
;
149 fhpibwait(hd
, IM_ROOM
);
150 hd
->hpib_stat
= ST_ATN
;
151 hd
->hpib_data
= (slave
== 31) ? C_UNA
: C_UNT
;
152 fhpibwait(hd
, IM_IDLE
);
155 return origcnt
- cnt
;
161 struct hpib_softc
*hs
= &hpib_softc
[unit
];
162 struct fhpibdevice
*hd
;
165 hd
= (void *)hs
->sc_addr
;
168 hd
->hpib_pmask
= 0xFF;
169 hd
->hpib_imask
= IM_PPRESP
| IM_PABORT
;
171 hd
->hpib_intr
= IM_PABORT
;
172 ppoll
= hd
->hpib_data
;
173 if (hd
->hpib_intr
& IM_PABORT
)
177 hd
->hpib_stat
= ST_IENAB
;
182 fhpibwait(struct fhpibdevice
*hd
, uint8_t x
)
186 while ((hd
->hpib_intr
& x
) == 0 && --timo
)