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