ast.c revision 1.24 1 1.24 cgd /* $NetBSD: ast.c,v 1.24 1996/04/04 07:08:10 cgd 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.2 mycroft #include <sys/device.h>
38 1.1 cgd
39 1.22 cgd #include <machine/bus.h>
40 1.5 mycroft
41 1.17 cgd #include <dev/isa/isavar.h>
42 1.20 cgd #include <dev/isa/comreg.h>
43 1.21 cgd #include <dev/isa/comvar.h>
44 1.20 cgd
45 1.20 cgd #define NSLAVES 4
46 1.1 cgd
47 1.2 mycroft struct ast_softc {
48 1.2 mycroft struct device sc_dev;
49 1.17 cgd void *sc_ih;
50 1.7 mycroft
51 1.22 cgd bus_chipset_tag_t sc_bc;
52 1.11 mycroft int sc_iobase;
53 1.22 cgd
54 1.20 cgd int sc_alive; /* mask of slave units attached */
55 1.20 cgd void *sc_slaves[NSLAVES]; /* com device unit numbers */
56 1.22 cgd bus_io_handle_t sc_slaveioh[NSLAVES];
57 1.5 mycroft };
58 1.5 mycroft
59 1.5 mycroft int astprobe();
60 1.5 mycroft void astattach();
61 1.17 cgd int astintr __P((void *));
62 1.5 mycroft
63 1.23 thorpej struct cfattach ast_ca = {
64 1.23 thorpej sizeof(struct ast_softc), astprobe, astattach
65 1.23 thorpej };
66 1.23 thorpej
67 1.23 thorpej struct cfdriver ast_cd = {
68 1.23 thorpej NULL, "ast", DV_TTY
69 1.5 mycroft };
70 1.1 cgd
71 1.1 cgd int
72 1.5 mycroft astprobe(parent, self, aux)
73 1.5 mycroft struct device *parent, *self;
74 1.5 mycroft void *aux;
75 1.1 cgd {
76 1.5 mycroft struct isa_attach_args *ia = aux;
77 1.22 cgd int iobase = ia->ia_iobase;
78 1.22 cgd bus_chipset_tag_t bc = ia->ia_bc;
79 1.22 cgd bus_io_handle_t ioh;
80 1.22 cgd int i, rv = 1;
81 1.2 mycroft
82 1.1 cgd /*
83 1.1 cgd * Do the normal com probe for the first UART and assume
84 1.22 cgd * its presence, and the ability to map the other UARTS,
85 1.22 cgd * means there is a multiport board there.
86 1.5 mycroft * XXX Needs more robustness.
87 1.1 cgd */
88 1.1 cgd
89 1.22 cgd /* if the first port is in use as console, then it. */
90 1.22 cgd if (iobase == comconsaddr && !comconsattached)
91 1.22 cgd goto checkmappings;
92 1.22 cgd
93 1.22 cgd if (bus_io_map(bc, iobase, COM_NPORTS, &ioh)) {
94 1.22 cgd rv = 0;
95 1.22 cgd goto out;
96 1.22 cgd }
97 1.22 cgd rv = comprobe1(bc, ioh, iobase);
98 1.22 cgd bus_io_unmap(bc, ioh, COM_NPORTS);
99 1.22 cgd if (rv == 0)
100 1.22 cgd goto out;
101 1.22 cgd
102 1.22 cgd checkmappings:
103 1.22 cgd for (i = 1; i < NSLAVES; i++) {
104 1.22 cgd iobase += COM_NPORTS;
105 1.22 cgd
106 1.22 cgd if (iobase == comconsaddr && !comconsattached)
107 1.22 cgd continue;
108 1.22 cgd
109 1.22 cgd if (bus_io_map(bc, iobase, COM_NPORTS, &ioh)) {
110 1.22 cgd rv = 0;
111 1.22 cgd goto out;
112 1.22 cgd }
113 1.22 cgd bus_io_unmap(bc, ioh, COM_NPORTS);
114 1.22 cgd }
115 1.2 mycroft
116 1.22 cgd out:
117 1.22 cgd if (rv)
118 1.22 cgd ia->ia_iosize = NSLAVES * COM_NPORTS;
119 1.22 cgd return (rv);
120 1.10 mycroft }
121 1.10 mycroft
122 1.10 mycroft int
123 1.22 cgd astprint(aux, pnp)
124 1.10 mycroft void *aux;
125 1.22 cgd char *pnp;
126 1.10 mycroft {
127 1.22 cgd struct commulti_attach_args *ca = aux;
128 1.10 mycroft
129 1.22 cgd if (pnp)
130 1.22 cgd printf("com at %s", pnp);
131 1.21 cgd printf(" slave %d", ca->ca_slave);
132 1.22 cgd return (UNCONF);
133 1.1 cgd }
134 1.1 cgd
135 1.1 cgd void
136 1.5 mycroft astattach(parent, self, aux)
137 1.5 mycroft struct device *parent, *self;
138 1.5 mycroft void *aux;
139 1.1 cgd {
140 1.5 mycroft struct ast_softc *sc = (void *)self;
141 1.5 mycroft struct isa_attach_args *ia = aux;
142 1.21 cgd struct commulti_attach_args ca;
143 1.22 cgd int i, subunit;
144 1.10 mycroft
145 1.22 cgd sc->sc_bc = ia->ia_bc;
146 1.10 mycroft sc->sc_iobase = ia->ia_iobase;
147 1.1 cgd
148 1.22 cgd for (i = 0; i < NSLAVES; i++)
149 1.22 cgd if (bus_io_map(bc, sc->sc_iobase + i * COM_NPORTS, COM_NPORTS,
150 1.22 cgd &sc->sc_slaveioh[i]))
151 1.22 cgd panic("astattach: couldn't map slave %d", i);
152 1.22 cgd
153 1.5 mycroft /*
154 1.5 mycroft * Enable the master interrupt.
155 1.5 mycroft */
156 1.22 cgd bus_io_write_1(bc, sc->sc_slaveioh[3], 7, 0x80);
157 1.10 mycroft
158 1.5 mycroft printf("\n");
159 1.5 mycroft
160 1.22 cgd for (i = 0; i < NSLAVES; i++) {
161 1.22 cgd struct cfdata *match;
162 1.22 cgd
163 1.22 cgd ca.ca_slave = i;
164 1.22 cgd ca.ca_bc = sc->sc_bc;
165 1.22 cgd ca.ca_ioh = sc->sc_slaveioh[i];
166 1.22 cgd ca.ca_iobase = sc->sc_iobase + i * COM_NPORTS;
167 1.22 cgd ca.ca_noien = 1;
168 1.22 cgd
169 1.24 cgd sc->sc_slaves[i] = config_found(self, &ca, astprint);
170 1.24 cgd if (sc->sc_slaves[i] != NULL)
171 1.22 cgd sc->sc_alive |= 1 << i;
172 1.10 mycroft }
173 1.7 mycroft
174 1.19 mycroft sc->sc_ih = isa_intr_establish(ia->ia_irq, IST_EDGE, IPL_TTY, astintr,
175 1.19 mycroft sc);
176 1.1 cgd }
177 1.1 cgd
178 1.1 cgd int
179 1.17 cgd astintr(arg)
180 1.17 cgd void *arg;
181 1.1 cgd {
182 1.17 cgd struct ast_softc *sc = arg;
183 1.22 cgd bus_chipset_tag_t bc = sc->sc_bc;
184 1.2 mycroft int alive = sc->sc_alive;
185 1.1 cgd int bits;
186 1.1 cgd
187 1.22 cgd bits = ~bus_io_read_1(bc, sc->sc_slaveioh[3], 7) & alive;
188 1.8 mycroft if (bits == 0)
189 1.10 mycroft return (0);
190 1.2 mycroft
191 1.8 mycroft for (;;) {
192 1.2 mycroft #define TRY(n) \
193 1.8 mycroft if (bits & (1 << (n))) \
194 1.5 mycroft comintr(sc->sc_slaves[n]);
195 1.2 mycroft TRY(0);
196 1.2 mycroft TRY(1);
197 1.2 mycroft TRY(2);
198 1.2 mycroft TRY(3);
199 1.5 mycroft #undef TRY
200 1.22 cgd bits = ~bus_io_read_1(bc, sc->sc_slaveioh[3], 7) & alive;
201 1.8 mycroft if (bits == 0)
202 1.10 mycroft return (1);
203 1.8 mycroft }
204 1.1 cgd }
205