| 1 | /* $NetBSD: fdc_isa.c,v 1.20 2015/04/13 16:33:24 riastradh 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 | * |
| 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. |
| 30 | */ |
| 31 | |
| 32 | /*- |
| 33 | * Copyright (c) 1990 The Regents of the University of California. |
| 34 | * All rights reserved. |
| 35 | * |
| 36 | * This code is derived from software contributed to Berkeley by |
| 37 | * Don Ahn. |
| 38 | * |
| 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. |
| 50 | * |
| 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. |
| 62 | * |
| 63 | * @(#)fd.c 7.4 (Berkeley) 5/25/91 |
| 64 | */ |
| 65 | |
| 66 | #include <sys/cdefs.h> |
| 67 | __KERNEL_RCSID(0, "$NetBSD: fdc_isa.c,v 1.20 2015/04/13 16:33:24 riastradh Exp $" ); |
| 68 | |
| 69 | #include <sys/param.h> |
| 70 | #include <sys/systm.h> |
| 71 | #include <sys/callout.h> |
| 72 | #include <sys/device.h> |
| 73 | #include <sys/buf.h> |
| 74 | #include <sys/queue.h> |
| 75 | |
| 76 | #include <sys/bus.h> |
| 77 | #include <sys/intr.h> |
| 78 | |
| 79 | #include <dev/isa/isavar.h> |
| 80 | #include <dev/isa/isadmavar.h> |
| 81 | |
| 82 | #include <dev/isa/fdreg.h> |
| 83 | #include <dev/isa/fdcvar.h> |
| 84 | |
| 85 | static int fdc_isa_probe(device_t, cfdata_t, void *); |
| 86 | static void fdc_isa_attach(device_t, device_t, void *); |
| 87 | static int fdc_isa_detach(device_t, int); |
| 88 | |
| 89 | struct fdc_isa_softc { |
| 90 | struct fdc_softc sc_fdc; /* base fdc device */ |
| 91 | |
| 92 | bus_space_handle_t sc_baseioh; /* base I/O handle */ |
| 93 | }; |
| 94 | |
| 95 | CFATTACH_DECL2_NEW(fdc_isa, sizeof(struct fdc_isa_softc), |
| 96 | fdc_isa_probe, fdc_isa_attach, fdc_isa_detach, NULL, NULL, fdc_childdet); |
| 97 | |
| 98 | #ifdef NEWCONFIG |
| 99 | void fdc_isa_forceintr(void *); |
| 100 | #endif |
| 101 | |
| 102 | static int |
| 103 | fdc_isa_probe(device_t parent, cfdata_t match, void *aux) |
| 104 | { |
| 105 | struct isa_attach_args *ia = aux; |
| 106 | bus_space_tag_t iot; |
| 107 | bus_space_handle_t ioh, ctl_ioh, base_ioh; |
| 108 | int rv, iobase; |
| 109 | |
| 110 | iot = ia->ia_iot; |
| 111 | rv = 0; |
| 112 | |
| 113 | if (ia->ia_nio < 1) |
| 114 | return (0); |
| 115 | if (ia->ia_nirq < 1) |
| 116 | return (0); |
| 117 | if (ia->ia_ndrq < 1) |
| 118 | return (0); |
| 119 | |
| 120 | if (ISA_DIRECT_CONFIG(ia)) |
| 121 | return (0); |
| 122 | |
| 123 | /* Disallow wildcarded I/O addresses. */ |
| 124 | if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT) |
| 125 | return (0); |
| 126 | |
| 127 | /* Don't allow wildcarded IRQ/DRQ. */ |
| 128 | if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ) |
| 129 | return (0); |
| 130 | |
| 131 | if (ia->ia_drq[0].ir_drq == ISA_UNKNOWN_DRQ) |
| 132 | return (0); |
| 133 | |
| 134 | /* Map the I/O space. */ |
| 135 | iobase = ia->ia_io[0].ir_addr; |
| 136 | if (bus_space_map(iot, iobase, 6 /* FDC_NPORT */, 0, &base_ioh)) |
| 137 | return (0); |
| 138 | |
| 139 | if (bus_space_subregion(iot, base_ioh, 2, 4, &ioh)) { |
| 140 | bus_space_unmap(iot, base_ioh, 6); |
| 141 | return (0); |
| 142 | } |
| 143 | |
| 144 | if (bus_space_map(iot, iobase + fdctl + 2, 1, 0, &ctl_ioh)) { |
| 145 | bus_space_unmap(iot, base_ioh, 6); |
| 146 | return (0); |
| 147 | } |
| 148 | |
| 149 | /* Not needed for the rest of the probe. */ |
| 150 | bus_space_unmap(iot, ctl_ioh, 1); |
| 151 | |
| 152 | /* reset */ |
| 153 | bus_space_write_1(iot, ioh, fdout, 0); |
| 154 | delay(100); |
| 155 | bus_space_write_1(iot, ioh, fdout, FDO_FRST); |
| 156 | |
| 157 | /* see if it can handle a command */ |
| 158 | if (out_fdc(iot, ioh, NE7CMD_SPECIFY) < 0) |
| 159 | goto out; |
| 160 | out_fdc(iot, ioh, 0xdf); |
| 161 | out_fdc(iot, ioh, 2); |
| 162 | |
| 163 | rv = 1; |
| 164 | ia->ia_nio = 1; |
| 165 | ia->ia_io[0].ir_size = FDC_NPORT; |
| 166 | |
| 167 | ia->ia_nirq = 1; |
| 168 | ia->ia_ndrq = 1; |
| 169 | |
| 170 | ia->ia_niomem = 0; |
| 171 | |
| 172 | out: |
| 173 | bus_space_unmap(iot, base_ioh, 6 /* FDC_NPORT */); |
| 174 | return (rv); |
| 175 | } |
| 176 | |
| 177 | static int |
| 178 | fdc_isa_detach(device_t self, int flags) |
| 179 | { |
| 180 | int rc; |
| 181 | struct fdc_isa_softc *isc = device_private(self); |
| 182 | struct fdc_softc *fdc = &isc->sc_fdc; |
| 183 | |
| 184 | if ((rc = fdcdetach(self, flags)) != 0) |
| 185 | return rc; |
| 186 | |
| 187 | isa_intr_disestablish(fdc->sc_ic, fdc->sc_ih); |
| 188 | |
| 189 | bus_space_unmap(fdc->sc_iot, fdc->sc_fdctlioh, 1); |
| 190 | |
| 191 | bus_space_unmap(fdc->sc_iot, isc->sc_baseioh, 6 /* FDC_NPORT */); |
| 192 | |
| 193 | return 0; |
| 194 | } |
| 195 | |
| 196 | static void |
| 197 | fdc_isa_attach(device_t parent, device_t self, void *aux) |
| 198 | { |
| 199 | struct fdc_isa_softc *isc = device_private(self); |
| 200 | struct fdc_softc *fdc = &isc->sc_fdc; |
| 201 | struct isa_attach_args *ia = aux; |
| 202 | |
| 203 | aprint_naive("\n" ); |
| 204 | aprint_normal("\n" ); |
| 205 | |
| 206 | fdc->sc_dev = self; |
| 207 | fdc->sc_iot = ia->ia_iot; |
| 208 | fdc->sc_ic = ia->ia_ic; |
| 209 | fdc->sc_drq = ia->ia_drq[0].ir_drq; |
| 210 | |
| 211 | if (bus_space_map(fdc->sc_iot, ia->ia_io[0].ir_addr, |
| 212 | 6 /* FDC_NPORT */, 0, &isc->sc_baseioh)) { |
| 213 | aprint_normal_dev(fdc->sc_dev, "unable to map I/O space\n" ); |
| 214 | return; |
| 215 | } |
| 216 | |
| 217 | if (bus_space_subregion(fdc->sc_iot, isc->sc_baseioh, 2, 4, |
| 218 | &fdc->sc_ioh)) { |
| 219 | aprint_normal_dev(fdc->sc_dev, |
| 220 | "unable to subregion I/O space\n" ); |
| 221 | return; |
| 222 | } |
| 223 | |
| 224 | if (bus_space_map(fdc->sc_iot, ia->ia_io[0].ir_addr + fdctl + 2, 1, 0, |
| 225 | &fdc->sc_fdctlioh)) { |
| 226 | aprint_normal_dev(fdc->sc_dev, |
| 227 | "unable to map CTL I/O space\n" ); |
| 228 | return; |
| 229 | } |
| 230 | |
| 231 | fdc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq, |
| 232 | IST_EDGE, IPL_BIO, fdcintr, fdc); |
| 233 | |
| 234 | fdcattach(fdc); |
| 235 | } |
| 236 | |