ast.c revision 1.1 1 /*
2 * Multi-port serial card interrupt demuxing support.
3 * Roland McGrath 3/20/94
4 *
5 * $Id: ast.c,v 1.1 1994/03/23 01:26:14 cgd Exp $
6 */
7
8 #include "ast.h"
9
10 #include <sys/types.h>
11
12 #include <machine/pio.h>
13 #include <i386/isa/isa_device.h>
14
15 int astprobe __P((struct isa_device *));
16 int astattach __P((struct isa_device *));
17
18 struct isa_driver astdriver = {
19 astprobe, astattach, "ast"
20 };
21
22 struct astunit /* XXX ast_softc? */
23 {
24 u_short iobase;
25 int alive; /* Mask of slave units attached. */
26 int slaveunits[8]; /* com device unit numbers. XXX - softc ptrs */
27 } astunits[NAST];
28
29 int
30 astprobe(struct isa_device *isa_dev)
31 {
32 /*
33 * Do the normal com probe for the first UART and assume
34 * its presence means there is a multiport board there.
35 * XXX needs more robustness.
36 */
37 return comprobe1(isa_dev->id_iobase);
38 }
39
40 int
41 astattach(struct isa_device *isa_dev)
42 {
43 int unit = isa_dev->id_unit;
44 u_short iobase = isa_dev->id_iobase;
45 unsigned int x;
46
47 astunits[unit].iobase = iobase;
48
49 /*
50 * XXX calculation of master address is a bit hazy --
51 * what if > 4 ports, etc.
52 */
53 outb (iobase | 0x1f, 0x80);
54 x = inb (iobase | 0x1f);
55 /*
56 * My guess is this bitmask tells you how many ports are there.
57 * I only have a 4-port board to try (returns 0xf). --roland
58 */
59 printf ("ast%d: 0x%x\n", unit, x);
60 }
61
62 void
63 astslave(struct isa_device *slave, int comunit)
64 {
65 struct astunit *a = &astunits[slave->id_parent->id_unit];
66
67 a->slaveunits[slave->id_physid] = comunit;
68 a->alive |= 1 << slave->id_physid;
69 }
70
71 int
72 astintr(int unit)
73 {
74 struct astunit *a = &astunits[unit];
75 u_short iobase = a->iobase;
76 int alive = a->alive;
77 int bits;
78
79 do {
80 bits = inb (iobase | 0x1f) & alive;
81 #define TRY(I) ((bits & (1 << (I))) ? 0 : comintr (a->slaveunits[I]))
82 TRY (0), TRY (1), TRY (2), TRY (3);
83 /* XXX -- i think the next 4 are bogus, see above -- cgd */
84 TRY (4), TRY (5), TRY (6), TRY (7);
85 #undef TRY
86 } while (bits != alive);
87
88 return 1;
89 }
90