1 /* $NetBSD: fdc_jazzio.c,v 1.4 2002/10/02 04:59:48 thorpej Exp $ */ 2 /* $OpenBSD: fd.c,v 1.6 1998/10/03 21:18:57 millert Exp $ */ 3 /* NetBSD: fd.c,v 1.78 1995/07/04 07:23:09 mycroft Exp */ 4 5 /*- 6 * Copyright (c) 1998 The NetBSD Foundation, Inc. 7 * All rights reserved. 8 * 9 * This code is derived from software contributed to The NetBSD Foundation 10 * by Charles M. Hannum. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 3. All advertising materials mentioning features or use of this software 21 * must display the following acknowledgement: 22 * This product includes software developed by the NetBSD 23 * Foundation, Inc. and its contributors. 24 * 4. Neither the name of The NetBSD Foundation nor the names of its 25 * contributors may be used to endorse or promote products derived 26 * from this software without specific prior written permission. 27 * 28 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 29 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 31 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 32 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 * POSSIBILITY OF SUCH DAMAGE. 39 */ 40 41 /*- 42 * Copyright (c) 1990 The Regents of the University of California. 43 * All rights reserved. 44 * 45 * This code is derived from software contributed to Berkeley by 46 * Don Ahn. 47 * 48 * Redistribution and use in source and binary forms, with or without 49 * modification, are permitted provided that the following conditions 50 * are met: 51 * 1. Redistributions of source code must retain the above copyright 52 * notice, this list of conditions and the following disclaimer. 53 * 2. Redistributions in binary form must reproduce the above copyright 54 * notice, this list of conditions and the following disclaimer in the 55 * documentation and/or other materials provided with the distribution. 56 * 3. All advertising materials mentioning features or use of this software 57 * must display the following acknowledgement: 58 * This product includes software developed by the University of 59 * California, Berkeley and its contributors. 60 * 4. Neither the name of the University nor the names of its contributors 61 * may be used to endorse or promote products derived from this software 62 * without specific prior written permission. 63 * 64 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 65 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 66 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 67 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 68 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 69 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 70 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 71 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 72 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 73 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 74 * SUCH DAMAGE. 75 * 76 * @(#)fd.c 7.4 (Berkeley) 5/25/91 77 */ 78 79 #include <sys/param.h> 80 #include <sys/systm.h> 81 #include <sys/callout.h> 82 #include <sys/device.h> 83 #include <sys/buf.h> 84 #include <sys/queue.h> 85 86 #include <mips/cache.h> 87 88 #include <machine/autoconf.h> 89 #include <machine/bus.h> 90 #include <machine/cpu.h> 91 92 #include <arc/jazz/jazzdmatlbreg.h> 93 #include <arc/jazz/fdreg.h> 94 #include <arc/jazz/fdcvar.h> 95 #include <arc/jazz/jazziovar.h> 96 #include <arc/jazz/dma.h> 97 98 #include "locators.h" 99 100 /* controller driver configuration */ 101 int fdc_jazzio_probe(struct device *, struct cfdata *, void *); 102 void fdc_jazzio_attach(struct device *, struct device *, void *); 103 104 /* MD DMA hook functions */ 105 void fdc_jazzio_dma_start(struct fdc_softc *, caddr_t, size_t, int); 106 void fdc_jazzio_dma_abort(struct fdc_softc *); 107 void fdc_jazzio_dma_done(struct fdc_softc *); 108 109 /* software state, per controller */ 110 struct fdc_jazzio_softc { 111 struct fdc_softc sc_fdc; /* base fdc device */ 112 113 bus_space_handle_t sc_baseioh; /* base I/O handle */ 114 struct dma_softc __dma; 115 struct dma_softc *dma; 116 }; 117 118 CFATTACH_DECL(fdc_jazzio, sizeof(struct fdc_jazzio_softc), 119 fdc_jazzio_probe, fdc_jazzio_attach, NULL, NULL); 120 121 #define FDC_NPORT 6 122 #define FDC_OFFSET 2 /* Should we use bus_space_subregion() or not? */ 123 124 int 125 fdc_jazzio_probe(parent, match, aux) 126 struct device *parent; 127 struct cfdata *match; 128 void *aux; 129 { 130 struct jazzio_attach_args *ja = aux; 131 bus_space_tag_t iot; 132 bus_space_handle_t base_ioh, ioh; 133 int rv; 134 135 if (strcmp(ja->ja_name, "fdc") != 0) 136 return 0; 137 138 iot = ja->ja_bust; 139 rv = 0; 140 141 /* Map the I/O space. */ 142 if (bus_space_map(iot, ja->ja_addr, 143 FDC_OFFSET + FDC_NPORT, 0, &base_ioh)) 144 return 0; 145 146 if (bus_space_subregion(iot, base_ioh, FDC_OFFSET, FDC_NPORT, &ioh)) 147 goto out; 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); /* XXX */ 158 out_fdc(iot, ioh, 2); /* XXX */ 159 160 rv = 1; 161 162 out: 163 bus_space_unmap(iot, base_ioh, FDC_OFFSET + FDC_NPORT); 164 return rv; 165 } 166 167 void 168 fdc_jazzio_attach(parent, self, aux) 169 struct device *parent, *self; 170 void *aux; 171 { 172 struct fdc_jazzio_softc *jsc = (struct fdc_jazzio_softc *)self; 173 struct fdc_softc *fdc = &jsc->sc_fdc; 174 struct jazzio_attach_args *ja = aux; 175 176 fdc->sc_iot = ja->ja_bust; 177 178 fdc->sc_maxiosize = 4096; /* XXX */ 179 fdc->sc_dma_start = fdc_jazzio_dma_start; 180 fdc->sc_dma_abort = fdc_jazzio_dma_abort; 181 fdc->sc_dma_done = fdc_jazzio_dma_done; 182 183 jsc->dma = &jsc->__dma; 184 fdc_dma_init(jsc->dma); 185 186 if (bus_space_map(fdc->sc_iot, ja->ja_addr, 187 FDC_OFFSET + FDC_NPORT, 0, &jsc->sc_baseioh)) { 188 printf(": unable to map I/O space\n"); 189 return; 190 } 191 192 if (bus_space_subregion(fdc->sc_iot, jsc->sc_baseioh, 193 FDC_OFFSET, FDC_NPORT, &fdc->sc_ioh)) { 194 printf(": unable to subregion I/O space\n"); 195 bus_space_unmap(fdc->sc_iot, jsc->sc_baseioh, 196 FDC_OFFSET + FDC_NPORT); 197 return; 198 } 199 200 printf("\n"); 201 202 jazzio_intr_establish(ja->ja_intr, fdcintr, fdc); 203 204 fdcattach(fdc); 205 } 206 207 void 208 fdc_jazzio_dma_start(fdc, addr, size, datain) 209 struct fdc_softc *fdc; 210 caddr_t addr; 211 size_t size; 212 int datain; 213 { 214 struct fdc_jazzio_softc *jsc = (void *)fdc; 215 216 mips_dcache_wbinv_range((vaddr_t)addr, (vsize_t)size); 217 DMA_START(jsc->dma, addr, size, datain ? DMA_FROM_DEV : DMA_TO_DEV); 218 } 219 220 void 221 fdc_jazzio_dma_abort(fdc) 222 struct fdc_softc *fdc; 223 { 224 struct fdc_jazzio_softc *jsc = (void *)fdc; 225 226 DMA_RESET(jsc->dma); 227 } 228 229 void 230 fdc_jazzio_dma_done(fdc) 231 struct fdc_softc *fdc; 232 { 233 struct fdc_jazzio_softc *jsc = (void *)fdc; 234 235 DMA_END(jsc->dma); 236 } 237