ast.c revision 1.21 1 1.21 cgd /* $NetBSD: ast.c,v 1.21 1996/03/09 01:03:59 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.21 cgd #include <dev/isa/comvar.h>
43 1.20 cgd
44 1.20 cgd #define NSLAVES 4
45 1.1 cgd
46 1.2 mycroft struct ast_softc {
47 1.2 mycroft struct device sc_dev;
48 1.17 cgd void *sc_ih;
49 1.7 mycroft
50 1.11 mycroft int sc_iobase;
51 1.20 cgd int sc_alive; /* mask of slave units attached */
52 1.20 cgd void *sc_slaves[NSLAVES]; /* com device unit numbers */
53 1.5 mycroft };
54 1.5 mycroft
55 1.5 mycroft int astprobe();
56 1.5 mycroft void astattach();
57 1.17 cgd int astintr __P((void *));
58 1.5 mycroft
59 1.5 mycroft struct cfdriver astcd = {
60 1.13 mycroft NULL, "ast", astprobe, astattach, DV_TTY, sizeof(struct ast_softc)
61 1.5 mycroft };
62 1.1 cgd
63 1.1 cgd int
64 1.5 mycroft astprobe(parent, self, aux)
65 1.5 mycroft struct device *parent, *self;
66 1.5 mycroft void *aux;
67 1.1 cgd {
68 1.5 mycroft struct isa_attach_args *ia = aux;
69 1.2 mycroft
70 1.1 cgd /*
71 1.1 cgd * Do the normal com probe for the first UART and assume
72 1.1 cgd * its presence means there is a multiport board there.
73 1.5 mycroft * XXX Needs more robustness.
74 1.1 cgd */
75 1.20 cgd ia->ia_iosize = NSLAVES * COM_NPORTS;
76 1.10 mycroft return (comprobe1(ia->ia_iobase));
77 1.1 cgd }
78 1.1 cgd
79 1.1 cgd int
80 1.10 mycroft astsubmatch(parent, match, aux)
81 1.10 mycroft struct device *parent;
82 1.10 mycroft void *match, *aux;
83 1.1 cgd {
84 1.5 mycroft struct ast_softc *sc = (void *)parent;
85 1.16 mycroft struct cfdata *cf = match;
86 1.10 mycroft struct isa_attach_args *ia = aux;
87 1.21 cgd struct commulti_attach_args *ca = ia->ia_aux;
88 1.2 mycroft
89 1.21 cgd if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != ca->ca_slave)
90 1.10 mycroft return (0);
91 1.10 mycroft return ((*cf->cf_driver->cd_match)(parent, match, ia));
92 1.10 mycroft }
93 1.10 mycroft
94 1.10 mycroft int
95 1.10 mycroft astprint(aux, ast)
96 1.10 mycroft void *aux;
97 1.10 mycroft char *ast;
98 1.10 mycroft {
99 1.10 mycroft struct isa_attach_args *ia = aux;
100 1.21 cgd struct commulti_attach_args *ca = ia->ia_aux;
101 1.10 mycroft
102 1.21 cgd printf(" slave %d", ca->ca_slave);
103 1.1 cgd }
104 1.1 cgd
105 1.1 cgd void
106 1.5 mycroft astattach(parent, self, aux)
107 1.5 mycroft struct device *parent, *self;
108 1.5 mycroft void *aux;
109 1.1 cgd {
110 1.5 mycroft struct ast_softc *sc = (void *)self;
111 1.5 mycroft struct isa_attach_args *ia = aux;
112 1.21 cgd struct commulti_attach_args ca;
113 1.10 mycroft struct isa_attach_args isa;
114 1.18 cgd int subunit;
115 1.10 mycroft
116 1.10 mycroft sc->sc_iobase = ia->ia_iobase;
117 1.1 cgd
118 1.5 mycroft /*
119 1.5 mycroft * Enable the master interrupt.
120 1.5 mycroft */
121 1.5 mycroft outb(sc->sc_iobase | 0x1f, 0x80);
122 1.10 mycroft
123 1.5 mycroft printf("\n");
124 1.5 mycroft
125 1.21 cgd isa.ia_aux = &ca;
126 1.21 cgd for (ca.ca_slave = 0; ca.ca_slave < NSLAVES; ca.ca_slave++) {
127 1.13 mycroft struct cfdata *cf;
128 1.21 cgd isa.ia_iobase = sc->sc_iobase + COM_NPORTS * ca.ca_slave;
129 1.10 mycroft isa.ia_iosize = 0x666;
130 1.10 mycroft isa.ia_irq = IRQUNK;
131 1.10 mycroft isa.ia_drq = DRQUNK;
132 1.10 mycroft isa.ia_msize = 0;
133 1.13 mycroft if ((cf = config_search(astsubmatch, self, &isa)) != 0) {
134 1.18 cgd subunit = cf->cf_unit; /* can change if unit == * */
135 1.13 mycroft config_attach(self, cf, &isa, astprint);
136 1.21 cgd sc->sc_slaves[ca.ca_slave] =
137 1.18 cgd cf->cf_driver->cd_devs[subunit];
138 1.21 cgd sc->sc_alive |= 1 << ca.ca_slave;
139 1.10 mycroft }
140 1.10 mycroft }
141 1.7 mycroft
142 1.19 mycroft sc->sc_ih = isa_intr_establish(ia->ia_irq, IST_EDGE, IPL_TTY, astintr,
143 1.19 mycroft sc);
144 1.1 cgd }
145 1.1 cgd
146 1.1 cgd int
147 1.17 cgd astintr(arg)
148 1.17 cgd void *arg;
149 1.1 cgd {
150 1.17 cgd struct ast_softc *sc = arg;
151 1.12 mycroft int iobase = sc->sc_iobase;
152 1.2 mycroft int alive = sc->sc_alive;
153 1.1 cgd int bits;
154 1.1 cgd
155 1.10 mycroft bits = ~inb(iobase | 0x1f) & alive;
156 1.8 mycroft if (bits == 0)
157 1.10 mycroft return (0);
158 1.2 mycroft
159 1.8 mycroft for (;;) {
160 1.2 mycroft #define TRY(n) \
161 1.8 mycroft if (bits & (1 << (n))) \
162 1.5 mycroft comintr(sc->sc_slaves[n]);
163 1.2 mycroft TRY(0);
164 1.2 mycroft TRY(1);
165 1.2 mycroft TRY(2);
166 1.2 mycroft TRY(3);
167 1.5 mycroft #undef TRY
168 1.10 mycroft bits = ~inb(iobase | 0x1f) & alive;
169 1.8 mycroft if (bits == 0)
170 1.10 mycroft return (1);
171 1.8 mycroft }
172 1.1 cgd }
173