sb_ofisa.c revision 1.4
1/* $NetBSD: sb_ofisa.c,v 1.4 1999/02/19 16:10:44 mycroft 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/param.h> 41#include <sys/systm.h> 42#include <sys/device.h> 43 44#include <machine/bus.h> 45#include <machine/intr.h> 46 47#include <sys/audioio.h> 48#include <dev/audio_if.h> 49#include <dev/midi_if.h> 50#include <dev/mulaw.h> 51 52#include <dev/ofw/openfirm.h> 53#include <dev/isa/isavar.h> 54#include <dev/ofisa/ofisavar.h> 55 56#include <dev/isa/sbreg.h> 57#include <dev/isa/sbvar.h> 58#include <dev/isa/sbdspvar.h> 59 60int sb_ofisa_match __P((struct device *, struct cfdata *, void *)); 61void sb_ofisa_attach __P((struct device *, struct device *, void *)); 62 63struct cfattach sb_ofisa_ca = { 64 sizeof(struct sbdsp_softc), sb_ofisa_match, sb_ofisa_attach 65}; 66 67int 68sb_ofisa_match(parent, cf, aux) 69 struct device *parent; 70 struct cfdata *cf; 71 void *aux; 72{ 73 struct ofisa_attach_args *aa = aux; 74 const char *compatible_strings[] = { 75 "pnpPNP,b000", /* generic SB 1.5 */ 76 "pnpPNP,b001", /* generic SB 2.0 */ 77 "pnpPNP,b002", /* generic SB Pro */ 78 "pnpPNP,b003", /* generic SB 16 */ 79 NULL, 80 }; 81 int rv = 0; 82 83 if (of_compatible(aa->oba.oba_phandle, compatible_strings) != -1) { 84 /* 85 * Use a low match priority so that a more specific driver 86 * can match, e.g. a native ESS driver. 87 */ 88 rv = 1; 89 } 90 91 return (rv); 92} 93 94void 95sb_ofisa_attach(parent, self, aux) 96 struct device *parent, *self; 97 void *aux; 98{ 99 struct sbdsp_softc *sc = (void *)self; 100 struct ofisa_attach_args *aa = aux; 101 struct ofisa_reg_desc reg; 102 struct ofisa_intr_desc intr; 103 struct ofisa_dma_desc dma[2]; 104 int n, ndrq; 105 char *model; 106 107 /* 108 * We're living on an OFW. We have to ask the OFW what our 109 * registers and interrupts properties look like. 110 * 111 * We expect: 112 * 113 * 1 i/o register region 114 * 1 interrupt 115 * 1 or 2 dma channels 116 */ 117 118 n = ofisa_reg_get(aa->oba.oba_phandle, ®, 1); 119 if (n != 1) { 120 printf(": error getting register data\n"); 121 return; 122 } 123 if (reg.type != OFISA_REG_TYPE_IO) { 124 printf(": register type not i/o\n"); 125 return; 126 } 127 if (reg.len != SB_NPORT && reg.len != SBP_NPORT) { 128 printf(": weird register size (%lu, expected %d or %d)\n", 129 (unsigned long)reg.len, SB_NPORT, SBP_NPORT); 130 return; 131 } 132 133 n = ofisa_intr_get(aa->oba.oba_phandle, &intr, 1); 134 if (n != 1) { 135 printf(": error getting interrupt data\n"); 136 return; 137 } 138 139 ndrq = ofisa_dma_get(aa->oba.oba_phandle, dma, 2); 140 if (ndrq != 1 && ndrq != 2) { 141 printf(": error getting DMA data\n"); 142 return; 143 } 144 145 sc->sc_ic = aa->ic; 146 147 sc->sc_iot = aa->iot; 148 if (bus_space_map(sc->sc_iot, reg.addr, reg.len, 0, &sc->sc_ioh)) { 149 printf(": unable to map register space\n"); 150 return; 151 } 152 153 /* XXX These are only for setting chip configuration registers. */ 154 sc->sc_iobase = reg.addr; 155 sc->sc_irq = intr.irq; 156 157 sc->sc_drq8 = DRQUNK; 158 sc->sc_drq16 = DRQUNK; 159 160 for (n = 0; n < ndrq; n++) { 161 /* XXX check mode? */ 162 switch (dma[n].width) { 163 case 8: 164 if (sc->sc_drq8 == DRQUNK) 165 sc->sc_drq8 = dma[n].drq; 166 break; 167 case 16: 168 if (sc->sc_drq16 == DRQUNK) 169 sc->sc_drq16 = dma[n].drq; 170 break; 171 default: 172 printf(": weird DMA width %d\n", dma[n].width); 173 return; 174 } 175 } 176 177 if (sc->sc_drq8 == DRQUNK) { 178 printf(": no 8-bit DMA channel\n"); 179 return; 180 } 181 182 if (sbmatch(sc) == 0) { 183 printf(": sbmatch failed\n"); 184 return; 185 } 186 187 sc->sc_ih = isa_intr_establish(aa_ic, intr.irq, IST_EDGE, IPL_AUDIO, 188 sbdsp_intr, sc); 189 190 n = OF_getproplen(aa->oba.oba_phandle, "model"); 191 if (n > 0) { 192 model = alloca(n); 193 if (OF_getprop(aa->oba.oba_phandle, "model", model, n) == n) 194 printf(": %s\n%s", model, sc->sc_dev.dv_xname); 195 } 196 197 sbattach(sc); 198} 199