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