hpib.c revision 1.5 1 /* $NetBSD: hpib.c,v 1.5 2005/02/20 13:59:27 tsutsui 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
50 struct hpib_softc hpib_softc[NHPIB];
51
52 void
53 hpibinit(void)
54 {
55 extern struct hp_hw sc_table[];
56 struct hp_hw *hw;
57 struct hpib_softc *hs;
58 int i;
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 int
78 hpibalive(int unit)
79 {
80 if (unit >= NHPIB || hpib_softc[unit].sc_alive == 0)
81 return 0;
82 return 1;
83 }
84
85 int
86 hpibid(int unit, int slave)
87 {
88 short id;
89 int rv;
90
91 if (hpib_softc[unit].sc_type == HPIBC)
92 rv = fhpibrecv(unit, 31, slave, (char *)&id, 2);
93 else
94 rv = nhpibrecv(unit, 31, slave, (char *)&id, 2);
95 if (rv != 2)
96 return 0;
97 return id;
98 }
99
100 int
101 hpibsend(int unit, int slave, int sec, char *buf, int cnt)
102 {
103
104 if (hpib_softc[unit].sc_type == HPIBC)
105 return (fhpibsend(unit, slave, sec, buf, cnt));
106 return nhpibsend(unit, slave, sec, buf, cnt);
107 }
108
109 int
110 hpibrecv(int unit, int slave, int sec, char *buf, int cnt)
111 {
112
113 if (hpib_softc[unit].sc_type == HPIBC)
114 return (fhpibrecv(unit, slave, sec, buf, cnt));
115 return nhpibrecv(unit, slave, sec, buf, cnt);
116 }
117
118 int
119 hpibswait(int unit, int slave)
120 {
121 int timo = 1000000;
122 int (*poll)(int);
123
124 slave = 0x80 >> slave;
125 if (hpib_softc[unit].sc_type == HPIBC)
126 poll = fhpibppoll;
127 else
128 poll = nhpibppoll;
129 while (((*poll)(unit) & slave) == 0)
130 if (--timo == 0)
131 break;
132 if (timo == 0)
133 return -1;
134 return 0;
135 }
136
137 void
138 hpibgo(int unit, int slave, int sec, char *addr, int count, int flag)
139 {
140
141 if (hpib_softc[unit].sc_type == HPIBC)
142 if (flag == F_READ)
143 fhpibrecv(unit, slave, sec, addr, count);
144 else
145 fhpibsend(unit, slave, sec, addr, count);
146 else
147 if (flag == F_READ)
148 nhpibrecv(unit, slave, sec, addr, count);
149 else
150 nhpibsend(unit, slave, sec, addr, count);
151 }
152