ast.c revision 1.3 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.3 1994/03/23 03:04:32 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. I think the AST protocol simply does not
70 * support more than 4 ports. - mycroft
71 */
72 printf("%s: 0x%x\n", sc->sc_dev.dv_xname, x);
73 }
74
75 void
76 astslave(dev)
77 struct isa_device *dev;
78 {
79 struct ast_softc *sc = &ast_softc[dev->id_parent->id_unit];
80
81 sc->sc_slaves[dev->id_physid] = dev->id_unit;
82 sc->sc_alive |= 1 << dev->id_physid;
83 }
84
85 int
86 astintr(unit)
87 int unit;
88 {
89 struct ast_softc *sc = &ast_softc[unit];
90 u_short iobase = sc->sc_iobase;
91 int alive = sc->sc_alive;
92 int bits;
93
94 bits = inb(iobase | 0x1f) & alive;
95 if (bits == alive)
96 return 0;
97
98 do {
99 #define TRY(n) \
100 if ((bits & (1 << (n))) == 0) \
101 comintr(sc->sc_slaves[n]); /* XXX softc ptr */
102 TRY(0);
103 TRY(1);
104 TRY(2);
105 TRY(3);
106 #ifdef notdef
107 TRY(4);
108 TRY(5);
109 TRY(6);
110 TRY(7);
111 #endif
112 bits = inb(iobase | 0x1f) & alive;
113 } while (bits != alive);
114
115 return 1;
116 }
117