ast.c revision 1.20 1 1.20 cgd /* $NetBSD: ast.c,v 1.20 1996/03/09 00:09:06 cgd Exp $ */
2 1.9 cgd
3 1.1 cgd /*
4 1.15 mycroft * Copyright (c) 1995 Charles Hannum. All rights reserved.
5 1.1 cgd *
6 1.15 mycroft * This code is derived from public-domain software written by
7 1.15 mycroft * Roland McGrath.
8 1.15 mycroft *
9 1.15 mycroft * Redistribution and use in source and binary forms, with or without
10 1.15 mycroft * modification, are permitted provided that the following conditions
11 1.15 mycroft * are met:
12 1.15 mycroft * 1. Redistributions of source code must retain the above copyright
13 1.15 mycroft * notice, this list of conditions and the following disclaimer.
14 1.15 mycroft * 2. Redistributions in binary form must reproduce the above copyright
15 1.15 mycroft * notice, this list of conditions and the following disclaimer in the
16 1.15 mycroft * documentation and/or other materials provided with the distribution.
17 1.15 mycroft * 3. All advertising materials mentioning features or use of this software
18 1.15 mycroft * must display the following acknowledgement:
19 1.15 mycroft * This product includes software developed by Charles Hannum.
20 1.15 mycroft * 4. The name of the author may not be used to endorse or promote products
21 1.15 mycroft * derived from this software without specific prior written permission.
22 1.15 mycroft *
23 1.15 mycroft * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 1.15 mycroft * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 1.15 mycroft * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 1.15 mycroft * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 1.15 mycroft * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 1.15 mycroft * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 1.15 mycroft * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 1.15 mycroft * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 1.15 mycroft * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 1.15 mycroft * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 1.1 cgd */
34 1.1 cgd
35 1.5 mycroft #include <sys/param.h>
36 1.2 mycroft #include <sys/device.h>
37 1.1 cgd
38 1.1 cgd #include <machine/pio.h>
39 1.5 mycroft
40 1.17 cgd #include <dev/isa/isavar.h>
41 1.20 cgd #include <dev/isa/comreg.h>
42 1.20 cgd
43 1.20 cgd #define NSLAVES 4
44 1.1 cgd
45 1.2 mycroft struct ast_softc {
46 1.2 mycroft struct device sc_dev;
47 1.17 cgd void *sc_ih;
48 1.7 mycroft
49 1.11 mycroft int sc_iobase;
50 1.20 cgd int sc_alive; /* mask of slave units attached */
51 1.20 cgd void *sc_slaves[NSLAVES]; /* com device unit numbers */
52 1.5 mycroft };
53 1.5 mycroft
54 1.5 mycroft int astprobe();
55 1.5 mycroft void astattach();
56 1.17 cgd int astintr __P((void *));
57 1.5 mycroft
58 1.5 mycroft struct cfdriver astcd = {
59 1.13 mycroft NULL, "ast", astprobe, astattach, DV_TTY, sizeof(struct ast_softc)
60 1.5 mycroft };
61 1.1 cgd
62 1.1 cgd int
63 1.5 mycroft astprobe(parent, self, aux)
64 1.5 mycroft struct device *parent, *self;
65 1.5 mycroft void *aux;
66 1.1 cgd {
67 1.5 mycroft struct isa_attach_args *ia = aux;
68 1.2 mycroft
69 1.1 cgd /*
70 1.1 cgd * Do the normal com probe for the first UART and assume
71 1.1 cgd * its presence means there is a multiport board there.
72 1.5 mycroft * XXX Needs more robustness.
73 1.1 cgd */
74 1.20 cgd ia->ia_iosize = NSLAVES * COM_NPORTS;
75 1.10 mycroft return (comprobe1(ia->ia_iobase));
76 1.1 cgd }
77 1.1 cgd
78 1.5 mycroft struct ast_attach_args {
79 1.5 mycroft int aa_slave;
80 1.5 mycroft };
81 1.5 mycroft
82 1.1 cgd int
83 1.10 mycroft astsubmatch(parent, match, aux)
84 1.10 mycroft struct device *parent;
85 1.10 mycroft void *match, *aux;
86 1.1 cgd {
87 1.5 mycroft struct ast_softc *sc = (void *)parent;
88 1.16 mycroft struct cfdata *cf = match;
89 1.10 mycroft struct isa_attach_args *ia = aux;
90 1.10 mycroft struct ast_attach_args *aa = ia->ia_aux;
91 1.2 mycroft
92 1.10 mycroft if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != aa->aa_slave)
93 1.10 mycroft return (0);
94 1.10 mycroft return ((*cf->cf_driver->cd_match)(parent, match, ia));
95 1.10 mycroft }
96 1.10 mycroft
97 1.10 mycroft int
98 1.10 mycroft astprint(aux, ast)
99 1.10 mycroft void *aux;
100 1.10 mycroft char *ast;
101 1.10 mycroft {
102 1.10 mycroft struct isa_attach_args *ia = aux;
103 1.10 mycroft struct ast_attach_args *aa = ia->ia_aux;
104 1.10 mycroft
105 1.10 mycroft printf(" slave %d", aa->aa_slave);
106 1.1 cgd }
107 1.1 cgd
108 1.1 cgd void
109 1.5 mycroft astattach(parent, self, aux)
110 1.5 mycroft struct device *parent, *self;
111 1.5 mycroft void *aux;
112 1.1 cgd {
113 1.5 mycroft struct ast_softc *sc = (void *)self;
114 1.5 mycroft struct isa_attach_args *ia = aux;
115 1.5 mycroft struct ast_attach_args aa;
116 1.10 mycroft struct isa_attach_args isa;
117 1.18 cgd int subunit;
118 1.10 mycroft
119 1.10 mycroft sc->sc_iobase = ia->ia_iobase;
120 1.1 cgd
121 1.5 mycroft /*
122 1.5 mycroft * Enable the master interrupt.
123 1.5 mycroft */
124 1.5 mycroft outb(sc->sc_iobase | 0x1f, 0x80);
125 1.10 mycroft
126 1.5 mycroft printf("\n");
127 1.5 mycroft
128 1.10 mycroft isa.ia_aux = &aa;
129 1.20 cgd for (aa.aa_slave = 0; aa.aa_slave < NSLAVES; aa.aa_slave++) {
130 1.13 mycroft struct cfdata *cf;
131 1.20 cgd isa.ia_iobase = sc->sc_iobase + COM_NPORTS * aa.aa_slave;
132 1.10 mycroft isa.ia_iosize = 0x666;
133 1.10 mycroft isa.ia_irq = IRQUNK;
134 1.10 mycroft isa.ia_drq = DRQUNK;
135 1.10 mycroft isa.ia_msize = 0;
136 1.13 mycroft if ((cf = config_search(astsubmatch, self, &isa)) != 0) {
137 1.18 cgd subunit = cf->cf_unit; /* can change if unit == * */
138 1.13 mycroft config_attach(self, cf, &isa, astprint);
139 1.13 mycroft sc->sc_slaves[aa.aa_slave] =
140 1.18 cgd cf->cf_driver->cd_devs[subunit];
141 1.10 mycroft sc->sc_alive |= 1 << aa.aa_slave;
142 1.10 mycroft }
143 1.10 mycroft }
144 1.7 mycroft
145 1.19 mycroft sc->sc_ih = isa_intr_establish(ia->ia_irq, IST_EDGE, IPL_TTY, astintr,
146 1.19 mycroft sc);
147 1.1 cgd }
148 1.1 cgd
149 1.1 cgd int
150 1.17 cgd astintr(arg)
151 1.17 cgd void *arg;
152 1.1 cgd {
153 1.17 cgd struct ast_softc *sc = arg;
154 1.12 mycroft int iobase = sc->sc_iobase;
155 1.2 mycroft int alive = sc->sc_alive;
156 1.1 cgd int bits;
157 1.1 cgd
158 1.10 mycroft bits = ~inb(iobase | 0x1f) & alive;
159 1.8 mycroft if (bits == 0)
160 1.10 mycroft return (0);
161 1.2 mycroft
162 1.8 mycroft for (;;) {
163 1.2 mycroft #define TRY(n) \
164 1.8 mycroft if (bits & (1 << (n))) \
165 1.5 mycroft comintr(sc->sc_slaves[n]);
166 1.2 mycroft TRY(0);
167 1.2 mycroft TRY(1);
168 1.2 mycroft TRY(2);
169 1.2 mycroft TRY(3);
170 1.5 mycroft #undef TRY
171 1.10 mycroft bits = ~inb(iobase | 0x1f) & alive;
172 1.8 mycroft if (bits == 0)
173 1.10 mycroft return (1);
174 1.8 mycroft }
175 1.1 cgd }
176