1 /* $NetBSD: sb_ofisa.c,v 1.10 2002/10/02 16:34:31 thorpej Exp $ */ 2 3 /*- 4 * Copyright (c) 1998 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 9 * NASA Ames Research Center. 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 * 3. All advertising materials mentioning features or use of this software 20 * must display the following acknowledgement: 21 * This product includes software developed by the NetBSD 22 * Foundation, Inc. and its contributors. 23 * 4. Neither the name of The NetBSD Foundation nor the names of its 24 * contributors may be used to endorse or promote products derived 25 * from this software without specific prior written permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 * POSSIBILITY OF SUCH DAMAGE. 38 */ 39 40 #include <sys/cdefs.h> 41 __KERNEL_RCSID(0, "$NetBSD: sb_ofisa.c,v 1.10 2002/10/02 16:34:31 thorpej Exp $"); 42 43 #include <sys/param.h> 44 #include <sys/systm.h> 45 #include <sys/device.h> 46 47 #include <machine/bus.h> 48 #include <machine/intr.h> 49 50 #include <sys/audioio.h> 51 #include <dev/audio_if.h> 52 #include <dev/midi_if.h> 53 #include <dev/mulaw.h> 54 55 #include <dev/ofw/openfirm.h> 56 #include <dev/isa/isavar.h> 57 #include <dev/ofisa/ofisavar.h> 58 59 #include <dev/isa/sbreg.h> 60 #include <dev/isa/sbvar.h> 61 #include <dev/isa/sbdspvar.h> 62 63 int sb_ofisa_match __P((struct device *, struct cfdata *, void *)); 64 void sb_ofisa_attach __P((struct device *, struct device *, void *)); 65 66 CFATTACH_DECL(sb_ofisa, sizeof(struct sbdsp_softc), 67 sb_ofisa_match, sb_ofisa_attach, NULL, NULL); 68 69 int 70 sb_ofisa_match(parent, cf, aux) 71 struct device *parent; 72 struct cfdata *cf; 73 void *aux; 74 { 75 struct ofisa_attach_args *aa = aux; 76 static const char *const compatible_strings[] = { 77 "pnpPNP,b000", /* generic SB 1.5 */ 78 "pnpPNP,b001", /* generic SB 2.0 */ 79 "pnpPNP,b002", /* generic SB Pro */ 80 "pnpPNP,b003", /* generic SB 16 */ 81 NULL, 82 }; 83 int rv = 0; 84 85 if (of_compatible(aa->oba.oba_phandle, compatible_strings) != -1) { 86 /* 87 * Use a low match priority so that a more specific driver 88 * can match, e.g. a native ESS driver. 89 */ 90 rv = 1; 91 } 92 93 return (rv); 94 } 95 96 void 97 sb_ofisa_attach(parent, self, aux) 98 struct device *parent, *self; 99 void *aux; 100 { 101 struct sbdsp_softc *sc = (void *)self; 102 struct ofisa_attach_args *aa = aux; 103 struct ofisa_reg_desc reg; 104 struct ofisa_intr_desc intr; 105 struct ofisa_dma_desc dma[2]; 106 int n, ndrq; 107 char *model; 108 109 /* 110 * We're living on an OFW. We have to ask the OFW what our 111 * registers and interrupts properties look like. 112 * 113 * We expect: 114 * 115 * 1 i/o register region 116 * 1 interrupt 117 * 1 or 2 dma channels 118 */ 119 120 n = ofisa_reg_get(aa->oba.oba_phandle, ®, 1); 121 if (n != 1) { 122 printf(": error getting register data\n"); 123 return; 124 } 125 if (reg.type != OFISA_REG_TYPE_IO) { 126 printf(": register type not i/o\n"); 127 return; 128 } 129 if (reg.len != SB_NPORT && reg.len != SBP_NPORT) { 130 printf(": weird register size (%lu, expected %d or %d)\n", 131 (unsigned long)reg.len, SB_NPORT, SBP_NPORT); 132 return; 133 } 134 135 n = ofisa_intr_get(aa->oba.oba_phandle, &intr, 1); 136 if (n != 1) { 137 printf(": error getting interrupt data\n"); 138 return; 139 } 140 141 ndrq = ofisa_dma_get(aa->oba.oba_phandle, dma, 2); 142 if (ndrq != 1 && ndrq != 2) { 143 printf(": error getting DMA data\n"); 144 return; 145 } 146 147 sc->sc_ic = aa->ic; 148 149 sc->sc_iot = aa->iot; 150 if (bus_space_map(sc->sc_iot, reg.addr, reg.len, 0, &sc->sc_ioh)) { 151 printf(": unable to map register space\n"); 152 return; 153 } 154 155 /* XXX These are only for setting chip configuration registers. */ 156 sc->sc_iobase = reg.addr; 157 sc->sc_irq = intr.irq; 158 159 sc->sc_drq8 = DRQUNK; 160 sc->sc_drq16 = DRQUNK; 161 162 for (n = 0; n < ndrq; n++) { 163 /* XXX check mode? */ 164 switch (dma[n].width) { 165 case 8: 166 if (sc->sc_drq8 == DRQUNK) 167 sc->sc_drq8 = dma[n].drq; 168 break; 169 case 16: 170 if (sc->sc_drq16 == DRQUNK) 171 sc->sc_drq16 = dma[n].drq; 172 break; 173 default: 174 printf(": weird DMA width %d\n", dma[n].width); 175 return; 176 } 177 } 178 179 if (sc->sc_drq8 == DRQUNK) { 180 printf(": no 8-bit DMA channel\n"); 181 return; 182 } 183 184 if (sbmatch(sc) == 0) { 185 printf(": sbmatch failed\n"); 186 return; 187 } 188 189 sc->sc_ih = isa_intr_establish(aa->ic, intr.irq, IST_EDGE, IPL_AUDIO, 190 sbdsp_intr, sc); 191 192 n = OF_getproplen(aa->oba.oba_phandle, "model"); 193 if (n > 0) { 194 model = alloca(n); 195 if (OF_getprop(aa->oba.oba_phandle, "model", model, n) == n) 196 printf(": %s\n%s", model, sc->sc_dev.dv_xname); 197 } 198 199 sbattach(sc); 200 } 201