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