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