Home | History | Annotate | Line # | Download | only in isa
sb.c revision 1.55
      1 /*	$NetBSD: sb.c,v 1.55 1997/10/19 07:42:35 augustss 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 #include <sys/param.h>
     38 #include <sys/systm.h>
     39 #include <sys/errno.h>
     40 #include <sys/ioctl.h>
     41 #include <sys/syslog.h>
     42 #include <sys/device.h>
     43 #include <sys/proc.h>
     44 
     45 #include <machine/cpu.h>
     46 #include <machine/intr.h>
     47 #include <machine/bus.h>
     48 #include <machine/pio.h>
     49 
     50 #include <sys/audioio.h>
     51 #include <dev/audio_if.h>
     52 
     53 #include <dev/isa/isavar.h>
     54 #include <dev/isa/isadmavar.h>
     55 
     56 #include <dev/isa/sbreg.h>
     57 #include <dev/isa/sbvar.h>
     58 #include <dev/isa/sbdspvar.h>
     59 
     60 struct cfdriver sb_cd = {
     61 	NULL, "sb", DV_DULL
     62 };
     63 
     64 struct audio_device sb_device = {
     65 	"SoundBlaster",
     66 	"x",
     67 	"sb"
     68 };
     69 
     70 int	sb_getdev __P((void *, struct audio_device *));
     71 
     72 /*
     73  * Define our interface to the higher level audio driver.
     74  */
     75 
     76 struct audio_hw_if sb_hw_if = {
     77 	sbdsp_open,
     78 	sbdsp_close,
     79 	0,
     80 	sbdsp_query_encoding,
     81 	sbdsp_set_params,
     82 	sbdsp_round_blocksize,
     83 	0,
     84 	sbdsp_dma_init_output,
     85 	sbdsp_dma_init_input,
     86 	sbdsp_dma_output,
     87 	sbdsp_dma_input,
     88 	sbdsp_haltdma,
     89 	sbdsp_haltdma,
     90 	sbdsp_speaker_ctl,
     91 	sb_getdev,
     92 	0,
     93 	sbdsp_mixer_set_port,
     94 	sbdsp_mixer_get_port,
     95 	sbdsp_mixer_query_devinfo,
     96 	sb_malloc,
     97 	sb_free,
     98 	sb_round,
     99         sb_mappage,
    100 	sbdsp_get_props,
    101 };
    102 
    103 /*
    104  * Probe / attach routines.
    105  */
    106 
    107 
    108 int
    109 sbmatch(sc)
    110 	struct sbdsp_softc *sc;
    111 {
    112 	static u_char drq_conf[8] = {
    113 		0x01, 0x02, -1, 0x08, -1, 0x20, 0x40, 0x80
    114 	};
    115 
    116 	static u_char irq_conf[11] = {
    117 		-1, -1, 0x01, -1, -1, 0x02, -1, 0x04, -1, 0x01, 0x08
    118 	};
    119 
    120 	if (sbdsp_probe(sc) == 0)
    121 		return 0;
    122 
    123 	/*
    124 	 * Cannot auto-discover DMA channel.
    125 	 */
    126 	if (ISSBPROCLASS(sc)) {
    127 		if (!SBP_DRQ_VALID(sc->sc_drq8)) {
    128 			printf("%s: configured dma chan %d invalid\n",
    129 			    sc->sc_dev.dv_xname, sc->sc_drq8);
    130 			return 0;
    131 		}
    132 	} else {
    133 		if (!SB_DRQ_VALID(sc->sc_drq8)) {
    134 			printf("%s: configured dma chan %d invalid\n",
    135 			    sc->sc_dev.dv_xname, sc->sc_drq8);
    136 			return 0;
    137 		}
    138 	}
    139 
    140 	/*
    141 	 * XXX THIS IS WRONG!  My ViBRA16S PnP
    142 	 * XXX has 1 drqs, but this resets it to use drq8 everywhere!
    143 	 * XXX --thorpej (at) netbsd.org
    144 	 */
    145 	if (ISSB16CLASS(sc)) {
    146 		if (sc->sc_drq16 == -1)
    147 			sc->sc_drq16 = sc->sc_drq8;
    148 		if (!SB16_DRQ_VALID(sc->sc_drq16)) {
    149 			printf("%s: configured dma chan %d invalid\n",
    150 			    sc->sc_dev.dv_xname, sc->sc_drq16);
    151 			return 0;
    152 		}
    153 	} else
    154 		sc->sc_drq16 = sc->sc_drq8;
    155 
    156 #ifdef NEWCONFIG
    157 	/*
    158 	 * If the IRQ wasn't compiled in, auto-detect it.
    159 	 */
    160 	if (sc->sc_irq == IRQUNK) {
    161 		sc->sc_irq = isa_discoverintr(sbforceintr, sc);
    162 		sbdsp_reset(sc);
    163 		if (ISSBPROCLASS(sc)) {
    164 			if (!SBP_IRQ_VALID(sc->sc_irq)) {
    165 				printf("%s: couldn't auto-detect interrupt\n",
    166 					sc->sc_dev.dv_xname);
    167 				return 0;
    168 			}
    169 		}
    170 		else {
    171 			if (!SB_IRQ_VALID(sc->sc_irq)) {
    172 				printf("%s: couldn't auto-detect interrupt\n");
    173 					sc->sc_dev.dv_xname);
    174 				return 0;
    175 			}
    176 		}
    177 	} else
    178 #endif
    179 	if (ISSBPROCLASS(sc)) {
    180 		if (!SBP_IRQ_VALID(sc->sc_irq)) {
    181 			printf("%s: configured irq %d invalid\n",
    182 			    sc->sc_dev.dv_xname, sc->sc_irq);
    183 			return 0;
    184 		}
    185 	} else {
    186 		if (!SB_IRQ_VALID(sc->sc_irq)) {
    187 			printf("%s: configured irq %d invalid\n",
    188 			    sc->sc_dev.dv_xname, sc->sc_irq);
    189 			return 0;
    190 		}
    191 	}
    192 
    193 	if (ISSB16CLASS(sc)) {
    194 		int w, r;
    195 #if 0
    196 		printf("%s: old drq conf %02x\n", sc->sc_dev.dv_xname,
    197 		    sbdsp_mix_read(sc, SBP_SET_DRQ));
    198 		printf("%s: try drq conf %02x\n", sc->sc_dev.dv_xname,
    199 		    drq_conf[sc->sc_drq16] | drq_conf[sc->sc_drq8]);
    200 #endif
    201 		w = drq_conf[sc->sc_drq16] | drq_conf[sc->sc_drq8];
    202 		sbdsp_mix_write(sc, SBP_SET_DRQ, w);
    203 		r = sbdsp_mix_read(sc, SBP_SET_DRQ) & 0xeb;
    204 		if (r != w) {
    205 			printf("%s: setting drq mask %02x failed, got %02x\n",
    206 			    sc->sc_dev.dv_xname, w, r);
    207 			return 0;
    208 		}
    209 #if 0
    210 		printf("%s: new drq conf %02x\n", sc->sc_dev.dv_xname,
    211 		    sbdsp_mix_read(sc, SBP_SET_DRQ));
    212 #endif
    213 
    214 #if 0
    215 		printf("%s: old irq conf %02x\n", sc->sc_dev.dv_xname,
    216 		    sbdsp_mix_read(sc, SBP_SET_IRQ));
    217 		printf("%s: try irq conf %02x\n", sc->sc_dev.dv_xname,
    218 		    irq_conf[sc->sc_irq]);
    219 #endif
    220 		w = irq_conf[sc->sc_irq];
    221 		sbdsp_mix_write(sc, SBP_SET_IRQ, w);
    222 		r = sbdsp_mix_read(sc, SBP_SET_IRQ) & 0x0f;
    223 		if (r != w) {
    224 			printf("%s: setting irq mask %02x failed, got %02x\n",
    225 			    sc->sc_dev.dv_xname, w, r);
    226 			return 0;
    227 		}
    228 #if 0
    229 		printf("%s: new irq conf %02x\n", sc->sc_dev.dv_xname,
    230 		    sbdsp_mix_read(sc, SBP_SET_IRQ));
    231 #endif
    232 	}
    233 
    234 	return 1;
    235 }
    236 
    237 
    238 void
    239 sbattach(sc)
    240 	struct sbdsp_softc *sc;
    241 {
    242 	sc->sc_ih = isa_intr_establish(sc->sc_ic, sc->sc_irq, IST_EDGE,
    243 	    IPL_AUDIO, sbdsp_intr, sc);
    244 
    245 	sbdsp_attach(sc);
    246 
    247 	audio_attach_mi(&sb_hw_if, 0, sc, &sc->sc_dev);
    248 }
    249 
    250 #ifdef NEWCONFIG
    251 void
    252 sbforceintr(aux)
    253 	void *aux;
    254 {
    255 	static char dmabuf;
    256 	struct sbdsp_softc *sc = aux;
    257 
    258 	/*
    259 	 * Set up a DMA read of one byte.
    260 	 * XXX Note that at this point we haven't called
    261 	 * at_setup_dmachan().  This is okay because it just
    262 	 * allocates a buffer in case it needs to make a copy,
    263 	 * and it won't need to make a copy for a 1 byte buffer.
    264 	 * (I think that calling at_setup_dmachan() should be optional;
    265 	 * if you don't call it, it will be called the first time
    266 	 * it is needed (and you pay the latency).  Also, you might
    267 	 * never need the buffer anyway.)
    268 	 */
    269 	at_dma(DMAMODE_READ, &dmabuf, 1, sc->sc_drq8);
    270 	if (sbdsp_wdsp(sc, SB_DSP_RDMA) == 0) {
    271 		(void)sbdsp_wdsp(sc, 0);
    272 		(void)sbdsp_wdsp(sc, 0);
    273 	}
    274 }
    275 #endif
    276 
    277 
    278 /*
    279  * Various routines to interface to higher level audio driver
    280  */
    281 
    282 int
    283 sb_getdev(addr, retp)
    284 	void *addr;
    285 	struct audio_device *retp;
    286 {
    287 	struct sbdsp_softc *sc = addr;
    288 	static char *names[] = SB_NAMES;
    289 	char *config;
    290 
    291 	if (sc->sc_model == SB_JAZZ)
    292 		strncpy(retp->name, "MV Jazz16", sizeof(retp->name));
    293 	else
    294 		strncpy(retp->name, "SoundBlaster", sizeof(retp->name));
    295 	sprintf(retp->version, "%d.%02d",
    296 		SBVER_MAJOR(sc->sc_version),
    297 		SBVER_MINOR(sc->sc_version));
    298 	if (0 <= sc->sc_model && sc->sc_model < sizeof names / sizeof names[0])
    299 		config = names[sc->sc_model];
    300 	else
    301 		config = "??";
    302 	strncpy(retp->config, config, sizeof(retp->config));
    303 
    304 	return 0;
    305 }
    306