fdcisa.c revision 1.1 1 /* $NetBSD: fdcisa.c,v 1.1 2001/03/16 21:31:56 leo 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 #include <sys/param.h>
77 #include <sys/systm.h>
78 #include <sys/callout.h>
79 #include <sys/device.h>
80
81 #include <machine/bus.h>
82
83 #include <dev/isa/isavar.h>
84 #include <dev/isa/isadmavar.h>
85 #include <dev/isa/fdreg.h>
86 #include <dev/isa/fdcvar.h>
87
88 #include <atari/atari/device.h>
89
90
91 /* controller driver configuration */
92 int fdc_isa_probe __P((struct device *, struct cfdata *, void *));
93 void fdc_isa_attach __P((struct device *, struct device *, void *));
94
95 struct fdc_isa_softc {
96 struct fdc_softc sc_fdc; /* base fdc device */
97 bus_space_handle_t sc_baseioh; /* base I/O handle */
98 };
99
100 struct cfattach fdcisa_ca = {
101 sizeof(struct fdc_isa_softc), fdc_isa_probe, fdc_isa_attach
102 };
103
104 int
105 fdc_isa_probe(parent, cfp, aux)
106 struct device *parent;
107 struct cfdata *cfp;
108 void *aux;
109 {
110 struct isa_attach_args *ia = aux;
111 static int fdc_matched = 0;
112 bus_space_tag_t iot;
113 bus_space_handle_t ioh, ctl_ioh, base_ioh;
114
115 if (!atari_realconfig)
116 return 0;
117
118 /* Match only once */
119 if (fdc_matched)
120 return 0;
121
122 iot = ia->ia_iot;
123
124 /*
125 * Disallow wildcarded i/o address and drq
126 */
127 if ((ia->ia_iobase == IOBASEUNK) || (ia->ia_drq == DRQUNK))
128 return 0;
129
130 /* Map the i/o space. */
131 if (bus_space_map(iot, ia->ia_iobase, 6 /* FDC_NPORT */, 0,
132 (caddr_t*)&base_ioh)) {
133 printf("fdcisaprobe: cannot map io-area\n");
134 return 0;
135 }
136 if (bus_space_subregion(iot, base_ioh, 2, 4, &ioh)) {
137 bus_space_unmap(iot, base_ioh, 6);
138 return (0);
139 }
140
141 if (bus_space_map(iot, ia->ia_iobase + fdctl + 2, 1, 0, &ctl_ioh)) {
142 bus_space_unmap(iot, base_ioh, 6);
143 return (0);
144 }
145
146 /* Not needed for the rest of the probe. */
147 bus_space_unmap(iot, ctl_ioh, 1);
148
149 /* reset */
150 bus_space_write_1(iot, ioh, fdout, 0);
151 delay(100);
152 bus_space_write_1(iot, ioh, fdout, FDO_FRST);
153
154 /* see if it can handle a command */
155 if (out_fdc(iot, ioh, NE7CMD_SPECIFY) < 0)
156 goto out;
157 out_fdc(iot, ioh, 0xdf);
158 out_fdc(iot, ioh, 2);
159
160 fdc_matched = 1;
161 ia->ia_iosize = FDC_NPORT;
162 ia->ia_msize = 0;
163 out:
164 bus_space_unmap(iot, base_ioh, 6 /* FDC_NPORT */);
165
166 return fdc_matched;
167 }
168
169 void
170 fdc_isa_attach(parent, self, aux)
171 struct device *parent, *self;
172 void *aux;
173 {
174 struct fdc_softc *fdc = (void *)self;
175 struct fdc_isa_softc *isc = (void *)self;
176 struct isa_attach_args *ia = aux;
177 printf("\n");
178
179 fdc->sc_iot = ia->ia_iot;
180 fdc->sc_ic = ia->ia_ic;
181 fdc->sc_drq = ia->ia_drq;
182
183 if (bus_space_map(fdc->sc_iot, ia->ia_iobase, 6 /* FDC_NPORT */, 0,
184 &isc->sc_baseioh)) {
185 printf("%s: unable to map I/O space\n", fdc->sc_dev.dv_xname);
186 return;
187 }
188
189 if (bus_space_subregion(fdc->sc_iot, isc->sc_baseioh, 2, 4,
190 &fdc->sc_ioh)) {
191 printf("%s: unable to subregion I/O space\n",
192 fdc->sc_dev.dv_xname);
193 return;
194 }
195
196 if (bus_space_map(fdc->sc_iot, ia->ia_iobase + fdctl + 2, 1, 0,
197 &fdc->sc_fdctlioh)) {
198 printf("%s: unable to map CTL I/O space\n",
199 fdc->sc_dev.dv_xname);
200 return;
201 }
202
203 fdc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
204 IPL_BIO, fdcintr, fdc);
205
206 fdcattach(fdc);
207 }
208