Commit | Line | Data |
---|---|---|
a8fd2d0d KM |
1 | /* |
2 | * Copyright (c) 1982, 1990 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
af359dea C |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * 3. All advertising materials mentioning features or use of this software | |
14 | * must display the following acknowledgement: | |
15 | * This product includes software developed by the University of | |
16 | * California, Berkeley and its contributors. | |
17 | * 4. Neither the name of the University nor the names of its contributors | |
18 | * may be used to endorse or promote products derived from this software | |
19 | * without specific prior written permission. | |
a8fd2d0d | 20 | * |
af359dea C |
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
31 | * SUCH DAMAGE. | |
32 | * | |
33 | * @(#)hpib.c 7.5 (Berkeley) 5/7/91 | |
a8fd2d0d KM |
34 | */ |
35 | ||
36 | /* | |
37 | * HPIB driver | |
38 | */ | |
af359dea C |
39 | #include <sys/param.h> |
40 | #include <sys/reboot.h> | |
b28b3a13 | 41 | #include "../dev/device.h" |
a8fd2d0d KM |
42 | #include "hpibvar.h" |
43 | ||
44 | #include "saio.h" | |
45 | #include "samachdep.h" | |
46 | ||
af359dea | 47 | int internalhpib = IIOV(0x478000); |
a8fd2d0d KM |
48 | int fhpibppoll(), nhpibppoll(); |
49 | ||
50 | struct hpib_softc hpib_softc[NHPIB]; | |
51 | ||
52 | #define hpibunit(x) ((x) >> 3) | |
53 | #define hpibslave(x) ((x) & 7) | |
54 | ||
55 | hpibinit() | |
56 | { | |
57 | extern struct hp_hw sc_table[]; | |
58 | register struct hp_hw *hw; | |
59 | register struct hpib_softc *hs; | |
60 | register int i, addr; | |
61 | static int first = 1; | |
62 | ||
63 | i = 0; | |
af359dea C |
64 | for (hw = sc_table; i < NHPIB && hw < &sc_table[MAXCTLRS]; hw++) { |
65 | if (!HW_ISHPIB(hw)) | |
a8fd2d0d KM |
66 | continue; |
67 | hs = &hpib_softc[i]; | |
af359dea | 68 | hs->sc_addr = hw->hw_kva; |
a8fd2d0d KM |
69 | if (nhpibinit(i) == 0) |
70 | if (fhpibinit(i) == 0) | |
71 | continue; | |
72 | if (howto & RB_ASKNAME) | |
73 | printf("hpib%d at sc%d\n", i, hw->hw_sc); | |
74 | /* | |
75 | * Adjust devtype on first call. This routine assumes that | |
76 | * adaptor is in the high byte of devtype. | |
77 | */ | |
78 | if (first && ((devtype >> 24) & 0xff) == hw->hw_sc) { | |
79 | devtype = (devtype & 0x00ffffff) | (i << 24); | |
80 | first = 0; | |
81 | } | |
82 | hs->sc_alive = 1; | |
83 | i++; | |
84 | } | |
85 | } | |
86 | ||
87 | hpibalive(unit) | |
88 | register int unit; | |
89 | { | |
90 | unit = hpibunit(unit); | |
91 | if (unit >= NHPIB || hpib_softc[unit].sc_alive == 0) | |
92 | return (0); | |
93 | return (1); | |
94 | } | |
95 | ||
96 | hpibid(unit) | |
97 | register int unit; | |
98 | { | |
99 | register struct hpib_softc *hs = &hpib_softc[hpibunit(unit)]; | |
100 | register int slave; | |
101 | short id; | |
102 | ||
103 | slave = hpibslave(unit); | |
104 | unit = hpibunit(unit); | |
105 | if (hs->sc_type == HPIBC) | |
106 | slave = fhpibrecv(unit, 31, slave, &id, 2); | |
107 | else | |
108 | slave = nhpibrecv(unit, 31, slave, &id, 2); | |
109 | if (slave != 2) | |
110 | return (0); | |
111 | return (id); | |
112 | } | |
113 | ||
114 | hpibsend(unit, sec, buf, cnt) | |
115 | register char *buf; | |
116 | register int cnt; | |
117 | { | |
118 | register struct hpib_softc *hs = &hpib_softc[hpibunit(unit)]; | |
119 | register int slave; | |
120 | ||
121 | slave = hpibslave(unit); | |
122 | unit = hpibunit(unit); | |
123 | if (hs->sc_type == HPIBC) | |
124 | return (fhpibsend(unit, slave, sec, buf, cnt)); | |
125 | else | |
126 | return (nhpibsend(unit, slave, sec, buf, cnt)); | |
127 | } | |
128 | ||
129 | hpibrecv(unit, sec, buf, cnt) | |
130 | register char *buf; | |
131 | register int cnt; | |
132 | { | |
133 | register struct hpib_softc *hs = &hpib_softc[hpibunit(unit)]; | |
134 | register int slave; | |
135 | ||
136 | slave = hpibslave(unit); | |
137 | unit = hpibunit(unit); | |
138 | if (hs->sc_type == HPIBC) | |
139 | return (fhpibrecv(unit, slave, sec, buf, cnt)); | |
140 | else | |
141 | return (nhpibrecv(unit, slave, sec, buf, cnt)); | |
142 | } | |
143 | ||
144 | hpibswait(unit) | |
145 | register int unit; | |
146 | { | |
147 | register int timo = 1000000; | |
148 | register int slave = 0x80 >> hpibslave(unit); | |
149 | register int (*poll)(); | |
150 | ||
151 | unit = hpibunit(unit); | |
152 | if (hpib_softc[unit].sc_type == HPIBC) | |
153 | poll = fhpibppoll; | |
154 | else | |
155 | poll = nhpibppoll; | |
156 | while (((*poll)(unit) & slave) == 0) | |
157 | if (--timo == 0) | |
158 | break; | |
159 | if (timo == 0) | |
160 | return (-1); | |
161 | return (0); | |
162 | } | |
163 | ||
164 | hpibgo(unit, sec, addr, count, flag) | |
165 | register int unit; | |
166 | char *addr; | |
167 | { | |
168 | register int slave; | |
169 | ||
170 | slave = hpibslave(unit); | |
171 | unit = hpibunit(unit); | |
172 | if (hpib_softc[unit].sc_type == HPIBC) | |
af359dea | 173 | if (flag == F_READ) |
a8fd2d0d KM |
174 | fhpibrecv(unit, slave, sec, addr, count); |
175 | else | |
176 | fhpibsend(unit, slave, sec, addr, count); | |
177 | else | |
af359dea | 178 | if (flag == F_READ) |
a8fd2d0d KM |
179 | nhpibrecv(unit, slave, sec, addr, count); |
180 | else | |
181 | nhpibsend(unit, slave, sec, addr, count); | |
182 | } |