1 /* $OpenBSD: gus_isa.c,v 1.5 2008/06/26 05:42:16 ray Exp $ */ 2 /* $NetBSD: gus.c,v 1.51 1998/01/25 23:48:06 mycroft Exp $ */ 3 4 /*- 5 * Copyright (c) 1996 The NetBSD Foundation, Inc. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to The NetBSD Foundation 9 * by Ken Hornstein and John Kohl. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 /* 34 * 35 * TODO: 36 * . figure out why mixer activity while sound is playing causes problems 37 * (phantom interrupts?) 38 * . figure out a better deinterleave strategy that avoids sucking up 39 * CPU, memory and cache bandwidth. (Maybe a special encoding? 40 * Maybe use the double-speed sampling/hardware deinterleave trick 41 * from the GUS SDK?) A 486/33 isn't quite fast enough to keep 42 * up with 44.1kHz 16-bit stereo output without some drop-outs. 43 * . use CS4231 for 16-bit sampling, for a-law and mu-law playback. 44 * . actually test full-duplex sampling(recording) and playback. 45 */ 46 47 /* 48 * Gravis UltraSound driver 49 * 50 * For more detailed information, see the GUS developers' kit 51 * available on the net at: 52 * 53 * ftp://freedom.nmsu.edu/pub/ultrasound/gravis/util/ 54 * gusdkXXX.zip (developers' kit--get rev 2.22 or later) 55 * See ultrawrd.doc inside--it's MS Word (ick), but it's the bible 56 * 57 */ 58 59 /* 60 * The GUS Max has a slightly strange set of connections between the CS4231 61 * and the GF1 and the DMA interconnects. It's set up so that the CS4231 can 62 * be playing while the GF1 is loading patches from the system. 63 * 64 * Here's a recreation of the DMA interconnect diagram: 65 * 66 * GF1 67 * +---------+ digital 68 * | | record ASIC 69 * | |--------------+ 70 * | | | +--------+ 71 * | | play (dram) | +----+ | | 72 * | |--------------(------|-\ | | +-+ | 73 * +---------+ | | >-|----|---|C|--|------ dma chan 1 74 * | +---|-/ | | +-+ | 75 * | | +----+ | | | 76 * | | +----+ | | | 77 * +---------+ +-+ +--(---|-\ | | | | 78 * | | play |8| | | >-|----|----+---|------ dma chan 2 79 * | ---C----|--------|/|------(---|-/ | | | 80 * | ^ |record |1| | +----+ | | 81 * | | | /----|6|------+ +--------+ 82 * | ---+----|--/ +-+ 83 * +---------+ 84 * CS4231 8-to-16 bit bus conversion, if needed 85 * 86 * 87 * "C" is an optional combiner. 88 * 89 */ 90 91 #include <sys/param.h> 92 #include <sys/systm.h> 93 #include <sys/errno.h> 94 #include <sys/ioctl.h> 95 #include <sys/syslog.h> 96 #include <sys/device.h> 97 #include <sys/proc.h> 98 #include <sys/buf.h> 99 #include <sys/fcntl.h> 100 #include <sys/malloc.h> 101 #include <sys/kernel.h> 102 #include <sys/timeout.h> 103 104 #include <machine/cpu.h> 105 #include <machine/intr.h> 106 #include <machine/bus.h> 107 #include <machine/cpufunc.h> 108 #include <sys/audioio.h> 109 #include <dev/audio_if.h> 110 #include <dev/mulaw.h> 111 #include <dev/auconv.h> 112 113 #include <dev/isa/isavar.h> 114 #include <dev/isa/isadmavar.h> 115 116 #include <dev/ic/ics2101reg.h> 117 #include <dev/ic/cs4231reg.h> 118 #include <dev/ic/ad1848reg.h> 119 #include <dev/isa/ics2101var.h> 120 #include <dev/isa/ad1848var.h> 121 #include <dev/isa/cs4231var.h> 122 #include "gusreg.h" 123 #include "gusvar.h" 124 125 /* 126 * ISA bus driver routines 127 */ 128 129 int gus_isa_match(struct device *, void *, void *); 130 void gus_isa_attach(struct device *, struct device *, void *); 131 132 struct cfattach gus_isa_ca = { 133 sizeof(struct gus_softc), gus_isa_match, gus_isa_attach, 134 }; 135 136 int 137 gus_isa_match(parent, match, aux) 138 struct device *parent; 139 void *match; 140 void *aux; 141 { 142 struct isa_attach_args *ia = aux; 143 int iobase = ia->ia_iobase; 144 int recdrq = ia->ia_drq2; 145 146 /* 147 * Before we do anything else, make sure requested IRQ and DRQ are 148 * valid for this card. 149 */ 150 151 /* XXX range check before indexing!! */ 152 if (ia->ia_irq == IRQUNK || gus_irq_map[ia->ia_irq] == IRQUNK) { 153 DPRINTF(("gus: invalid irq %d, card not probed\n", ia->ia_irq)); 154 return 0; 155 } 156 157 if (ia->ia_drq == DRQUNK || gus_drq_map[ia->ia_drq] == DRQUNK) { 158 DPRINTF(("gus: invalid drq %d, card not probed\n", ia->ia_drq)); 159 return 0; 160 } 161 162 if (recdrq != DRQUNK) { 163 if (recdrq > 7 || gus_drq_map[recdrq] == DRQUNK) { 164 DPRINTF(("gus: invalid second DMA channel (%d), card not probed\n", recdrq)); 165 return 0; 166 } 167 } else 168 recdrq = ia->ia_drq; 169 170 if (iobase == IOBASEUNK) { 171 int i; 172 for(i = 0; i < gus_addrs; i++) 173 if (gus_test_iobase(ia->ia_iot, gus_base_addrs[i])) { 174 iobase = gus_base_addrs[i]; 175 goto done; 176 } 177 return 0; 178 } else if (!gus_test_iobase(ia->ia_iot, iobase)) 179 return 0; 180 181 done: 182 if ((ia->ia_drq != -1 && !isa_drq_isfree(parent, ia->ia_drq)) || 183 (recdrq != -1 && !isa_drq_isfree(parent, recdrq))) 184 return 0; 185 186 ia->ia_iobase = iobase; 187 ia->ia_iosize = GUS_NPORT1; 188 return 1; 189 } 190 191 192 /* 193 * Setup the GUS for use; called shortly after probe 194 */ 195 196 void 197 gus_isa_attach(parent, self, aux) 198 struct device *parent, *self; 199 void *aux; 200 { 201 struct gus_softc *sc = (void *) self; 202 struct isa_attach_args *ia = aux; 203 204 sc->sc_iot = ia->ia_iot; 205 sc->sc_iobase = ia->ia_iobase; 206 207 /* Map i/o space */ 208 if (bus_space_map(sc->sc_iot, sc->sc_iobase, GUS_NPORT1, 0, &sc->sc_ioh1)) 209 panic("%s: can't map io port range 1", self->dv_xname); 210 if (bus_space_map(sc->sc_iot, sc->sc_iobase+GUS_IOH2_OFFSET, GUS_NPORT2, 0, 211 &sc->sc_ioh2)) 212 panic("%s: can't map io port range 2", self->dv_xname); 213 214 /* XXX Maybe we shouldn't fail on mapping this, but just assume 215 * the card is of revision 0? */ 216 if (bus_space_map(sc->sc_iot, sc->sc_iobase+GUS_IOH3_OFFSET, GUS_NPORT3, 0, 217 &sc->sc_ioh3)) 218 panic("%s: can't map io port range 3", self->dv_xname); 219 220 if (bus_space_map(sc->sc_iot, sc->sc_iobase+GUS_IOH4_OFFSET, GUS_NPORT4, 0, 221 &sc->sc_ioh4)) 222 panic("%s: can't map io port range 4", self->dv_xname); 223 224 sc->sc_irq = ia->ia_irq; 225 sc->sc_drq = ia->ia_drq; 226 sc->sc_recdrq = ia->ia_drq2; 227 sc->sc_isa = parent; 228 229 gus_subattach(sc, aux); 230 } 231