fdcisa.c revision 1.1.12.2 1 1.1.12.2 nathanw /* $NetBSD: fdcisa.c,v 1.1.12.2 2002/01/11 23:38:12 nathanw Exp $ */
2 1.1.12.2 nathanw
3 1.1.12.2 nathanw /*-
4 1.1.12.2 nathanw * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.1.12.2 nathanw * All rights reserved.
6 1.1.12.2 nathanw *
7 1.1.12.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.1.12.2 nathanw * by Charles M. Hannum.
9 1.1.12.2 nathanw *
10 1.1.12.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.1.12.2 nathanw * modification, are permitted provided that the following conditions
12 1.1.12.2 nathanw * are met:
13 1.1.12.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.1.12.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.1.12.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.12.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.1.12.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.1.12.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.1.12.2 nathanw * must display the following acknowledgement:
20 1.1.12.2 nathanw * This product includes software developed by the NetBSD
21 1.1.12.2 nathanw * Foundation, Inc. and its contributors.
22 1.1.12.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1.12.2 nathanw * contributors may be used to endorse or promote products derived
24 1.1.12.2 nathanw * from this software without specific prior written permission.
25 1.1.12.2 nathanw *
26 1.1.12.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1.12.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.12.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.12.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1.12.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.12.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.12.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.12.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.12.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.12.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.12.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.1.12.2 nathanw */
38 1.1.12.2 nathanw
39 1.1.12.2 nathanw /*-
40 1.1.12.2 nathanw * Copyright (c) 1990 The Regents of the University of California.
41 1.1.12.2 nathanw * All rights reserved.
42 1.1.12.2 nathanw *
43 1.1.12.2 nathanw * This code is derived from software contributed to Berkeley by
44 1.1.12.2 nathanw * Don Ahn.
45 1.1.12.2 nathanw *
46 1.1.12.2 nathanw * Redistribution and use in source and binary forms, with or without
47 1.1.12.2 nathanw * modification, are permitted provided that the following conditions
48 1.1.12.2 nathanw * are met:
49 1.1.12.2 nathanw * 1. Redistributions of source code must retain the above copyright
50 1.1.12.2 nathanw * notice, this list of conditions and the following disclaimer.
51 1.1.12.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
52 1.1.12.2 nathanw * notice, this list of conditions and the following disclaimer in the
53 1.1.12.2 nathanw * documentation and/or other materials provided with the distribution.
54 1.1.12.2 nathanw * 3. All advertising materials mentioning features or use of this software
55 1.1.12.2 nathanw * must display the following acknowledgement:
56 1.1.12.2 nathanw * This product includes software developed by the University of
57 1.1.12.2 nathanw * California, Berkeley and its contributors.
58 1.1.12.2 nathanw * 4. Neither the name of the University nor the names of its contributors
59 1.1.12.2 nathanw * may be used to endorse or promote products derived from this software
60 1.1.12.2 nathanw * without specific prior written permission.
61 1.1.12.2 nathanw *
62 1.1.12.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
63 1.1.12.2 nathanw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
64 1.1.12.2 nathanw * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
65 1.1.12.2 nathanw * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
66 1.1.12.2 nathanw * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
67 1.1.12.2 nathanw * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
68 1.1.12.2 nathanw * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
69 1.1.12.2 nathanw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
70 1.1.12.2 nathanw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
71 1.1.12.2 nathanw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72 1.1.12.2 nathanw * SUCH DAMAGE.
73 1.1.12.2 nathanw *
74 1.1.12.2 nathanw * @(#)fd.c 7.4 (Berkeley) 5/25/91
75 1.1.12.2 nathanw */
76 1.1.12.2 nathanw #include <sys/param.h>
77 1.1.12.2 nathanw #include <sys/systm.h>
78 1.1.12.2 nathanw #include <sys/callout.h>
79 1.1.12.2 nathanw #include <sys/device.h>
80 1.1.12.2 nathanw
81 1.1.12.2 nathanw #include <machine/bus.h>
82 1.1.12.2 nathanw
83 1.1.12.2 nathanw #include <dev/isa/isavar.h>
84 1.1.12.2 nathanw #include <dev/isa/isadmavar.h>
85 1.1.12.2 nathanw #include <dev/isa/fdreg.h>
86 1.1.12.2 nathanw #include <dev/isa/fdcvar.h>
87 1.1.12.2 nathanw
88 1.1.12.2 nathanw #include <atari/atari/device.h>
89 1.1.12.2 nathanw
90 1.1.12.2 nathanw
91 1.1.12.2 nathanw /* controller driver configuration */
92 1.1.12.2 nathanw int fdc_isa_probe __P((struct device *, struct cfdata *, void *));
93 1.1.12.2 nathanw void fdc_isa_attach __P((struct device *, struct device *, void *));
94 1.1.12.2 nathanw
95 1.1.12.2 nathanw struct fdc_isa_softc {
96 1.1.12.2 nathanw struct fdc_softc sc_fdc; /* base fdc device */
97 1.1.12.2 nathanw bus_space_handle_t sc_baseioh; /* base I/O handle */
98 1.1.12.2 nathanw };
99 1.1.12.2 nathanw
100 1.1.12.2 nathanw struct cfattach fdcisa_ca = {
101 1.1.12.2 nathanw sizeof(struct fdc_isa_softc), fdc_isa_probe, fdc_isa_attach
102 1.1.12.2 nathanw };
103 1.1.12.2 nathanw
104 1.1.12.2 nathanw int
105 1.1.12.2 nathanw fdc_isa_probe(parent, cfp, aux)
106 1.1.12.2 nathanw struct device *parent;
107 1.1.12.2 nathanw struct cfdata *cfp;
108 1.1.12.2 nathanw void *aux;
109 1.1.12.2 nathanw {
110 1.1.12.2 nathanw struct isa_attach_args *ia = aux;
111 1.1.12.2 nathanw static int fdc_matched = 0;
112 1.1.12.2 nathanw bus_space_tag_t iot;
113 1.1.12.2 nathanw bus_space_handle_t ioh, ctl_ioh, base_ioh;
114 1.1.12.2 nathanw int iobase;
115 1.1.12.2 nathanw
116 1.1.12.2 nathanw if (!atari_realconfig)
117 1.1.12.2 nathanw return 0;
118 1.1.12.2 nathanw
119 1.1.12.2 nathanw /* Match only once */
120 1.1.12.2 nathanw if (fdc_matched)
121 1.1.12.2 nathanw return 0;
122 1.1.12.2 nathanw
123 1.1.12.2 nathanw iot = ia->ia_iot;
124 1.1.12.2 nathanw
125 1.1.12.2 nathanw if (ia->ia_nio < 1)
126 1.1.12.2 nathanw return (0);
127 1.1.12.2 nathanw if (ia->ia_nirq < 1)
128 1.1.12.2 nathanw return (0);
129 1.1.12.2 nathanw if (ia->ia_ndrq < 1)
130 1.1.12.2 nathanw return (0);
131 1.1.12.2 nathanw
132 1.1.12.2 nathanw if (ISA_DIRECT_CONFIG(ia))
133 1.1.12.2 nathanw return (0);
134 1.1.12.2 nathanw
135 1.1.12.2 nathanw /* Disallow wildcarded I/O addresses. */
136 1.1.12.2 nathanw if (ia->ia_io[0].ir_addr == ISACF_PORT_DEFAULT)
137 1.1.12.2 nathanw return (0);
138 1.1.12.2 nathanw
139 1.1.12.2 nathanw /* Don't allow wildcarded IRQ/DRQ. */
140 1.1.12.2 nathanw if (ia->ia_irq[0].ir_irq == ISACF_IRQ_DEFAULT)
141 1.1.12.2 nathanw return (0);
142 1.1.12.2 nathanw
143 1.1.12.2 nathanw if (ia->ia_drq[0].ir_drq == ISACF_DRQ_DEFAULT)
144 1.1.12.2 nathanw return (0);
145 1.1.12.2 nathanw
146 1.1.12.2 nathanw /* Map the i/o space. */
147 1.1.12.2 nathanw iobase = ia->ia_io[0].ir_addr;
148 1.1.12.2 nathanw if (bus_space_map(iot, iobase, 6 /* FDC_NPORT */, 0, &base_ioh)) {
149 1.1.12.2 nathanw printf("fdcisaprobe: cannot map io-area\n");
150 1.1.12.2 nathanw return 0;
151 1.1.12.2 nathanw }
152 1.1.12.2 nathanw if (bus_space_subregion(iot, base_ioh, 2, 4, &ioh)) {
153 1.1.12.2 nathanw bus_space_unmap(iot, base_ioh, 6);
154 1.1.12.2 nathanw return (0);
155 1.1.12.2 nathanw }
156 1.1.12.2 nathanw
157 1.1.12.2 nathanw if (bus_space_map(iot, iobase + fdctl + 2, 1, 0, &ctl_ioh)) {
158 1.1.12.2 nathanw bus_space_unmap(iot, base_ioh, 6);
159 1.1.12.2 nathanw return (0);
160 1.1.12.2 nathanw }
161 1.1.12.2 nathanw
162 1.1.12.2 nathanw /* Not needed for the rest of the probe. */
163 1.1.12.2 nathanw bus_space_unmap(iot, ctl_ioh, 1);
164 1.1.12.2 nathanw
165 1.1.12.2 nathanw /* reset */
166 1.1.12.2 nathanw bus_space_write_1(iot, ioh, fdout, 0);
167 1.1.12.2 nathanw delay(100);
168 1.1.12.2 nathanw bus_space_write_1(iot, ioh, fdout, FDO_FRST);
169 1.1.12.2 nathanw
170 1.1.12.2 nathanw /* see if it can handle a command */
171 1.1.12.2 nathanw if (out_fdc(iot, ioh, NE7CMD_SPECIFY) < 0)
172 1.1.12.2 nathanw goto out;
173 1.1.12.2 nathanw out_fdc(iot, ioh, 0xdf);
174 1.1.12.2 nathanw out_fdc(iot, ioh, 2);
175 1.1.12.2 nathanw
176 1.1.12.2 nathanw fdc_matched = 1;
177 1.1.12.2 nathanw ia->ia_nio = 1;
178 1.1.12.2 nathanw ia->ia_io[0].ir_size = FDC_NPORT;
179 1.1.12.2 nathanw
180 1.1.12.2 nathanw ia->ia_nirq = 1;
181 1.1.12.2 nathanw ia->ia_ndrq = 1;
182 1.1.12.2 nathanw
183 1.1.12.2 nathanw ia->ia_niomem = 0;
184 1.1.12.2 nathanw
185 1.1.12.2 nathanw out:
186 1.1.12.2 nathanw bus_space_unmap(iot, base_ioh, 6 /* FDC_NPORT */);
187 1.1.12.2 nathanw
188 1.1.12.2 nathanw return fdc_matched;
189 1.1.12.2 nathanw }
190 1.1.12.2 nathanw
191 1.1.12.2 nathanw void
192 1.1.12.2 nathanw fdc_isa_attach(parent, self, aux)
193 1.1.12.2 nathanw struct device *parent, *self;
194 1.1.12.2 nathanw void *aux;
195 1.1.12.2 nathanw {
196 1.1.12.2 nathanw struct fdc_softc *fdc = (void *)self;
197 1.1.12.2 nathanw struct fdc_isa_softc *isc = (void *)self;
198 1.1.12.2 nathanw struct isa_attach_args *ia = aux;
199 1.1.12.2 nathanw printf("\n");
200 1.1.12.2 nathanw
201 1.1.12.2 nathanw fdc->sc_iot = ia->ia_iot;
202 1.1.12.2 nathanw fdc->sc_ic = ia->ia_ic;
203 1.1.12.2 nathanw fdc->sc_drq = ia->ia_drq[0].ir_drq;
204 1.1.12.2 nathanw
205 1.1.12.2 nathanw if (bus_space_map(fdc->sc_iot, ia->ia_io[0].ir_addr,
206 1.1.12.2 nathanw 6 /* FDC_NPORT */, 0, &isc->sc_baseioh)) {
207 1.1.12.2 nathanw printf("%s: unable to map I/O space\n", fdc->sc_dev.dv_xname);
208 1.1.12.2 nathanw return;
209 1.1.12.2 nathanw }
210 1.1.12.2 nathanw
211 1.1.12.2 nathanw if (bus_space_subregion(fdc->sc_iot, isc->sc_baseioh, 2, 4,
212 1.1.12.2 nathanw &fdc->sc_ioh)) {
213 1.1.12.2 nathanw printf("%s: unable to subregion I/O space\n",
214 1.1.12.2 nathanw fdc->sc_dev.dv_xname);
215 1.1.12.2 nathanw return;
216 1.1.12.2 nathanw }
217 1.1.12.2 nathanw
218 1.1.12.2 nathanw if (bus_space_map(fdc->sc_iot, ia->ia_io[0].ir_addr + fdctl + 2, 1, 0,
219 1.1.12.2 nathanw &fdc->sc_fdctlioh)) {
220 1.1.12.2 nathanw printf("%s: unable to map CTL I/O space\n",
221 1.1.12.2 nathanw fdc->sc_dev.dv_xname);
222 1.1.12.2 nathanw return;
223 1.1.12.2 nathanw }
224 1.1.12.2 nathanw
225 1.1.12.2 nathanw fdc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq,
226 1.1.12.2 nathanw IST_EDGE, IPL_BIO, fdcintr, fdc);
227 1.1.12.2 nathanw
228 1.1.12.2 nathanw fdcattach(fdc);
229 1.1.12.2 nathanw }
230