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