Home | History | Annotate | Line # | Download | only in isa
sb.c revision 1.70.4.1
      1  1.70.4.1   thorpej /*	$NetBSD: sb.c,v 1.70.4.1 2002/01/10 19:55:42 thorpej 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.1       cgd 
     37  1.70.4.1   thorpej #include <sys/cdefs.h>
     38  1.70.4.1   thorpej __KERNEL_RCSID(0, "$NetBSD: sb.c,v 1.70.4.1 2002/01/10 19:55:42 thorpej Exp $");
     39  1.70.4.1   thorpej 
     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.1       cgd #include <machine/cpu.h>
     51      1.36   mycroft #include <machine/intr.h>
     52      1.49   thorpej #include <machine/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.63  augustss #include <dev/midi_if.h>
     59      1.17    brezak 
     60      1.23       cgd #include <dev/isa/isavar.h>
     61      1.23       cgd #include <dev/isa/isadmavar.h>
     62       1.1       cgd 
     63      1.39  christos #include <dev/isa/sbreg.h>
     64      1.39  christos #include <dev/isa/sbvar.h>
     65      1.24       cgd #include <dev/isa/sbdspvar.h>
     66      1.33   thorpej 
     67      1.69   mycroft #if NMPU > 0
     68      1.60  augustss struct midi_hw_if sb_midi_hw_if = {
     69      1.60  augustss 	sbdsp_midi_open,
     70      1.60  augustss 	sbdsp_midi_close,
     71      1.60  augustss 	sbdsp_midi_output,
     72      1.60  augustss 	sbdsp_midi_getinfo,
     73      1.60  augustss 	0,			/* ioctl */
     74      1.60  augustss };
     75      1.60  augustss #endif
     76      1.60  augustss 
     77      1.33   thorpej struct audio_device sb_device = {
     78      1.33   thorpej 	"SoundBlaster",
     79      1.33   thorpej 	"x",
     80      1.33   thorpej 	"sb"
     81      1.17    brezak };
     82       1.1       cgd 
     83      1.22   mycroft int	sb_getdev __P((void *, struct audio_device *));
     84       1.1       cgd 
     85      1.17    brezak /*
     86      1.17    brezak  * Define our interface to the higher level audio driver.
     87      1.17    brezak  */
     88      1.17    brezak 
     89      1.17    brezak struct audio_hw_if sb_hw_if = {
     90      1.53  augustss 	sbdsp_open,
     91      1.17    brezak 	sbdsp_close,
     92      1.51  augustss 	0,
     93      1.17    brezak 	sbdsp_query_encoding,
     94      1.46  augustss 	sbdsp_set_params,
     95      1.17    brezak 	sbdsp_round_blocksize,
     96      1.51  augustss 	0,
     97      1.61   mycroft 	0,
     98      1.61   mycroft 	0,
     99      1.61   mycroft 	0,
    100      1.61   mycroft 	0,
    101      1.65   mycroft 	sbdsp_halt_output,
    102      1.65   mycroft 	sbdsp_halt_input,
    103      1.17    brezak 	sbdsp_speaker_ctl,
    104      1.17    brezak 	sb_getdev,
    105      1.51  augustss 	0,
    106      1.17    brezak 	sbdsp_mixer_set_port,
    107      1.17    brezak 	sbdsp_mixer_get_port,
    108      1.17    brezak 	sbdsp_mixer_query_devinfo,
    109      1.50  augustss 	sb_malloc,
    110      1.50  augustss 	sb_free,
    111      1.64   mycroft 	sb_round_buffersize,
    112      1.52  augustss         sb_mappage,
    113      1.53  augustss 	sbdsp_get_props,
    114      1.61   mycroft 	sbdsp_trigger_output,
    115      1.61   mycroft 	sbdsp_trigger_input,
    116  1.70.4.1   thorpej 	0,
    117       1.6   mycroft };
    118       1.1       cgd 
    119      1.17    brezak /*
    120      1.17    brezak  * Probe / attach routines.
    121      1.17    brezak  */
    122      1.17    brezak 
    123      1.39  christos 
    124       1.1       cgd int
    125      1.39  christos sbmatch(sc)
    126      1.39  christos 	struct sbdsp_softc *sc;
    127       1.1       cgd {
    128      1.43   mycroft 	static u_char drq_conf[8] = {
    129      1.43   mycroft 		0x01, 0x02, -1, 0x08, -1, 0x20, 0x40, 0x80
    130      1.28   mycroft 	};
    131      1.39  christos 
    132      1.19    brezak 	static u_char irq_conf[11] = {
    133      1.28   mycroft 		-1, -1, 0x01, -1, -1, 0x02, -1, 0x04, -1, 0x01, 0x08
    134      1.19    brezak 	};
    135       1.1       cgd 
    136      1.44   mycroft 	if (sbdsp_probe(sc) == 0)
    137       1.6   mycroft 		return 0;
    138      1.43   mycroft 
    139       1.1       cgd 	/*
    140       1.1       cgd 	 * Cannot auto-discover DMA channel.
    141       1.1       cgd 	 */
    142      1.26    brezak 	if (ISSBPROCLASS(sc)) {
    143      1.43   mycroft 		if (!SBP_DRQ_VALID(sc->sc_drq8)) {
    144      1.43   mycroft 			printf("%s: configured dma chan %d invalid\n",
    145      1.43   mycroft 			    sc->sc_dev.dv_xname, sc->sc_drq8);
    146      1.43   mycroft 			return 0;
    147      1.43   mycroft 		}
    148      1.43   mycroft 	} else {
    149      1.43   mycroft 		if (!SB_DRQ_VALID(sc->sc_drq8)) {
    150      1.39  christos 			printf("%s: configured dma chan %d invalid\n",
    151      1.43   mycroft 			    sc->sc_dev.dv_xname, sc->sc_drq8);
    152      1.17    brezak 			return 0;
    153      1.17    brezak 		}
    154      1.17    brezak 	}
    155      1.49   thorpej 
    156      1.56  augustss         if (0 <= sc->sc_drq16 && sc->sc_drq16 <= 3)
    157      1.56  augustss         	/*
    158      1.56  augustss                  * XXX Some ViBRA16 cards seem to have two 8 bit DMA
    159      1.56  augustss                  * channels.  I've no clue how to use them, so ignore
    160      1.56  augustss                  * one of them for now.  -- augustss (at) netbsd.org
    161      1.56  augustss                  */
    162      1.56  augustss         	sc->sc_drq16 = -1;
    163      1.56  augustss 
    164      1.43   mycroft 	if (ISSB16CLASS(sc)) {
    165      1.43   mycroft 		if (sc->sc_drq16 == -1)
    166      1.43   mycroft 			sc->sc_drq16 = sc->sc_drq8;
    167      1.43   mycroft 		if (!SB16_DRQ_VALID(sc->sc_drq16)) {
    168      1.39  christos 			printf("%s: configured dma chan %d invalid\n",
    169      1.43   mycroft 			    sc->sc_dev.dv_xname, sc->sc_drq16);
    170      1.17    brezak 			return 0;
    171      1.17    brezak 		}
    172      1.43   mycroft 	} else
    173      1.43   mycroft 		sc->sc_drq16 = sc->sc_drq8;
    174      1.17    brezak 
    175      1.26    brezak 	if (ISSBPROCLASS(sc)) {
    176      1.39  christos 		if (!SBP_IRQ_VALID(sc->sc_irq)) {
    177      1.39  christos 			printf("%s: configured irq %d invalid\n",
    178      1.39  christos 			    sc->sc_dev.dv_xname, sc->sc_irq);
    179      1.17    brezak 			return 0;
    180      1.19    brezak 		}
    181      1.43   mycroft 	} else {
    182      1.39  christos 		if (!SB_IRQ_VALID(sc->sc_irq)) {
    183      1.39  christos 			printf("%s: configured irq %d invalid\n",
    184      1.39  christos 			    sc->sc_dev.dv_xname, sc->sc_irq);
    185       1.6   mycroft 			return 0;
    186       1.1       cgd 		}
    187       1.1       cgd 	}
    188      1.43   mycroft 
    189      1.70       mjl 	if (ISSB16CLASS(sc) && !(sc->sc_quirks & SB_QUIRK_NO_INIT_DRQ)) {
    190      1.47  augustss 		int w, r;
    191      1.43   mycroft #if 0
    192      1.43   mycroft 		printf("%s: old drq conf %02x\n", sc->sc_dev.dv_xname,
    193      1.43   mycroft 		    sbdsp_mix_read(sc, SBP_SET_DRQ));
    194      1.43   mycroft 		printf("%s: try drq conf %02x\n", sc->sc_dev.dv_xname,
    195      1.43   mycroft 		    drq_conf[sc->sc_drq16] | drq_conf[sc->sc_drq8]);
    196      1.43   mycroft #endif
    197      1.47  augustss 		w = drq_conf[sc->sc_drq16] | drq_conf[sc->sc_drq8];
    198      1.47  augustss 		sbdsp_mix_write(sc, SBP_SET_DRQ, w);
    199      1.47  augustss 		r = sbdsp_mix_read(sc, SBP_SET_DRQ) & 0xeb;
    200      1.47  augustss 		if (r != w) {
    201      1.47  augustss 			printf("%s: setting drq mask %02x failed, got %02x\n",
    202      1.47  augustss 			    sc->sc_dev.dv_xname, w, r);
    203      1.47  augustss 			return 0;
    204      1.47  augustss 		}
    205      1.43   mycroft #if 0
    206      1.43   mycroft 		printf("%s: new drq conf %02x\n", sc->sc_dev.dv_xname,
    207      1.43   mycroft 		    sbdsp_mix_read(sc, SBP_SET_DRQ));
    208      1.43   mycroft #endif
    209      1.43   mycroft 
    210      1.43   mycroft #if 0
    211      1.43   mycroft 		printf("%s: old irq conf %02x\n", sc->sc_dev.dv_xname,
    212      1.43   mycroft 		    sbdsp_mix_read(sc, SBP_SET_IRQ));
    213      1.43   mycroft 		printf("%s: try irq conf %02x\n", sc->sc_dev.dv_xname,
    214      1.43   mycroft 		    irq_conf[sc->sc_irq]);
    215      1.43   mycroft #endif
    216      1.47  augustss 		w = irq_conf[sc->sc_irq];
    217      1.47  augustss 		sbdsp_mix_write(sc, SBP_SET_IRQ, w);
    218      1.47  augustss 		r = sbdsp_mix_read(sc, SBP_SET_IRQ) & 0x0f;
    219      1.47  augustss 		if (r != w) {
    220      1.47  augustss 			printf("%s: setting irq mask %02x failed, got %02x\n",
    221      1.47  augustss 			    sc->sc_dev.dv_xname, w, r);
    222      1.47  augustss 			return 0;
    223      1.47  augustss 		}
    224      1.43   mycroft #if 0
    225      1.43   mycroft 		printf("%s: new irq conf %02x\n", sc->sc_dev.dv_xname,
    226      1.43   mycroft 		    sbdsp_mix_read(sc, SBP_SET_IRQ));
    227      1.43   mycroft #endif
    228      1.43   mycroft 	}
    229      1.43   mycroft 
    230      1.39  christos 	return 1;
    231      1.39  christos }
    232      1.39  christos 
    233      1.39  christos 
    234      1.39  christos void
    235      1.39  christos sbattach(sc)
    236      1.39  christos 	struct sbdsp_softc *sc;
    237      1.39  christos {
    238      1.63  augustss 	struct audio_attach_args arg;
    239      1.39  christos 
    240      1.39  christos 	sbdsp_attach(sc);
    241      1.39  christos 
    242      1.68  augustss 	audio_attach_mi(&sb_hw_if, sc, &sc->sc_dev);
    243      1.68  augustss 
    244      1.69   mycroft #if NMPU > 0
    245      1.68  augustss 	if (sc->sc_hasmpu) {
    246      1.68  augustss 		arg.type = AUDIODEV_TYPE_MPU;
    247      1.68  augustss 		arg.hwif = 0;
    248      1.68  augustss 		arg.hdl = 0;
    249      1.68  augustss 		sc->sc_mpudev = config_found(&sc->sc_dev, &arg, audioprint);
    250      1.67   mycroft 	} else {
    251      1.67   mycroft 		midi_attach_mi(&sb_midi_hw_if, sc, &sc->sc_dev);
    252       1.1       cgd 	}
    253       1.6   mycroft #endif
    254      1.63  augustss 
    255      1.67   mycroft 	if (sc->sc_model >= SB_20) {
    256      1.67   mycroft 		arg.type = AUDIODEV_TYPE_OPL;
    257      1.67   mycroft 		arg.hwif = 0;
    258      1.67   mycroft 		arg.hdl = 0;
    259      1.67   mycroft 		(void)config_found(&sc->sc_dev, &arg, audioprint);
    260      1.67   mycroft 	}
    261      1.60  augustss }
    262       1.1       cgd 
    263       1.1       cgd /*
    264      1.17    brezak  * Various routines to interface to higher level audio driver
    265       1.1       cgd  */
    266       1.1       cgd 
    267       1.1       cgd int
    268      1.17    brezak sb_getdev(addr, retp)
    269      1.22   mycroft 	void *addr;
    270      1.17    brezak 	struct audio_device *retp;
    271       1.1       cgd {
    272      1.32       jtk 	struct sbdsp_softc *sc = addr;
    273      1.53  augustss 	static char *names[] = SB_NAMES;
    274      1.53  augustss 	char *config;
    275      1.32       jtk 
    276      1.48  augustss 	if (sc->sc_model == SB_JAZZ)
    277      1.32       jtk 		strncpy(retp->name, "MV Jazz16", sizeof(retp->name));
    278      1.32       jtk 	else
    279      1.32       jtk 		strncpy(retp->name, "SoundBlaster", sizeof(retp->name));
    280      1.40     mikel 	sprintf(retp->version, "%d.%02d",
    281      1.48  augustss 		SBVER_MAJOR(sc->sc_version),
    282      1.48  augustss 		SBVER_MINOR(sc->sc_version));
    283      1.53  augustss 	if (0 <= sc->sc_model && sc->sc_model < sizeof names / sizeof names[0])
    284      1.53  augustss 		config = names[sc->sc_model];
    285      1.53  augustss 	else
    286      1.53  augustss 		config = "??";
    287      1.53  augustss 	strncpy(retp->config, config, sizeof(retp->config));
    288      1.32       jtk 
    289       1.6   mycroft 	return 0;
    290       1.1       cgd }
    291