ast.c revision 1.14 1 1.14 mycroft /* $NetBSD: ast.c,v 1.14 1995/01/03 01:30:20 mycroft Exp $ */
2 1.9 cgd
3 1.1 cgd /*
4 1.1 cgd * Multi-port serial card interrupt demuxing support.
5 1.1 cgd * Roland McGrath 3/20/94
6 1.4 cgd * The author disclaims copyright and places this file in the public domain.
7 1.1 cgd *
8 1.4 cgd * Modified by: Charles Hannum, 3/22/94
9 1.1 cgd */
10 1.1 cgd
11 1.5 mycroft #include <sys/param.h>
12 1.2 mycroft #include <sys/device.h>
13 1.1 cgd
14 1.1 cgd #include <machine/pio.h>
15 1.5 mycroft
16 1.5 mycroft #include <i386/isa/isavar.h>
17 1.1 cgd
18 1.2 mycroft struct ast_softc {
19 1.2 mycroft struct device sc_dev;
20 1.7 mycroft struct intrhand sc_ih;
21 1.7 mycroft
22 1.11 mycroft int sc_iobase;
23 1.5 mycroft int sc_alive; /* mask of slave units attached */
24 1.7 mycroft void *sc_slaves[4]; /* com device unit numbers */
25 1.5 mycroft };
26 1.5 mycroft
27 1.5 mycroft int astprobe();
28 1.5 mycroft void astattach();
29 1.7 mycroft int astintr __P((struct ast_softc *));
30 1.5 mycroft
31 1.5 mycroft struct cfdriver astcd = {
32 1.13 mycroft NULL, "ast", astprobe, astattach, DV_TTY, sizeof(struct ast_softc)
33 1.5 mycroft };
34 1.1 cgd
35 1.1 cgd int
36 1.5 mycroft astprobe(parent, self, aux)
37 1.5 mycroft struct device *parent, *self;
38 1.5 mycroft void *aux;
39 1.1 cgd {
40 1.5 mycroft struct isa_attach_args *ia = aux;
41 1.2 mycroft
42 1.1 cgd /*
43 1.1 cgd * Do the normal com probe for the first UART and assume
44 1.1 cgd * its presence means there is a multiport board there.
45 1.5 mycroft * XXX Needs more robustness.
46 1.1 cgd */
47 1.6 mycroft ia->ia_iosize = 4 * 8;
48 1.10 mycroft return (comprobe1(ia->ia_iobase));
49 1.1 cgd }
50 1.1 cgd
51 1.5 mycroft struct ast_attach_args {
52 1.5 mycroft int aa_slave;
53 1.5 mycroft };
54 1.5 mycroft
55 1.1 cgd int
56 1.10 mycroft astsubmatch(parent, match, aux)
57 1.10 mycroft struct device *parent;
58 1.10 mycroft void *match, *aux;
59 1.1 cgd {
60 1.5 mycroft struct ast_softc *sc = (void *)parent;
61 1.10 mycroft struct device *self = match;
62 1.10 mycroft struct isa_attach_args *ia = aux;
63 1.10 mycroft struct ast_attach_args *aa = ia->ia_aux;
64 1.5 mycroft struct cfdata *cf = self->dv_cfdata;
65 1.2 mycroft
66 1.10 mycroft if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != aa->aa_slave)
67 1.10 mycroft return (0);
68 1.10 mycroft return ((*cf->cf_driver->cd_match)(parent, match, ia));
69 1.10 mycroft }
70 1.10 mycroft
71 1.10 mycroft int
72 1.10 mycroft astprint(aux, ast)
73 1.10 mycroft void *aux;
74 1.10 mycroft char *ast;
75 1.10 mycroft {
76 1.10 mycroft struct isa_attach_args *ia = aux;
77 1.10 mycroft struct ast_attach_args *aa = ia->ia_aux;
78 1.10 mycroft
79 1.10 mycroft printf(" slave %d", aa->aa_slave);
80 1.1 cgd }
81 1.1 cgd
82 1.1 cgd void
83 1.5 mycroft astattach(parent, self, aux)
84 1.5 mycroft struct device *parent, *self;
85 1.5 mycroft void *aux;
86 1.1 cgd {
87 1.5 mycroft struct ast_softc *sc = (void *)self;
88 1.5 mycroft struct isa_attach_args *ia = aux;
89 1.5 mycroft struct ast_attach_args aa;
90 1.10 mycroft struct isa_attach_args isa;
91 1.10 mycroft
92 1.10 mycroft sc->sc_iobase = ia->ia_iobase;
93 1.1 cgd
94 1.5 mycroft /*
95 1.5 mycroft * Enable the master interrupt.
96 1.5 mycroft */
97 1.5 mycroft outb(sc->sc_iobase | 0x1f, 0x80);
98 1.10 mycroft
99 1.5 mycroft printf("\n");
100 1.5 mycroft
101 1.10 mycroft isa.ia_aux = &aa;
102 1.10 mycroft for (aa.aa_slave = 0; aa.aa_slave < 4; aa.aa_slave++) {
103 1.13 mycroft struct cfdata *cf;
104 1.10 mycroft isa.ia_iobase = sc->sc_iobase + 8 * aa.aa_slave;
105 1.10 mycroft isa.ia_iosize = 0x666;
106 1.10 mycroft isa.ia_irq = IRQUNK;
107 1.10 mycroft isa.ia_drq = DRQUNK;
108 1.10 mycroft isa.ia_msize = 0;
109 1.13 mycroft if ((cf = config_search(astsubmatch, self, &isa)) != 0) {
110 1.13 mycroft config_attach(self, cf, &isa, astprint);
111 1.13 mycroft sc->sc_slaves[aa.aa_slave] =
112 1.13 mycroft cf->cf_driver->cd_devs[cf->cf_unit];
113 1.10 mycroft sc->sc_alive |= 1 << aa.aa_slave;
114 1.10 mycroft }
115 1.10 mycroft }
116 1.7 mycroft
117 1.7 mycroft sc->sc_ih.ih_fun = astintr;
118 1.7 mycroft sc->sc_ih.ih_arg = sc;
119 1.7 mycroft sc->sc_ih.ih_level = IPL_TTY;
120 1.14 mycroft intr_establish(ia->ia_irq, IST_EDGE, &sc->sc_ih);
121 1.1 cgd }
122 1.1 cgd
123 1.1 cgd int
124 1.7 mycroft astintr(sc)
125 1.7 mycroft struct ast_softc *sc;
126 1.1 cgd {
127 1.12 mycroft int iobase = sc->sc_iobase;
128 1.2 mycroft int alive = sc->sc_alive;
129 1.1 cgd int bits;
130 1.1 cgd
131 1.10 mycroft bits = ~inb(iobase | 0x1f) & alive;
132 1.8 mycroft if (bits == 0)
133 1.10 mycroft return (0);
134 1.2 mycroft
135 1.8 mycroft for (;;) {
136 1.2 mycroft #define TRY(n) \
137 1.8 mycroft if (bits & (1 << (n))) \
138 1.5 mycroft comintr(sc->sc_slaves[n]);
139 1.2 mycroft TRY(0);
140 1.2 mycroft TRY(1);
141 1.2 mycroft TRY(2);
142 1.2 mycroft TRY(3);
143 1.5 mycroft #undef TRY
144 1.10 mycroft bits = ~inb(iobase | 0x1f) & alive;
145 1.8 mycroft if (bits == 0)
146 1.10 mycroft return (1);
147 1.8 mycroft }
148 1.1 cgd }
149