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