gus_isa.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /* $OpenBSD: gus_isa.c,v 1.7 2015/05/12 16:35:23 ratchov Exp $ */
  2. /* $NetBSD: gus.c,v 1.51 1998/01/25 23:48:06 mycroft Exp $ */
  3. /*-
  4. * Copyright (c) 1996 The NetBSD Foundation, Inc.
  5. * All rights reserved.
  6. *
  7. * This code is derived from software contributed to The NetBSD Foundation
  8. * by Ken Hornstein and John Kohl.
  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. * TODO:
  34. * . figure out why mixer activity while sound is playing causes problems
  35. * (phantom interrupts?)
  36. * . figure out a better deinterleave strategy that avoids sucking up
  37. * CPU, memory and cache bandwidth. (Maybe a special encoding?
  38. * Maybe use the double-speed sampling/hardware deinterleave trick
  39. * from the GUS SDK?) A 486/33 isn't quite fast enough to keep
  40. * up with 44.1kHz 16-bit stereo output without some drop-outs.
  41. * . use CS4231 for 16-bit sampling, for a-law and mu-law playback.
  42. * . actually test full-duplex sampling(recording) and playback.
  43. */
  44. /*
  45. * Gravis UltraSound driver
  46. *
  47. * For more detailed information, see the GUS developers' kit
  48. * available on the net at:
  49. *
  50. * ftp://freedom.nmsu.edu/pub/ultrasound/gravis/util/
  51. * gusdkXXX.zip (developers' kit--get rev 2.22 or later)
  52. * See ultrawrd.doc inside--it's MS Word (ick), but it's the bible
  53. *
  54. */
  55. /*
  56. * The GUS Max has a slightly strange set of connections between the CS4231
  57. * and the GF1 and the DMA interconnects. It's set up so that the CS4231 can
  58. * be playing while the GF1 is loading patches from the system.
  59. *
  60. * Here's a recreation of the DMA interconnect diagram:
  61. *
  62. * GF1
  63. * +---------+ digital
  64. * | | record ASIC
  65. * | |--------------+
  66. * | | | +--------+
  67. * | | play (dram) | +----+ | |
  68. * | |--------------(------|-\ | | +-+ |
  69. * +---------+ | | >-|----|---|C|--|------ dma chan 1
  70. * | +---|-/ | | +-+ |
  71. * | | +----+ | | |
  72. * | | +----+ | | |
  73. * +---------+ +-+ +--(---|-\ | | | |
  74. * | | play |8| | | >-|----|----+---|------ dma chan 2
  75. * | ---C----|--------|/|------(---|-/ | | |
  76. * | ^ |record |1| | +----+ | |
  77. * | | | /----|6|------+ +--------+
  78. * | ---+----|--/ +-+
  79. * +---------+
  80. * CS4231 8-to-16 bit bus conversion, if needed
  81. *
  82. *
  83. * "C" is an optional combiner.
  84. *
  85. */
  86. #include <sys/param.h>
  87. #include <sys/systm.h>
  88. #include <sys/errno.h>
  89. #include <sys/ioctl.h>
  90. #include <sys/syslog.h>
  91. #include <sys/device.h>
  92. #include <sys/buf.h>
  93. #include <sys/fcntl.h>
  94. #include <sys/malloc.h>
  95. #include <sys/kernel.h>
  96. #include <sys/timeout.h>
  97. #include <machine/cpu.h>
  98. #include <machine/intr.h>
  99. #include <machine/bus.h>
  100. #include <machine/cpufunc.h>
  101. #include <sys/audioio.h>
  102. #include <dev/audio_if.h>
  103. #include <dev/isa/isavar.h>
  104. #include <dev/isa/isadmavar.h>
  105. #include <dev/ic/ics2101reg.h>
  106. #include <dev/ic/cs4231reg.h>
  107. #include <dev/ic/ad1848reg.h>
  108. #include <dev/isa/ics2101var.h>
  109. #include <dev/isa/ad1848var.h>
  110. #include <dev/isa/cs4231var.h>
  111. #include "gusreg.h"
  112. #include "gusvar.h"
  113. /*
  114. * ISA bus driver routines
  115. */
  116. int gus_isa_match(struct device *, void *, void *);
  117. void gus_isa_attach(struct device *, struct device *, void *);
  118. struct cfattach gus_isa_ca = {
  119. sizeof(struct gus_softc), gus_isa_match, gus_isa_attach,
  120. };
  121. int
  122. gus_isa_match(parent, match, aux)
  123. struct device *parent;
  124. void *match;
  125. void *aux;
  126. {
  127. struct isa_attach_args *ia = aux;
  128. int iobase = ia->ia_iobase;
  129. int recdrq = ia->ia_drq2;
  130. /*
  131. * Before we do anything else, make sure requested IRQ and DRQ are
  132. * valid for this card.
  133. */
  134. /* XXX range check before indexing!! */
  135. if (ia->ia_irq == IRQUNK || gus_irq_map[ia->ia_irq] == IRQUNK) {
  136. DPRINTF(("gus: invalid irq %d, card not probed\n", ia->ia_irq));
  137. return 0;
  138. }
  139. if (ia->ia_drq == DRQUNK || gus_drq_map[ia->ia_drq] == DRQUNK) {
  140. DPRINTF(("gus: invalid drq %d, card not probed\n", ia->ia_drq));
  141. return 0;
  142. }
  143. if (recdrq != DRQUNK) {
  144. if (recdrq > 7 || gus_drq_map[recdrq] == DRQUNK) {
  145. DPRINTF(("gus: invalid second DMA channel (%d), card not probed\n", recdrq));
  146. return 0;
  147. }
  148. } else
  149. recdrq = ia->ia_drq;
  150. if (iobase == IOBASEUNK) {
  151. int i;
  152. for(i = 0; i < gus_addrs; i++)
  153. if (gus_test_iobase(ia->ia_iot, gus_base_addrs[i])) {
  154. iobase = gus_base_addrs[i];
  155. goto done;
  156. }
  157. return 0;
  158. } else if (!gus_test_iobase(ia->ia_iot, iobase))
  159. return 0;
  160. done:
  161. if ((ia->ia_drq != -1 && !isa_drq_isfree(parent, ia->ia_drq)) ||
  162. (recdrq != -1 && !isa_drq_isfree(parent, recdrq)))
  163. return 0;
  164. ia->ia_iobase = iobase;
  165. ia->ia_iosize = GUS_NPORT1;
  166. return 1;
  167. }
  168. /*
  169. * Setup the GUS for use; called shortly after probe
  170. */
  171. void
  172. gus_isa_attach(parent, self, aux)
  173. struct device *parent, *self;
  174. void *aux;
  175. {
  176. struct gus_softc *sc = (void *) self;
  177. struct isa_attach_args *ia = aux;
  178. sc->sc_iot = ia->ia_iot;
  179. sc->sc_iobase = ia->ia_iobase;
  180. /* Map i/o space */
  181. if (bus_space_map(sc->sc_iot, sc->sc_iobase, GUS_NPORT1, 0, &sc->sc_ioh1))
  182. panic("%s: can't map io port range 1", self->dv_xname);
  183. if (bus_space_map(sc->sc_iot, sc->sc_iobase+GUS_IOH2_OFFSET, GUS_NPORT2, 0,
  184. &sc->sc_ioh2))
  185. panic("%s: can't map io port range 2", self->dv_xname);
  186. /* XXX Maybe we shouldn't fail on mapping this, but just assume
  187. * the card is of revision 0? */
  188. if (bus_space_map(sc->sc_iot, sc->sc_iobase+GUS_IOH3_OFFSET, GUS_NPORT3, 0,
  189. &sc->sc_ioh3))
  190. panic("%s: can't map io port range 3", self->dv_xname);
  191. if (bus_space_map(sc->sc_iot, sc->sc_iobase+GUS_IOH4_OFFSET, GUS_NPORT4, 0,
  192. &sc->sc_ioh4))
  193. panic("%s: can't map io port range 4", self->dv_xname);
  194. sc->sc_irq = ia->ia_irq;
  195. sc->sc_drq = ia->ia_drq;
  196. sc->sc_recdrq = ia->ia_drq2;
  197. sc->sc_isa = parent;
  198. gus_subattach(sc, aux);
  199. }