1 /* $NetBSD: ym_isapnp.c,v 1.24 2009/05/12 10:16:35 cegger Exp $ */ 2 3 /* 4 * Copyright (c) 1991-1993 Regents of the University of California. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by the Computer Systems 18 * Engineering Group at Lawrence Berkeley Laboratory. 19 * 4. Neither the name of the University nor of the Laboratory may be used 20 * to endorse or promote products derived from this software without 21 * specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 */ 36 37 /* 38 * Driver for the Yamaha OPL3-SA3 chipset. This is found on many laptops 39 * and Pentium (II) motherboards. 40 * 41 * Original code from OpenBSD. 42 */ 43 44 #include <sys/cdefs.h> 45 __KERNEL_RCSID(0, "$NetBSD: ym_isapnp.c,v 1.24 2009/05/12 10:16:35 cegger Exp $"); 46 47 #include "mpu_ym.h" 48 49 #include <sys/param.h> 50 #include <sys/systm.h> 51 #include <sys/device.h> 52 #include <sys/errno.h> 53 54 #include <sys/audioio.h> 55 #include <dev/audio_if.h> 56 57 #include <dev/isa/isavar.h> 58 #include <dev/isa/isadmavar.h> 59 60 #include <dev/isapnp/isapnpreg.h> 61 #include <dev/isapnp/isapnpvar.h> 62 #include <dev/isapnp/isapnpdevs.h> 63 64 #include <dev/ic/ad1848reg.h> 65 #include <dev/isa/ad1848var.h> 66 67 #include <dev/ic/cs4231reg.h> 68 #include <dev/isa/cs4231var.h> 69 70 #include <dev/ic/opl3sa3reg.h> 71 #include <dev/isa/wssreg.h> 72 #include <dev/isa/ymvar.h> 73 74 int ym_isapnp_match(device_t, cfdata_t, void *); 75 void ym_isapnp_attach(device_t, device_t, void *); 76 77 CFATTACH_DECL(ym_isapnp, sizeof(struct ym_softc), 78 ym_isapnp_match, ym_isapnp_attach, NULL, NULL); 79 80 /* 81 * Probe / attach routines. 82 */ 83 84 /* 85 * Probe for the Yamaha hardware. 86 */ 87 int 88 ym_isapnp_match(device_t parent, cfdata_t match, void *aux) 89 { 90 int pri, variant; 91 92 pri = isapnp_devmatch(aux, &isapnp_ym_devinfo, &variant); 93 if (pri && variant > 0) 94 pri = 0; 95 return pri; 96 } 97 98 /* 99 * Attach hardware to driver, attach hardware driver to audio 100 * pseudo-device driver. 101 */ 102 void 103 ym_isapnp_attach(device_t parent, device_t self, void *aux) 104 { 105 struct ym_softc *sc; 106 struct ad1848_softc *ac; 107 struct isapnp_attach_args *ipa; 108 109 sc = device_private(self); 110 ac = &sc->sc_ad1848.sc_ad1848; 111 ipa = aux; 112 printf("\n"); 113 114 if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) { 115 aprint_error_dev(self, "error in region allocation\n"); 116 return; 117 } 118 119 sc->sc_iot = ipa->ipa_iot; 120 sc->sc_ic = ipa->ipa_ic; 121 sc->sc_ioh = ipa->ipa_io[1].h; 122 123 sc->ym_irq = ipa->ipa_irq[0].num; 124 sc->ym_playdrq = ipa->ipa_drq[0].num; 125 sc->ym_recdrq = ipa->ipa_drq[1].num; 126 127 sc->sc_sb_ioh = ipa->ipa_io[0].h; 128 sc->sc_opl_ioh = ipa->ipa_io[2].h; 129 #if NMPU_YM > 0 130 sc->sc_mpu_ioh = ipa->ipa_io[3].h; 131 #endif 132 sc->sc_controlioh = ipa->ipa_io[4].h; 133 134 ac->sc_iot = sc->sc_iot; 135 if (bus_space_subregion(sc->sc_iot, sc->sc_ioh, WSS_CODEC, AD1848_NPORT, 136 &ac->sc_ioh)) { 137 aprint_error_dev(self, "bus_space_subregion failed\n"); 138 return; 139 } 140 ac->mode = 2; 141 ac->MCE_bit = MODE_CHANGE_ENABLE; 142 143 sc->sc_ad1848.sc_ic = sc->sc_ic; 144 145 printf("%s: %s %s", device_xname(self), ipa->ipa_devident, 146 ipa->ipa_devclass); 147 148 ym_attach(sc); 149 } 150