hpib.c revision 1.2 1 /* $NetBSD: hpib.c,v 1.2 1997/05/12 07:48:23 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 * @(#)hpib.c 8.1 (Berkeley) 6/10/93
36 */
37
38 /*
39 * HPIB driver
40 */
41 #include <sys/param.h>
42 #include <sys/reboot.h>
43
44 #include <lib/libsa/stand.h>
45
46 #include <hp300/stand/common/device.h>
47 #include <hp300/stand/common/hpibvar.h>
48 #include <hp300/stand/common/samachdep.h>
49
50 #include <hp300/dev/dioreg.h>
51
52 int internalhpib = IIOV(DIO_IHPIBADDR);
53 int fhpibppoll(), nhpibppoll();
54
55 struct hpib_softc hpib_softc[NHPIB];
56
57 hpibinit()
58 {
59 extern struct hp_hw sc_table[];
60 register struct hp_hw *hw;
61 register struct hpib_softc *hs;
62 register int i, addr;
63
64 i = 0;
65 for (hw = sc_table; i < NHPIB && hw < &sc_table[MAXCTLRS]; hw++) {
66 if (!HW_ISHPIB(hw))
67 continue;
68 hs = &hpib_softc[i];
69 hs->sc_addr = hw->hw_kva;
70 if (nhpibinit(i) == 0)
71 if (fhpibinit(i) == 0)
72 continue;
73 if (howto & RB_ASKNAME)
74 printf("hpib%d at sc%d\n", i, hw->hw_sc);
75 hw->hw_pa = (caddr_t) i; /* XXX for autoconfig */
76 hs->sc_alive = 1;
77 i++;
78 }
79 }
80
81 hpibalive(unit)
82 register int unit;
83 {
84 if (unit >= NHPIB || hpib_softc[unit].sc_alive == 0)
85 return (0);
86 return (1);
87 }
88
89 hpibid(unit, slave)
90 int unit, slave;
91 {
92 short id;
93 int rv;
94
95 if (hpib_softc[unit].sc_type == HPIBC)
96 rv = fhpibrecv(unit, 31, slave, &id, 2);
97 else
98 rv = nhpibrecv(unit, 31, slave, &id, 2);
99 if (rv != 2)
100 return (0);
101 return (id);
102 }
103
104 hpibsend(unit, slave, sec, buf, cnt)
105 int unit, slave;
106 char *buf;
107 int cnt;
108 {
109 if (hpib_softc[unit].sc_type == HPIBC)
110 return (fhpibsend(unit, slave, sec, buf, cnt));
111 return (nhpibsend(unit, slave, sec, buf, cnt));
112 }
113
114 hpibrecv(unit, slave, sec, buf, cnt)
115 int unit, slave;
116 char *buf;
117 int cnt;
118 {
119 if (hpib_softc[unit].sc_type == HPIBC)
120 return (fhpibrecv(unit, slave, sec, buf, cnt));
121 return (nhpibrecv(unit, slave, sec, buf, cnt));
122 }
123
124 hpibswait(unit, slave)
125 register int unit, slave;
126 {
127 register int timo = 1000000;
128 register int (*poll)();
129
130 slave = 0x80 >> slave;
131 if (hpib_softc[unit].sc_type == HPIBC)
132 poll = fhpibppoll;
133 else
134 poll = nhpibppoll;
135 while (((*poll)(unit) & slave) == 0)
136 if (--timo == 0)
137 break;
138 if (timo == 0)
139 return (-1);
140 return (0);
141 }
142
143 hpibgo(unit, slave, sec, addr, count, flag)
144 int unit, slave;
145 char *addr;
146 {
147 if (hpib_softc[unit].sc_type == HPIBC)
148 if (flag == F_READ)
149 fhpibrecv(unit, slave, sec, addr, count);
150 else
151 fhpibsend(unit, slave, sec, addr, count);
152 else
153 if (flag == F_READ)
154 nhpibrecv(unit, slave, sec, addr, count);
155 else
156 nhpibsend(unit, slave, sec, addr, count);
157 }
158