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