Home | History | Annotate | Line # | Download | only in isa
sb.c revision 1.88.40.1
      1  1.88.40.1  jmcneill /*	$NetBSD: sb.c,v 1.88.40.1 2011/11/19 21:49:39 jmcneill Exp $	*/
      2       1.10       cgd 
      3        1.1       cgd /*
      4        1.1       cgd  * Copyright (c) 1991-1993 Regents of the University of California.
      5        1.1       cgd  * All rights reserved.
      6        1.1       cgd  *
      7        1.1       cgd  * Redistribution and use in source and binary forms, with or without
      8        1.1       cgd  * modification, are permitted provided that the following conditions
      9        1.1       cgd  * are met:
     10        1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     11        1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     12        1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     13        1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     14        1.1       cgd  *    documentation and/or other materials provided with the distribution.
     15        1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     16        1.1       cgd  *    must display the following acknowledgement:
     17        1.1       cgd  *	This product includes software developed by the Computer Systems
     18        1.1       cgd  *	Engineering Group at Lawrence Berkeley Laboratory.
     19        1.1       cgd  * 4. Neither the name of the University nor of the Laboratory may be used
     20        1.1       cgd  *    to endorse or promote products derived from this software without
     21        1.1       cgd  *    specific prior written permission.
     22        1.1       cgd  *
     23        1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24        1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25        1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26        1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27        1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28        1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29        1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30        1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31        1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32        1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33        1.1       cgd  * SUCH DAMAGE.
     34       1.17    brezak  *
     35        1.1       cgd  */
     36       1.72     lukem 
     37       1.72     lukem #include <sys/cdefs.h>
     38  1.88.40.1  jmcneill __KERNEL_RCSID(0, "$NetBSD: sb.c,v 1.88.40.1 2011/11/19 21:49:39 jmcneill Exp $");
     39        1.1       cgd 
     40       1.60  augustss #include "midi.h"
     41       1.60  augustss 
     42        1.1       cgd #include <sys/param.h>
     43        1.1       cgd #include <sys/systm.h>
     44        1.1       cgd #include <sys/errno.h>
     45        1.1       cgd #include <sys/ioctl.h>
     46        1.1       cgd #include <sys/syslog.h>
     47        1.6   mycroft #include <sys/device.h>
     48       1.17    brezak #include <sys/proc.h>
     49        1.1       cgd 
     50       1.87        ad #include <sys/cpu.h>
     51       1.87        ad #include <sys/intr.h>
     52       1.87        ad #include <sys/bus.h>
     53        1.1       cgd 
     54       1.17    brezak #include <sys/audioio.h>
     55       1.17    brezak #include <dev/audio_if.h>
     56       1.63  augustss #include <dev/midi_if.h>
     57       1.63  augustss 
     58       1.23       cgd #include <dev/isa/isavar.h>
     59       1.23       cgd #include <dev/isa/isadmavar.h>
     60        1.1       cgd 
     61       1.39  christos #include <dev/isa/sbreg.h>
     62       1.39  christos #include <dev/isa/sbvar.h>
     63       1.24       cgd #include <dev/isa/sbdspvar.h>
     64       1.33   thorpej 
     65       1.69   mycroft #if NMPU > 0
     66       1.78      yamt const struct midi_hw_if sb_midi_hw_if = {
     67       1.60  augustss 	sbdsp_midi_open,
     68       1.60  augustss 	sbdsp_midi_close,
     69       1.60  augustss 	sbdsp_midi_output,
     70       1.60  augustss 	sbdsp_midi_getinfo,
     71       1.60  augustss 	0,			/* ioctl */
     72  1.88.40.1  jmcneill 	sbdsp_get_locks,
     73       1.60  augustss };
     74       1.60  augustss #endif
     75        1.1       cgd 
     76       1.80      kent int	sb_getdev(void *, struct audio_device *);
     77        1.1       cgd 
     78       1.17    brezak /*
     79       1.17    brezak  * Define our interface to the higher level audio driver.
     80       1.17    brezak  */
     81       1.17    brezak 
     82       1.78      yamt const struct audio_hw_if sb_hw_if = {
     83       1.53  augustss 	sbdsp_open,
     84       1.17    brezak 	sbdsp_close,
     85       1.51  augustss 	0,
     86       1.17    brezak 	sbdsp_query_encoding,
     87       1.46  augustss 	sbdsp_set_params,
     88       1.17    brezak 	sbdsp_round_blocksize,
     89       1.51  augustss 	0,
     90       1.61   mycroft 	0,
     91       1.61   mycroft 	0,
     92       1.61   mycroft 	0,
     93       1.61   mycroft 	0,
     94       1.65   mycroft 	sbdsp_halt_output,
     95       1.65   mycroft 	sbdsp_halt_input,
     96       1.17    brezak 	sbdsp_speaker_ctl,
     97       1.17    brezak 	sb_getdev,
     98       1.51  augustss 	0,
     99       1.17    brezak 	sbdsp_mixer_set_port,
    100       1.17    brezak 	sbdsp_mixer_get_port,
    101       1.17    brezak 	sbdsp_mixer_query_devinfo,
    102       1.50  augustss 	sb_malloc,
    103       1.50  augustss 	sb_free,
    104       1.64   mycroft 	sb_round_buffersize,
    105       1.79      kent 	sb_mappage,
    106       1.53  augustss 	sbdsp_get_props,
    107       1.61   mycroft 	sbdsp_trigger_output,
    108       1.61   mycroft 	sbdsp_trigger_input,
    109       1.85  christos 	NULL,
    110       1.85  christos 	NULL,
    111  1.88.40.1  jmcneill 	sbdsp_get_locks,
    112        1.6   mycroft };
    113        1.1       cgd 
    114       1.17    brezak /*
    115       1.17    brezak  * Probe / attach routines.
    116       1.17    brezak  */
    117       1.17    brezak 
    118       1.39  christos 
    119        1.1       cgd int
    120       1.88      cube sbmatch(struct sbdsp_softc *sc, int probing, cfdata_t match)
    121        1.1       cgd {
    122       1.75  jdolecek 	static const u_char drq_conf[8] = {
    123       1.43   mycroft 		0x01, 0x02, -1, 0x08, -1, 0x20, 0x40, 0x80
    124       1.28   mycroft 	};
    125       1.39  christos 
    126       1.75  jdolecek 	static const u_char irq_conf[11] = {
    127       1.28   mycroft 		-1, -1, 0x01, -1, -1, 0x02, -1, 0x04, -1, 0x01, 0x08
    128       1.19    brezak 	};
    129        1.1       cgd 
    130       1.88      cube 	if (sbdsp_probe(sc, match) == 0)
    131        1.6   mycroft 		return 0;
    132       1.43   mycroft 
    133        1.1       cgd 	/*
    134        1.1       cgd 	 * Cannot auto-discover DMA channel.
    135        1.1       cgd 	 */
    136       1.26    brezak 	if (ISSBPROCLASS(sc)) {
    137       1.43   mycroft 		if (!SBP_DRQ_VALID(sc->sc_drq8)) {
    138       1.88      cube 			aprint_error("%s: configured DMA chan %d invalid\n",
    139       1.88      cube 			    probing ? "sbmatch" : device_xname(sc->sc_dev),
    140       1.88      cube 			    sc->sc_drq8);
    141       1.43   mycroft 			return 0;
    142       1.43   mycroft 		}
    143       1.43   mycroft 	} else {
    144       1.43   mycroft 		if (!SB_DRQ_VALID(sc->sc_drq8)) {
    145       1.88      cube 			aprint_error("%s: configured DMA chan %d invalid\n",
    146       1.88      cube 			    probing ? "sbmatch" : device_xname(sc->sc_dev),
    147       1.88      cube 			    sc->sc_drq8);
    148       1.17    brezak 			return 0;
    149       1.17    brezak 		}
    150       1.17    brezak 	}
    151       1.49   thorpej 
    152       1.80      kent 	if (0 <= sc->sc_drq16 && sc->sc_drq16 <= 3)
    153       1.80      kent 		/*
    154       1.80      kent                  * XXX Some ViBRA16 cards seem to have two 8 bit DMA
    155       1.56  augustss                  * channels.  I've no clue how to use them, so ignore
    156       1.76    keihan                  * one of them for now.  -- augustss (at) NetBSD.org
    157       1.56  augustss                  */
    158       1.80      kent 		sc->sc_drq16 = -1;
    159       1.56  augustss 
    160       1.43   mycroft 	if (ISSB16CLASS(sc)) {
    161       1.43   mycroft 		if (sc->sc_drq16 == -1)
    162       1.43   mycroft 			sc->sc_drq16 = sc->sc_drq8;
    163       1.43   mycroft 		if (!SB16_DRQ_VALID(sc->sc_drq16)) {
    164       1.88      cube 			aprint_error("%s: configured DMA chan %d invalid\n",
    165       1.88      cube 			    probing ? "sbmatch" : device_xname(sc->sc_dev),
    166       1.88      cube 			    sc->sc_drq16);
    167       1.17    brezak 			return 0;
    168       1.17    brezak 		}
    169       1.43   mycroft 	} else
    170       1.43   mycroft 		sc->sc_drq16 = sc->sc_drq8;
    171       1.80      kent 
    172       1.26    brezak 	if (ISSBPROCLASS(sc)) {
    173       1.39  christos 		if (!SBP_IRQ_VALID(sc->sc_irq)) {
    174       1.88      cube 			aprint_error("%s: configured irq %d invalid\n",
    175       1.88      cube 			    probing ? "sbmatch" : device_xname(sc->sc_dev),
    176       1.88      cube 			    sc->sc_irq);
    177       1.17    brezak 			return 0;
    178       1.19    brezak 		}
    179       1.43   mycroft 	} else {
    180       1.39  christos 		if (!SB_IRQ_VALID(sc->sc_irq)) {
    181       1.88      cube 			aprint_error("%s: configured irq %d invalid\n",
    182       1.88      cube 			    probing ? "sbmatch" : device_xname(sc->sc_dev),
    183       1.88      cube 			    sc->sc_irq);
    184        1.6   mycroft 			return 0;
    185        1.1       cgd 		}
    186        1.1       cgd 	}
    187       1.43   mycroft 
    188       1.70       mjl 	if (ISSB16CLASS(sc) && !(sc->sc_quirks & SB_QUIRK_NO_INIT_DRQ)) {
    189       1.47  augustss 		int w, r;
    190       1.84  christos 		if (sc->sc_irq >= __arraycount(irq_conf)) {
    191       1.88      cube 			aprint_error("%s: Cannot handle irq %d\n",
    192       1.88      cube 			    probing ? "sbmatch" : device_xname(sc->sc_dev),
    193       1.88      cube 			    sc->sc_irq);
    194       1.84  christos 			return 0;
    195       1.84  christos 		}
    196       1.84  christos 		if (sc->sc_drq16 >= __arraycount(drq_conf)) {
    197       1.88      cube 			aprint_error("%s: Cannot handle drq16 %d\n",
    198       1.88      cube 			    probing ? "sbmatch" : device_xname(sc->sc_dev),
    199       1.88      cube 			    sc->sc_drq16);
    200       1.84  christos 			return 0;
    201       1.84  christos 		}
    202       1.84  christos 		if (sc->sc_drq8 >= __arraycount(drq_conf)) {
    203       1.88      cube 			aprint_error("%s: Cannot handle drq8 %d\n",
    204       1.88      cube 			    probing ? "sbmatch" : device_xname(sc->sc_dev),
    205       1.88      cube 			    sc->sc_drq8);
    206       1.84  christos 			return 0;
    207       1.84  christos 		}
    208       1.43   mycroft #if 0
    209       1.88      cube 		printf("%s: old drq conf %02x\n", device_xname(sc->sc_dev),
    210       1.43   mycroft 		    sbdsp_mix_read(sc, SBP_SET_DRQ));
    211       1.88      cube 		printf("%s: try drq conf %02x\n", device_xname(sc->sc_dev),
    212       1.43   mycroft 		    drq_conf[sc->sc_drq16] | drq_conf[sc->sc_drq8]);
    213       1.43   mycroft #endif
    214       1.47  augustss 		w = drq_conf[sc->sc_drq16] | drq_conf[sc->sc_drq8];
    215       1.47  augustss 		sbdsp_mix_write(sc, SBP_SET_DRQ, w);
    216       1.47  augustss 		r = sbdsp_mix_read(sc, SBP_SET_DRQ) & 0xeb;
    217       1.47  augustss 		if (r != w) {
    218       1.88      cube 			aprint_error("%s: setting drq mask %02x failed, "
    219       1.88      cube 			    "got %02x\n",
    220       1.88      cube 			    probing ? "sbmatch" : device_xname(sc->sc_dev), w,
    221       1.88      cube 			    r);
    222       1.47  augustss 			return 0;
    223       1.47  augustss 		}
    224       1.43   mycroft #if 0
    225       1.88      cube 		printf("%s: new drq conf %02x\n", device_xname(sc->sc_dev),
    226       1.43   mycroft 		    sbdsp_mix_read(sc, SBP_SET_DRQ));
    227       1.43   mycroft #endif
    228       1.43   mycroft 
    229       1.43   mycroft #if 0
    230       1.88      cube 		printf("%s: old irq conf %02x\n", device_xname(sc->sc_dev),
    231       1.43   mycroft 		    sbdsp_mix_read(sc, SBP_SET_IRQ));
    232       1.88      cube 		printf("%s: try irq conf %02x\n", device_xname(sc->sc_dev),
    233       1.43   mycroft 		    irq_conf[sc->sc_irq]);
    234       1.43   mycroft #endif
    235       1.47  augustss 		w = irq_conf[sc->sc_irq];
    236       1.47  augustss 		sbdsp_mix_write(sc, SBP_SET_IRQ, w);
    237       1.47  augustss 		r = sbdsp_mix_read(sc, SBP_SET_IRQ) & 0x0f;
    238       1.47  augustss 		if (r != w) {
    239       1.88      cube 			aprint_error("%s: setting irq mask %02x failed, "
    240       1.88      cube 			    "got %02x\n",
    241       1.88      cube 			    probing ? "sbmatch" : device_xname(sc->sc_dev), w,
    242       1.88      cube 			    r);
    243       1.47  augustss 			return 0;
    244       1.47  augustss 		}
    245       1.43   mycroft #if 0
    246       1.88      cube 		printf("%s: new irq conf %02x\n", device_xname(sc->sc_dev),
    247       1.43   mycroft 		    sbdsp_mix_read(sc, SBP_SET_IRQ));
    248       1.43   mycroft #endif
    249       1.43   mycroft 	}
    250       1.43   mycroft 
    251       1.39  christos 	return 1;
    252       1.39  christos }
    253       1.39  christos 
    254       1.39  christos 
    255       1.39  christos void
    256       1.80      kent sbattach(struct sbdsp_softc *sc)
    257       1.39  christos {
    258       1.63  augustss 	struct audio_attach_args arg;
    259       1.39  christos 
    260       1.39  christos 	sbdsp_attach(sc);
    261       1.39  christos 
    262       1.88      cube 	audio_attach_mi(&sb_hw_if, sc, sc->sc_dev);
    263       1.68  augustss 
    264       1.69   mycroft #if NMPU > 0
    265       1.82  christos 	switch(sc->sc_hasmpu) {
    266       1.82  christos 	default:
    267       1.83      cube 	case SBMPU_NONE:	/* no mpu */
    268       1.82  christos 		break;
    269       1.83      cube 	case SBMPU_INTERNAL:	/* try to attach midi directly */
    270       1.88      cube 		midi_attach_mi(&sb_midi_hw_if, sc, sc->sc_dev);
    271       1.82  christos 		break;
    272       1.83      cube 	case SBMPU_EXTERNAL:	/* search for mpu */
    273       1.68  augustss 		arg.type = AUDIODEV_TYPE_MPU;
    274       1.68  augustss 		arg.hwif = 0;
    275       1.68  augustss 		arg.hdl = 0;
    276       1.88      cube 		sc->sc_mpudev = config_found_ia(sc->sc_dev, "sbdsp", &arg, audioprint);
    277       1.82  christos 		break;
    278        1.1       cgd 	}
    279        1.6   mycroft #endif
    280       1.67   mycroft 	if (sc->sc_model >= SB_20) {
    281       1.67   mycroft 		arg.type = AUDIODEV_TYPE_OPL;
    282       1.67   mycroft 		arg.hwif = 0;
    283       1.67   mycroft 		arg.hdl = 0;
    284       1.88      cube 		(void)config_found_ia(sc->sc_dev, "sbdsp", &arg, audioprint);
    285       1.67   mycroft 	}
    286       1.60  augustss }
    287        1.1       cgd 
    288        1.1       cgd /*
    289       1.17    brezak  * Various routines to interface to higher level audio driver
    290        1.1       cgd  */
    291        1.1       cgd 
    292        1.1       cgd int
    293       1.80      kent sb_getdev(void *addr, struct audio_device *retp)
    294        1.1       cgd {
    295       1.75  jdolecek 	static const char * const names[] = SB_NAMES;
    296       1.80      kent 	struct sbdsp_softc *sc;
    297       1.75  jdolecek 	const char *config;
    298       1.32       jtk 
    299       1.80      kent 	sc = addr;
    300       1.48  augustss 	if (sc->sc_model == SB_JAZZ)
    301       1.77    itojun 		strlcpy(retp->name, "MV Jazz16", sizeof(retp->name));
    302       1.32       jtk 	else
    303       1.77    itojun 		strlcpy(retp->name, "SoundBlaster", sizeof(retp->name));
    304       1.77    itojun 	snprintf(retp->version, sizeof(retp->version), "%d.%02d",
    305       1.77    itojun 	    SBVER_MAJOR(sc->sc_version), SBVER_MINOR(sc->sc_version));
    306       1.85  christos 	if (sc->sc_model < sizeof names / sizeof names[0])
    307       1.53  augustss 		config = names[sc->sc_model];
    308       1.53  augustss 	else
    309       1.53  augustss 		config = "??";
    310       1.77    itojun 	strlcpy(retp->config, config, sizeof(retp->config));
    311       1.80      kent 
    312        1.6   mycroft 	return 0;
    313        1.1       cgd }
    314