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