1 /*
2 * Copyright (c) 1982, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 *
7 * @(#)hpib.c 8.1 (Berkeley) 06/10/93
8 */
9
10 /*
11 * HPIB driver
12 */
13 #include <sys/param.h>
14 #include <sys/reboot.h>
15 #include <hp/dev/device.h>
16 #include <hp300/stand/hpibvar.h>
17
18 #include <stand.att/saio.h>
19 #include <hp300/stand/samachdep.h>
20
21 int internalhpib = IIOV(0x478000);
22 int fhpibppoll(), nhpibppoll();
23
24 struct hpib_softc hpib_softc[NHPIB];
25
hpibinit()26 hpibinit()
27 {
28 extern struct hp_hw sc_table[];
29 register struct hp_hw *hw;
30 register struct hpib_softc *hs;
31 register int i, addr;
32
33 i = 0;
34 for (hw = sc_table; i < NHPIB && hw < &sc_table[MAXCTLRS]; hw++) {
35 if (!HW_ISHPIB(hw))
36 continue;
37 hs = &hpib_softc[i];
38 hs->sc_addr = hw->hw_kva;
39 if (nhpibinit(i) == 0)
40 if (fhpibinit(i) == 0)
41 continue;
42 if (howto & RB_ASKNAME)
43 printf("hpib%d at sc%d\n", i, hw->hw_sc);
44 hw->hw_pa = (caddr_t) i; /* XXX for autoconfig */
45 hs->sc_alive = 1;
46 i++;
47 }
48 }
49
hpibalive(unit)50 hpibalive(unit)
51 register int unit;
52 {
53 if (unit >= NHPIB || hpib_softc[unit].sc_alive == 0)
54 return (0);
55 return (1);
56 }
57
hpibid(unit,slave)58 hpibid(unit, slave)
59 int unit, slave;
60 {
61 short id;
62 int rv;
63
64 if (hpib_softc[unit].sc_type == HPIBC)
65 rv = fhpibrecv(unit, 31, slave, &id, 2);
66 else
67 rv = nhpibrecv(unit, 31, slave, &id, 2);
68 if (rv != 2)
69 return (0);
70 return (id);
71 }
72
hpibsend(unit,slave,sec,buf,cnt)73 hpibsend(unit, slave, sec, buf, cnt)
74 int unit, slave;
75 char *buf;
76 int cnt;
77 {
78 if (hpib_softc[unit].sc_type == HPIBC)
79 return (fhpibsend(unit, slave, sec, buf, cnt));
80 return (nhpibsend(unit, slave, sec, buf, cnt));
81 }
82
hpibrecv(unit,slave,sec,buf,cnt)83 hpibrecv(unit, slave, sec, buf, cnt)
84 int unit, slave;
85 char *buf;
86 int cnt;
87 {
88 if (hpib_softc[unit].sc_type == HPIBC)
89 return (fhpibrecv(unit, slave, sec, buf, cnt));
90 return (nhpibrecv(unit, slave, sec, buf, cnt));
91 }
92
hpibswait(unit,slave)93 hpibswait(unit, slave)
94 register int unit, slave;
95 {
96 register int timo = 1000000;
97 register int (*poll)();
98
99 slave = 0x80 >> slave;
100 if (hpib_softc[unit].sc_type == HPIBC)
101 poll = fhpibppoll;
102 else
103 poll = nhpibppoll;
104 while (((*poll)(unit) & slave) == 0)
105 if (--timo == 0)
106 break;
107 if (timo == 0)
108 return (-1);
109 return (0);
110 }
111
hpibgo(unit,slave,sec,addr,count,flag)112 hpibgo(unit, slave, sec, addr, count, flag)
113 int unit, slave;
114 char *addr;
115 {
116 if (hpib_softc[unit].sc_type == HPIBC)
117 if (flag == F_READ)
118 fhpibrecv(unit, slave, sec, addr, count);
119 else
120 fhpibsend(unit, slave, sec, addr, count);
121 else
122 if (flag == F_READ)
123 nhpibrecv(unit, slave, sec, addr, count);
124 else
125 nhpibsend(unit, slave, sec, addr, count);
126 }
127