Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / atari / isa / fdcisa.c
blobf3cf90fd7ce7f59229a1080f2d97d087e68600ed
1 /* $NetBSD: fdcisa.c,v 1.12 2008/03/17 00:00:55 yamt Exp $ */
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum.
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 /*-
33 * Copyright (c) 1990 The Regents of the University of California.
34 * All rights reserved.
36 * This code is derived from software contributed to Berkeley by
37 * Don Ahn.
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
41 * are met:
42 * 1. Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in the
46 * documentation and/or other materials provided with the distribution.
47 * 3. Neither the name of the University nor the names of its contributors
48 * may be used to endorse or promote products derived from this software
49 * without specific prior written permission.
51 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * SUCH DAMAGE.
63 * @(#)fd.c 7.4 (Berkeley) 5/25/91
66 #include <sys/cdefs.h>
67 __KERNEL_RCSID(0, "$NetBSD: fdcisa.c,v 1.12 2008/03/17 00:00:55 yamt Exp $");
69 #include <sys/param.h>
70 #include <sys/systm.h>
71 #include <sys/callout.h>
72 #include <sys/device.h>
74 #include <machine/bus.h>
76 #include <dev/isa/isavar.h>
77 #include <dev/isa/isadmavar.h>
78 #include <dev/isa/fdreg.h>
79 #include <dev/isa/fdcvar.h>
81 #include <atari/atari/device.h>
84 /* controller driver configuration */
85 int fdc_isa_probe (device_t, cfdata_t, void *);
86 void fdc_isa_attach (device_t, device_t, void *);
88 struct fdc_isa_softc {
89 struct fdc_softc sc_fdc; /* base fdc device */
90 bus_space_handle_t sc_baseioh; /* base I/O handle */
93 CFATTACH_DECL_NEW(fdcisa, sizeof(struct fdc_isa_softc),
94 fdc_isa_probe, fdc_isa_attach, NULL, NULL);
96 int
97 fdc_isa_probe(device_t parent, cfdata_t cfp, void *aux)
99 struct isa_attach_args *ia = aux;
100 static int fdc_matched = 0;
101 bus_space_tag_t iot;
102 bus_space_handle_t ioh, ctl_ioh, base_ioh;
103 int iobase;
105 if (!atari_realconfig)
106 return 0;
108 /* Match only once */
109 if (fdc_matched)
110 return 0;
112 iot = ia->ia_iot;
114 if (ia->ia_nio < 1)
115 return (0);
116 if (ia->ia_nirq < 1)
117 return (0);
118 if (ia->ia_ndrq < 1)
119 return (0);
121 if (ISA_DIRECT_CONFIG(ia))
122 return (0);
124 /* Disallow wildcarded I/O addresses. */
125 if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
126 return (0);
128 /* Don't allow wildcarded IRQ/DRQ. */
129 if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ)
130 return (0);
132 if (ia->ia_drq[0].ir_drq == ISA_UNKNOWN_DRQ)
133 return (0);
135 /* Map the i/o space. */
136 iobase = ia->ia_io[0].ir_addr;
137 if (bus_space_map(iot, iobase, 6 /* FDC_NPORT */, 0, &base_ioh)) {
138 printf("fdcisaprobe: cannot map io-area\n");
139 return 0;
141 if (bus_space_subregion(iot, base_ioh, 2, 4, &ioh)) {
142 bus_space_unmap(iot, base_ioh, 6);
143 return (0);
146 if (bus_space_map(iot, iobase + fdctl + 2, 1, 0, &ctl_ioh)) {
147 bus_space_unmap(iot, base_ioh, 6);
148 return (0);
151 /* Not needed for the rest of the probe. */
152 bus_space_unmap(iot, ctl_ioh, 1);
154 /* reset */
155 bus_space_write_1(iot, ioh, fdout, 0);
156 delay(100);
157 bus_space_write_1(iot, ioh, fdout, FDO_FRST);
159 /* see if it can handle a command */
160 if (out_fdc(iot, ioh, NE7CMD_SPECIFY) < 0)
161 goto out;
162 out_fdc(iot, ioh, 0xdf);
163 out_fdc(iot, ioh, 2);
165 fdc_matched = 1;
166 ia->ia_nio = 1;
167 ia->ia_io[0].ir_size = FDC_NPORT;
169 ia->ia_nirq = 1;
170 ia->ia_ndrq = 1;
172 ia->ia_niomem = 0;
174 out:
175 bus_space_unmap(iot, base_ioh, 6 /* FDC_NPORT */);
177 return fdc_matched;
180 void
181 fdc_isa_attach(device_t parent, device_t self, void *aux)
183 struct fdc_isa_softc *isc = device_private(self);
184 struct fdc_softc *fdc = &isc->sc_fdc;
185 struct isa_attach_args *ia = aux;
187 aprint_normal("\n");
189 fdc->sc_dev = self;
190 fdc->sc_iot = ia->ia_iot;
191 fdc->sc_ic = ia->ia_ic;
192 fdc->sc_drq = ia->ia_drq[0].ir_drq;
194 if (bus_space_map(fdc->sc_iot, ia->ia_io[0].ir_addr,
195 6 /* FDC_NPORT */, 0, &isc->sc_baseioh)) {
196 aprint_error_dev(self, "unable to map I/O space\n");
197 return;
200 if (bus_space_subregion(fdc->sc_iot, isc->sc_baseioh, 2, 4,
201 &fdc->sc_ioh)) {
202 aprint_error_dev(self, "unable to subregion I/O space\n");
203 return;
206 if (bus_space_map(fdc->sc_iot, ia->ia_io[0].ir_addr + fdctl + 2, 1, 0,
207 &fdc->sc_fdctlioh)) {
208 aprint_error_dev(self, "unable to map CTL I/O space\n");
209 return;
212 fdc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq,
213 IST_EDGE, IPL_BIO, fdcintr, fdc);
215 fdcattach(fdc);