ast.c revision 1.2 1 /*
2 * Multi-port serial card interrupt demuxing support.
3 * Roland McGrath 3/20/94
4 * Charles Hannum 3/22/94
5 *
6 * $Id: ast.c,v 1.2 1994/03/23 03:01:50 mycroft Exp $
7 */
8
9 #include "ast.h"
10
11 #include <sys/types.h>
12 #include <sys/device.h>
13
14 #include <machine/pio.h>
15 #include <i386/isa/isa_device.h>
16
17 int astprobe __P((struct isa_device *));
18 int astattach __P((struct isa_device *));
19
20 struct isa_driver astdriver = {
21 astprobe, astattach, "ast"
22 };
23
24 struct ast_softc {
25 struct device sc_dev;
26 u_short sc_iobase;
27 int sc_alive; /* Mask of slave units attached. */
28 int sc_slaves[8]; /* com device unit numbers. XXX - softc ptrs */
29 } ast_softc[NAST];
30
31 int
32 astprobe(dev)
33 struct isa_device *dev;
34 {
35
36 /*
37 * Do the normal com probe for the first UART and assume
38 * its presence means there is a multiport board there.
39 * XXX needs more robustness.
40 */
41 return comprobe1(dev->id_iobase);
42 }
43
44 int
45 astattach(dev)
46 struct isa_device *dev;
47 {
48 struct ast_softc *sc = &ast_softc[dev->id_unit];
49 u_short iobase = dev->id_iobase;
50 unsigned int x;
51
52 /* XXX HACK */
53 sprintf(sc->sc_dev.dv_xname, "%s%d", astdriver.name, dev->id_unit);
54 sc->sc_dev.dv_unit = dev->id_unit;
55
56 sc->sc_iobase = iobase;
57
58 /*
59 * Enable the master interrupt.
60 */
61 outb(iobase | 0x1f, 0x80);
62 x = inb(iobase | 0x1f);
63 /*
64 * My guess is this bitmask tells you how many ports are there.
65 * I only have a 4-port board to try (returns 0xf). --roland
66 *
67 * It's also not clear that it would be correct to rely on this, since
68 * there might be an interrupt pending on one of the ports, and thus
69 * its bit wouldn't be set. - mycroft
70 */
71 printf("%s: 0x%x\n", sc->sc_dev.dv_xname, x);
72 }
73
74 void
75 astslave(dev)
76 struct isa_device *dev;
77 {
78 struct ast_softc *sc = &ast_softc[dev->id_parent->id_unit];
79
80 sc->sc_slaves[dev->id_physid] = dev->id_unit;
81 sc->sc_alive |= 1 << dev->id_physid;
82 }
83
84 int
85 astintr(unit)
86 int unit;
87 {
88 struct ast_softc *sc = &ast_softc[unit];
89 u_short iobase = sc->sc_iobase;
90 int alive = sc->sc_alive;
91 int bits;
92
93 bits = inb(iobase | 0x1f) & alive;
94 if (bits == alive)
95 return 0;
96
97 do {
98 #define TRY(n) \
99 if ((bits & (1 << (n))) == 0) \
100 comintr(sc->sc_slaves[n]); /* XXX softc ptr */
101 TRY(0);
102 TRY(1);
103 TRY(2);
104 TRY(3);
105 TRY(4);
106 TRY(5);
107 TRY(6);
108 TRY(7);
109 bits = inb(iobase | 0x1f) & alive;
110 } while (bits != alive);
111
112 return 1;
113 }
114