ast.c revision 1.26 1 /* $NetBSD: ast.c,v 1.26 1996/04/15 18:55:23 cgd Exp $ */
2
3 /*
4 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
5 * Copyright (c) 1995 Charles Hannum. All rights reserved.
6 *
7 * This code is derived from public-domain software written by
8 * Roland McGrath.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by Charles Hannum.
21 * 4. The name of the author may not be used to endorse or promote products
22 * derived from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35
36 #include <sys/param.h>
37 #include <sys/device.h>
38 #include <sys/termios.h>
39
40 #ifdef i386 /* XXX */
41 #include <machine/cpu.h> /* XXX */
42 #else /* XXX */
43 #include <machine/intr.h>
44 #endif /* XXX */
45 #include <machine/bus.h>
46
47 #include <dev/isa/isavar.h>
48 #include <dev/isa/comreg.h>
49 #include <dev/isa/comvar.h>
50
51 #define NSLAVES 4
52
53 struct ast_softc {
54 struct device sc_dev;
55 void *sc_ih;
56
57 bus_chipset_tag_t sc_bc;
58 int sc_iobase;
59
60 int sc_alive; /* mask of slave units attached */
61 void *sc_slaves[NSLAVES]; /* com device unit numbers */
62 bus_io_handle_t sc_slaveioh[NSLAVES];
63 };
64
65 int astprobe();
66 void astattach();
67 int astintr __P((void *));
68
69 struct cfattach ast_ca = {
70 sizeof(struct ast_softc), astprobe, astattach
71 };
72
73 struct cfdriver ast_cd = {
74 NULL, "ast", DV_TTY
75 };
76
77 int
78 astprobe(parent, self, aux)
79 struct device *parent, *self;
80 void *aux;
81 {
82 struct isa_attach_args *ia = aux;
83 int iobase = ia->ia_iobase;
84 bus_chipset_tag_t bc = ia->ia_bc;
85 bus_io_handle_t ioh;
86 int i, rv = 1;
87
88 /*
89 * Do the normal com probe for the first UART and assume
90 * its presence, and the ability to map the other UARTS,
91 * means there is a multiport board there.
92 * XXX Needs more robustness.
93 */
94
95 /* if the first port is in use as console, then it. */
96 if (iobase == comconsaddr && !comconsattached)
97 goto checkmappings;
98
99 if (bus_io_map(bc, iobase, COM_NPORTS, &ioh)) {
100 rv = 0;
101 goto out;
102 }
103 rv = comprobe1(bc, ioh, iobase);
104 bus_io_unmap(bc, ioh, COM_NPORTS);
105 if (rv == 0)
106 goto out;
107
108 checkmappings:
109 for (i = 1; i < NSLAVES; i++) {
110 iobase += COM_NPORTS;
111
112 if (iobase == comconsaddr && !comconsattached)
113 continue;
114
115 if (bus_io_map(bc, iobase, COM_NPORTS, &ioh)) {
116 rv = 0;
117 goto out;
118 }
119 bus_io_unmap(bc, ioh, COM_NPORTS);
120 }
121
122 out:
123 if (rv)
124 ia->ia_iosize = NSLAVES * COM_NPORTS;
125 return (rv);
126 }
127
128 int
129 astprint(aux, pnp)
130 void *aux;
131 char *pnp;
132 {
133 struct commulti_attach_args *ca = aux;
134
135 if (pnp)
136 printf("com at %s", pnp);
137 printf(" slave %d", ca->ca_slave);
138 return (UNCONF);
139 }
140
141 void
142 astattach(parent, self, aux)
143 struct device *parent, *self;
144 void *aux;
145 {
146 struct ast_softc *sc = (void *)self;
147 struct isa_attach_args *ia = aux;
148 struct commulti_attach_args ca;
149 int i, subunit;
150
151 sc->sc_bc = ia->ia_bc;
152 sc->sc_iobase = ia->ia_iobase;
153
154 for (i = 0; i < NSLAVES; i++)
155 if (bus_io_map(bc, sc->sc_iobase + i * COM_NPORTS, COM_NPORTS,
156 &sc->sc_slaveioh[i]))
157 panic("astattach: couldn't map slave %d", i);
158
159 /*
160 * Enable the master interrupt.
161 */
162 bus_io_write_1(bc, sc->sc_slaveioh[3], 7, 0x80);
163
164 printf("\n");
165
166 for (i = 0; i < NSLAVES; i++) {
167 struct cfdata *match;
168
169 ca.ca_slave = i;
170 ca.ca_bc = sc->sc_bc;
171 ca.ca_ioh = sc->sc_slaveioh[i];
172 ca.ca_iobase = sc->sc_iobase + i * COM_NPORTS;
173 ca.ca_noien = 1;
174
175 sc->sc_slaves[i] = config_found(self, &ca, astprint);
176 if (sc->sc_slaves[i] != NULL)
177 sc->sc_alive |= 1 << i;
178 }
179
180 sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
181 IPL_TTY, astintr, sc);
182 }
183
184 int
185 astintr(arg)
186 void *arg;
187 {
188 struct ast_softc *sc = arg;
189 bus_chipset_tag_t bc = sc->sc_bc;
190 int alive = sc->sc_alive;
191 int bits;
192
193 bits = ~bus_io_read_1(bc, sc->sc_slaveioh[3], 7) & alive;
194 if (bits == 0)
195 return (0);
196
197 for (;;) {
198 #define TRY(n) \
199 if (bits & (1 << (n))) \
200 comintr(sc->sc_slaves[n]);
201 TRY(0);
202 TRY(1);
203 TRY(2);
204 TRY(3);
205 #undef TRY
206 bits = ~bus_io_read_1(bc, sc->sc_slaveioh[3], 7) & alive;
207 if (bits == 0)
208 return (1);
209 }
210 }
211