Home | History | Annotate | Line # | Download | only in isa
sbdsp.c revision 1.63.2.4
      1  1.63.2.4   thorpej /*	$NetBSD: sbdsp.c,v 1.63.2.4 1997/09/16 03:50:28 thorpej Exp $	*/
      2       1.1    brezak 
      3       1.1    brezak /*
      4       1.1    brezak  * Copyright (c) 1991-1993 Regents of the University of California.
      5       1.1    brezak  * All rights reserved.
      6       1.1    brezak  *
      7       1.1    brezak  * Redistribution and use in source and binary forms, with or without
      8       1.1    brezak  * modification, are permitted provided that the following conditions
      9       1.1    brezak  * are met:
     10       1.1    brezak  * 1. Redistributions of source code must retain the above copyright
     11       1.1    brezak  *    notice, this list of conditions and the following disclaimer.
     12       1.1    brezak  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1    brezak  *    notice, this list of conditions and the following disclaimer in the
     14       1.1    brezak  *    documentation and/or other materials provided with the distribution.
     15       1.1    brezak  * 3. All advertising materials mentioning features or use of this software
     16       1.1    brezak  *    must display the following acknowledgement:
     17       1.1    brezak  *	This product includes software developed by the Computer Systems
     18       1.1    brezak  *	Engineering Group at Lawrence Berkeley Laboratory.
     19       1.1    brezak  * 4. Neither the name of the University nor of the Laboratory may be used
     20       1.1    brezak  *    to endorse or promote products derived from this software without
     21       1.1    brezak  *    specific prior written permission.
     22       1.1    brezak  *
     23       1.1    brezak  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24       1.1    brezak  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25       1.1    brezak  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26       1.1    brezak  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27       1.1    brezak  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28       1.1    brezak  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29       1.1    brezak  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30       1.1    brezak  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31       1.1    brezak  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32       1.1    brezak  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33       1.1    brezak  * SUCH DAMAGE.
     34       1.1    brezak  *
     35       1.1    brezak  */
     36      1.39   mycroft 
     37       1.1    brezak /*
     38       1.1    brezak  * SoundBlaster Pro code provided by John Kohl, based on lots of
     39       1.1    brezak  * information he gleaned from Steve Haehnichen <steve (at) vigra.com>'s
     40       1.1    brezak  * SBlast driver for 386BSD and DOS driver code from Daniel Sachs
     41       1.1    brezak  * <sachs (at) meibm15.cen.uiuc.edu>.
     42      1.52  augustss  * Lots of rewrites by Lennart Augustsson <augustss (at) cs.chalmers.se>
     43      1.52  augustss  * with information from SB "Hardware Programming Guide" and the
     44      1.52  augustss  * Linux drivers.
     45       1.1    brezak  */
     46       1.1    brezak 
     47       1.1    brezak #include <sys/param.h>
     48       1.1    brezak #include <sys/systm.h>
     49       1.1    brezak #include <sys/errno.h>
     50       1.1    brezak #include <sys/ioctl.h>
     51       1.1    brezak #include <sys/syslog.h>
     52       1.1    brezak #include <sys/device.h>
     53       1.1    brezak #include <sys/proc.h>
     54       1.1    brezak #include <sys/buf.h>
     55       1.1    brezak #include <vm/vm.h>
     56       1.1    brezak 
     57       1.1    brezak #include <machine/cpu.h>
     58      1.26   mycroft #include <machine/intr.h>
     59      1.57   thorpej #include <machine/bus.h>
     60       1.1    brezak 
     61       1.1    brezak #include <sys/audioio.h>
     62       1.1    brezak #include <dev/audio_if.h>
     63      1.45  augustss #include <dev/mulaw.h>
     64  1.63.2.1   thorpej #include <dev/auconv.h>
     65       1.1    brezak 
     66       1.6       cgd #include <dev/isa/isavar.h>
     67       1.6       cgd #include <dev/isa/isadmavar.h>
     68       1.1    brezak 
     69       1.7       cgd #include <dev/isa/sbreg.h>
     70       1.7       cgd #include <dev/isa/sbdspvar.h>
     71       1.1    brezak 
     72      1.12    brezak #ifdef AUDIO_DEBUG
     73      1.60  augustss #define DPRINTF(x)	if (sbdspdebug) printf x
     74       1.1    brezak int	sbdspdebug = 0;
     75       1.1    brezak #else
     76       1.1    brezak #define DPRINTF(x)
     77       1.1    brezak #endif
     78       1.1    brezak 
     79       1.1    brezak #ifndef SBDSP_NPOLL
     80       1.1    brezak #define SBDSP_NPOLL 3000
     81       1.1    brezak #endif
     82       1.1    brezak 
     83       1.1    brezak struct {
     84       1.1    brezak 	int wdsp;
     85       1.1    brezak 	int rdsp;
     86       1.1    brezak 	int wmidi;
     87       1.1    brezak } sberr;
     88       1.1    brezak 
     89      1.16   mycroft /*
     90      1.16   mycroft  * Time constant routines follow.  See SBK, section 12.
     91      1.16   mycroft  * Although they don't come out and say it (in the docs),
     92      1.16   mycroft  * the card clearly uses a 1MHz countdown timer, as the
     93      1.16   mycroft  * low-speed formula (p. 12-4) is:
     94      1.16   mycroft  *	tc = 256 - 10^6 / sr
     95      1.16   mycroft  * In high-speed mode, the constant is the upper byte of a 16-bit counter,
     96      1.16   mycroft  * and a 256MHz clock is used:
     97      1.16   mycroft  *	tc = 65536 - 256 * 10^ 6 / sr
     98      1.16   mycroft  * Since we can only use the upper byte of the HS TC, the two formulae
     99      1.16   mycroft  * are equivalent.  (Why didn't they say so?)  E.g.,
    100      1.16   mycroft  * 	(65536 - 256 * 10 ^ 6 / x) >> 8 = 256 - 10^6 / x
    101      1.16   mycroft  *
    102      1.16   mycroft  * The crossover point (from low- to high-speed modes) is different
    103      1.16   mycroft  * for the SBPRO and SB20.  The table on p. 12-5 gives the following data:
    104      1.16   mycroft  *
    105      1.16   mycroft  *				SBPRO			SB20
    106      1.16   mycroft  *				-----			--------
    107      1.16   mycroft  * input ls min			4	KHz		4	KHz
    108      1.16   mycroft  * input ls max			23	KHz		13	KHz
    109      1.16   mycroft  * input hs max			44.1	KHz		15	KHz
    110      1.16   mycroft  * output ls min		4	KHz		4	KHz
    111      1.16   mycroft  * output ls max		23	KHz		23	KHz
    112      1.16   mycroft  * output hs max		44.1	KHz		44.1	KHz
    113      1.16   mycroft  */
    114      1.52  augustss /* XXX Should we round the tc?
    115      1.52  augustss #define SB_RATE_TO_TC(x) (((65536 - 256 * 1000000 / (x)) + 128) >> 8)
    116      1.52  augustss */
    117      1.52  augustss #define SB_RATE_TO_TC(x) (256 - 1000000 / (x))
    118      1.52  augustss #define SB_TC_TO_RATE(tc) (1000000 / (256 - (tc)))
    119      1.52  augustss 
    120      1.52  augustss struct sbmode {
    121      1.54  augustss 	short	model;
    122      1.52  augustss 	u_char	channels;
    123      1.52  augustss 	u_char	precision;
    124      1.52  augustss 	u_short	lowrate, highrate;
    125      1.52  augustss 	u_char	cmd;
    126      1.56       jtk 	u_char	cmdchan;
    127      1.52  augustss };
    128      1.52  augustss static struct sbmode sbpmodes[] = {
    129      1.52  augustss  { SB_1,    1,  8,  4000, 22727, SB_DSP_WDMA      },
    130      1.52  augustss  { SB_20,   1,  8,  4000, 22727, SB_DSP_WDMA_LOOP },
    131      1.52  augustss  { SB_2x,   1,  8,  4000, 22727, SB_DSP_WDMA_LOOP },
    132      1.52  augustss  { SB_2x,   1,  8, 22727, 45454, SB_DSP_HS_OUTPUT },
    133      1.52  augustss  { SB_PRO,  1,  8,  4000, 22727, SB_DSP_WDMA_LOOP },
    134      1.52  augustss  { SB_PRO,  1,  8, 22727, 45454, SB_DSP_HS_OUTPUT },
    135      1.52  augustss  { SB_PRO,  2,  8, 11025, 22727, SB_DSP_HS_OUTPUT },
    136      1.56       jtk  /* Yes, we write the record mode to set 16-bit playback mode. weird, huh? */
    137      1.52  augustss  { SB_JAZZ, 1,  8,  4000, 22727, SB_DSP_WDMA_LOOP, SB_DSP_RECORD_MONO },
    138      1.52  augustss  { SB_JAZZ, 1,  8, 22727, 45454, SB_DSP_HS_OUTPUT, SB_DSP_RECORD_MONO },
    139      1.52  augustss  { SB_JAZZ, 2,  8, 11025, 22727, SB_DSP_HS_OUTPUT, SB_DSP_RECORD_STEREO },
    140      1.52  augustss  { SB_JAZZ, 1, 16,  4000, 22727, SB_DSP_WDMA_LOOP, JAZZ16_RECORD_MONO },
    141      1.52  augustss  { SB_JAZZ, 1, 16, 22727, 45454, SB_DSP_HS_OUTPUT, JAZZ16_RECORD_MONO },
    142      1.52  augustss  { SB_JAZZ, 2, 16, 11025, 22727, SB_DSP_HS_OUTPUT, JAZZ16_RECORD_STEREO },
    143      1.52  augustss  { SB_16,   1,  8,  5000, 45000, SB_DSP16_WDMA_8  },
    144      1.52  augustss  { SB_16,   2,  8,  5000, 45000, SB_DSP16_WDMA_8  },
    145  1.63.2.1   thorpej #define PLAY16 15 /* must be the index of the next entry in the table */
    146      1.52  augustss  { SB_16,   1, 16,  5000, 45000, SB_DSP16_WDMA_16 },
    147      1.52  augustss  { SB_16,   2, 16,  5000, 45000, SB_DSP16_WDMA_16 },
    148      1.52  augustss  { -1 }
    149      1.52  augustss };
    150      1.52  augustss static struct sbmode sbrmodes[] = {
    151      1.52  augustss  { SB_1,    1,  8,  4000, 12987, SB_DSP_RDMA      },
    152      1.52  augustss  { SB_20,   1,  8,  4000, 12987, SB_DSP_RDMA_LOOP },
    153      1.52  augustss  { SB_2x,   1,  8,  4000, 12987, SB_DSP_RDMA_LOOP },
    154      1.52  augustss  { SB_2x,   1,  8, 12987, 14925, SB_DSP_HS_INPUT  },
    155      1.52  augustss  { SB_PRO,  1,  8,  4000, 22727, SB_DSP_RDMA_LOOP, SB_DSP_RECORD_MONO },
    156      1.52  augustss  { SB_PRO,  1,  8, 22727, 45454, SB_DSP_HS_INPUT,  SB_DSP_RECORD_MONO },
    157      1.52  augustss  { SB_PRO,  2,  8, 11025, 22727, SB_DSP_HS_INPUT,  SB_DSP_RECORD_STEREO },
    158      1.52  augustss  { SB_JAZZ, 1,  8,  4000, 22727, SB_DSP_RDMA_LOOP, SB_DSP_RECORD_MONO },
    159      1.52  augustss  { SB_JAZZ, 1,  8, 22727, 45454, SB_DSP_HS_INPUT,  SB_DSP_RECORD_MONO },
    160      1.52  augustss  { SB_JAZZ, 2,  8, 11025, 22727, SB_DSP_HS_INPUT,  SB_DSP_RECORD_STEREO },
    161      1.52  augustss  { SB_JAZZ, 1, 16,  4000, 22727, SB_DSP_RDMA_LOOP, JAZZ16_RECORD_MONO },
    162      1.52  augustss  { SB_JAZZ, 1, 16, 22727, 45454, SB_DSP_HS_INPUT,  JAZZ16_RECORD_MONO },
    163      1.52  augustss  { SB_JAZZ, 2, 16, 11025, 22727, SB_DSP_HS_INPUT,  JAZZ16_RECORD_STEREO },
    164      1.52  augustss  { SB_16,   1,  8,  5000, 45000, SB_DSP16_RDMA_8  },
    165      1.52  augustss  { SB_16,   2,  8,  5000, 45000, SB_DSP16_RDMA_8  },
    166      1.52  augustss  { SB_16,   1, 16,  5000, 45000, SB_DSP16_RDMA_16 },
    167      1.52  augustss  { SB_16,   2, 16,  5000, 45000, SB_DSP16_RDMA_16 },
    168      1.52  augustss  { -1 }
    169      1.52  augustss };
    170      1.52  augustss 
    171      1.52  augustss void	sbversion __P((struct sbdsp_softc *));
    172      1.52  augustss void	sbdsp_jazz16_probe __P((struct sbdsp_softc *));
    173      1.52  augustss void	sbdsp_set_mixer_gain __P((struct sbdsp_softc *sc, int port));
    174      1.25  christos void	sbdsp_to __P((void *));
    175      1.25  christos void	sbdsp_pause __P((struct sbdsp_softc *));
    176      1.25  christos int	sbdsp_set_timeconst __P((struct sbdsp_softc *, int));
    177      1.52  augustss int	sbdsp16_set_rate __P((struct sbdsp_softc *, int, int));
    178      1.50  augustss int	sbdsp_set_in_ports __P((struct sbdsp_softc *, int));
    179      1.50  augustss void	sbdsp_set_ifilter __P((void *, int));
    180      1.50  augustss int	sbdsp_get_ifilter __P((void *));
    181      1.25  christos 
    182  1.63.2.3   thorpej static	int sbdsp_dma_setup_input __P((struct sbdsp_softc *sc));
    183  1.63.2.3   thorpej static	int sbdsp_dma_setup_output __P((struct sbdsp_softc *sc));
    184  1.63.2.1   thorpej static	int sbdsp_adjust __P((int, int));
    185  1.63.2.1   thorpej 
    186      1.25  christos #ifdef AUDIO_DEBUG
    187      1.25  christos void sb_printsc __P((struct sbdsp_softc *));
    188      1.25  christos 
    189       1.1    brezak void
    190      1.25  christos sb_printsc(sc)
    191      1.25  christos 	struct sbdsp_softc *sc;
    192       1.1    brezak {
    193       1.1    brezak 	int i;
    194       1.1    brezak 
    195  1.63.2.3   thorpej 	printf("open %d dmachan %d/%d %d/%d iobase 0x%x irq %d\n",
    196  1.63.2.3   thorpej 	    (int)sc->sc_open, sc->sc_i.run, sc->sc_o.run,
    197  1.63.2.3   thorpej 	    sc->sc_drq8, sc->sc_drq16,
    198      1.43     mikel 	    sc->sc_iobase, sc->sc_irq);
    199      1.52  augustss 	printf("irate %d itc %x orate %d otc %x\n",
    200  1.63.2.3   thorpej 	    sc->sc_i.rate, sc->sc_i.tc,
    201  1.63.2.3   thorpej 	    sc->sc_o.rate, sc->sc_o.tc);
    202      1.43     mikel 	printf("outport %u inport %u spkron %u nintr %lu\n",
    203      1.16   mycroft 	    sc->out_port, sc->in_port, sc->spkr_state, sc->sc_interrupts);
    204  1.63.2.3   thorpej 	printf("intr8 %p arg8 %p\n",
    205  1.63.2.3   thorpej 	    sc->sc_intr8, sc->sc_arg16);
    206  1.63.2.3   thorpej 	printf("intr16 %p arg16 %p\n",
    207  1.63.2.3   thorpej 	    sc->sc_intr8, sc->sc_arg16);
    208      1.43     mikel 	printf("gain:");
    209       1.1    brezak 	for (i = 0; i < SB_NDEVS; i++)
    210      1.50  augustss 		printf(" %u,%u", sc->gain[i][SB_LEFT], sc->gain[i][SB_RIGHT]);
    211      1.28  christos 	printf("\n");
    212       1.1    brezak }
    213      1.43     mikel #endif /* AUDIO_DEBUG */
    214       1.1    brezak 
    215       1.1    brezak /*
    216       1.1    brezak  * Probe / attach routines.
    217       1.1    brezak  */
    218       1.1    brezak 
    219       1.1    brezak /*
    220       1.1    brezak  * Probe for the soundblaster hardware.
    221       1.1    brezak  */
    222       1.1    brezak int
    223       1.1    brezak sbdsp_probe(sc)
    224       1.1    brezak 	struct sbdsp_softc *sc;
    225       1.1    brezak {
    226       1.1    brezak 
    227       1.1    brezak 	if (sbdsp_reset(sc) < 0) {
    228       1.1    brezak 		DPRINTF(("sbdsp: couldn't reset card\n"));
    229       1.1    brezak 		return 0;
    230       1.1    brezak 	}
    231      1.24       jtk 	/* if flags set, go and probe the jazz16 stuff */
    232      1.52  augustss 	if (sc->sc_dev.dv_cfdata->cf_flags & 1)
    233      1.52  augustss 		sbdsp_jazz16_probe(sc);
    234      1.52  augustss 	else
    235      1.52  augustss 		sbversion(sc);
    236      1.52  augustss 	if (sc->sc_model == SB_UNK) {
    237      1.52  augustss 		/* Unknown SB model found. */
    238      1.52  augustss 		DPRINTF(("sbdsp: unknown SB model found\n"));
    239      1.52  augustss 		return 0;
    240      1.40       jtk 	}
    241       1.1    brezak 	return 1;
    242       1.1    brezak }
    243       1.1    brezak 
    244       1.1    brezak /*
    245      1.24       jtk  * Try add-on stuff for Jazz16.
    246      1.24       jtk  */
    247      1.52  augustss void
    248      1.24       jtk sbdsp_jazz16_probe(sc)
    249      1.24       jtk 	struct sbdsp_softc *sc;
    250      1.24       jtk {
    251      1.24       jtk 	static u_char jazz16_irq_conf[16] = {
    252      1.24       jtk 	    -1, -1, 0x02, 0x03,
    253      1.24       jtk 	    -1, 0x01, -1, 0x04,
    254      1.24       jtk 	    -1, 0x02, 0x05, -1,
    255      1.24       jtk 	    -1, -1, -1, 0x06};
    256      1.24       jtk 	static u_char jazz16_drq_conf[8] = {
    257      1.24       jtk 	    -1, 0x01, -1, 0x02,
    258      1.24       jtk 	    -1, 0x03, -1, 0x04};
    259      1.24       jtk 
    260      1.31  christos 	bus_space_tag_t iot = sc->sc_iot;
    261      1.31  christos 	bus_space_handle_t ioh;
    262      1.31  christos 
    263      1.52  augustss 	sbversion(sc);
    264      1.52  augustss 
    265      1.40       jtk 	DPRINTF(("jazz16 probe\n"));
    266      1.40       jtk 
    267      1.40       jtk 	if (bus_space_map(iot, JAZZ16_CONFIG_PORT, 1, 0, &ioh)) {
    268      1.40       jtk 		DPRINTF(("bus map failed\n"));
    269      1.52  augustss 		return;
    270      1.40       jtk 	}
    271      1.24       jtk 
    272      1.35   mycroft 	if (jazz16_drq_conf[sc->sc_drq8] == (u_char)-1 ||
    273      1.40       jtk 	    jazz16_irq_conf[sc->sc_irq] == (u_char)-1) {
    274      1.40       jtk 		DPRINTF(("drq/irq check failed\n"));
    275      1.31  christos 		goto done;		/* give up, we can't do it. */
    276      1.40       jtk 	}
    277      1.31  christos 
    278      1.31  christos 	bus_space_write_1(iot, ioh, 0, JAZZ16_WAKEUP);
    279      1.24       jtk 	delay(10000);			/* delay 10 ms */
    280      1.31  christos 	bus_space_write_1(iot, ioh, 0, JAZZ16_SETBASE);
    281      1.31  christos 	bus_space_write_1(iot, ioh, 0, sc->sc_iobase & 0x70);
    282      1.24       jtk 
    283      1.40       jtk 	if (sbdsp_reset(sc) < 0) {
    284      1.40       jtk 		DPRINTF(("sbdsp_reset check failed\n"));
    285      1.31  christos 		goto done;		/* XXX? what else could we do? */
    286      1.40       jtk 	}
    287      1.24       jtk 
    288      1.40       jtk 	if (sbdsp_wdsp(sc, JAZZ16_READ_VER)) {
    289      1.40       jtk 		DPRINTF(("read16 setup failed\n"));
    290      1.31  christos 		goto done;
    291      1.40       jtk 	}
    292      1.31  christos 
    293      1.40       jtk 	if (sbdsp_rdsp(sc) != JAZZ16_VER_JAZZ) {
    294      1.40       jtk 		DPRINTF(("read16 failed\n"));
    295      1.31  christos 		goto done;
    296      1.40       jtk 	}
    297      1.24       jtk 
    298      1.35   mycroft 	/* XXX set both 8 & 16-bit drq to same channel, it works fine. */
    299      1.35   mycroft 	sc->sc_drq16 = sc->sc_drq8;
    300      1.31  christos 	if (sbdsp_wdsp(sc, JAZZ16_SET_DMAINTR) ||
    301      1.35   mycroft 	    sbdsp_wdsp(sc, (jazz16_drq_conf[sc->sc_drq16] << 4) |
    302      1.35   mycroft 		jazz16_drq_conf[sc->sc_drq8]) ||
    303      1.40       jtk 	    sbdsp_wdsp(sc, jazz16_irq_conf[sc->sc_irq])) {
    304      1.40       jtk 		DPRINTF(("sbdsp: can't write jazz16 probe stuff\n"));
    305      1.40       jtk 	} else {
    306      1.40       jtk 		DPRINTF(("jazz16 detected!\n"));
    307      1.52  augustss 		sc->sc_model = SB_JAZZ;
    308      1.52  augustss 		sc->sc_mixer_model = SBM_CT1345; /* XXX really? */
    309      1.40       jtk 	}
    310      1.31  christos 
    311      1.31  christos done:
    312      1.31  christos 	bus_space_unmap(iot, ioh, 1);
    313      1.24       jtk }
    314      1.24       jtk 
    315      1.24       jtk /*
    316       1.1    brezak  * Attach hardware to driver, attach hardware driver to audio
    317       1.1    brezak  * pseudo-device driver .
    318       1.1    brezak  */
    319       1.1    brezak void
    320       1.1    brezak sbdsp_attach(sc)
    321       1.1    brezak 	struct sbdsp_softc *sc;
    322       1.1    brezak {
    323  1.63.2.2   thorpej 	struct audio_params pparams, rparams;
    324      1.51  augustss         int i;
    325      1.51  augustss         u_int v;
    326       1.1    brezak 
    327      1.57   thorpej 	/*
    328      1.57   thorpej 	 * Create our DMA maps.
    329      1.57   thorpej 	 */
    330      1.57   thorpej 	if (sc->sc_drq8 != -1) {
    331      1.57   thorpej 		if (isa_dmamap_create(sc->sc_isa, sc->sc_drq8,
    332      1.62  augustss 		    MAX_ISADMA, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
    333      1.57   thorpej 			printf("%s: can't create map for drq %d\n",
    334      1.57   thorpej 			    sc->sc_dev.dv_xname, sc->sc_drq8);
    335      1.57   thorpej 			return;
    336      1.57   thorpej 		}
    337      1.57   thorpej 	}
    338      1.57   thorpej 	if (sc->sc_drq16 != -1 && sc->sc_drq16 != sc->sc_drq8) {
    339      1.57   thorpej 		if (isa_dmamap_create(sc->sc_isa, sc->sc_drq16,
    340      1.62  augustss 		    MAX_ISADMA, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
    341      1.57   thorpej 			printf("%s: can't create map for drq %d\n",
    342      1.57   thorpej 			    sc->sc_dev.dv_xname, sc->sc_drq16);
    343      1.57   thorpej 			return;
    344      1.57   thorpej 		}
    345      1.57   thorpej 	}
    346      1.57   thorpej 
    347  1.63.2.2   thorpej 	pparams = audio_default;
    348  1.63.2.2   thorpej 	rparams = audio_default;
    349  1.63.2.2   thorpej         sbdsp_set_params(sc, AUMODE_RECORD|AUMODE_PLAY, 0, &pparams, &rparams);
    350      1.51  augustss 
    351      1.51  augustss 	sbdsp_set_in_port(sc, SB_MIC_VOL);
    352      1.51  augustss 	sbdsp_set_out_port(sc, SB_MASTER_VOL);
    353      1.51  augustss 
    354      1.51  augustss 	if (sc->sc_mixer_model != SBM_NONE) {
    355      1.51  augustss         	/* Reset the mixer.*/
    356       1.1    brezak 		sbdsp_mix_write(sc, SBP_MIX_RESET, SBP_MIX_RESET);
    357      1.51  augustss                 /* And set our own default values */
    358      1.50  augustss 		for (i = 0; i < SB_NDEVS; i++) {
    359      1.50  augustss 			switch(i) {
    360      1.50  augustss 			case SB_MIC_VOL:
    361      1.50  augustss 			case SB_LINE_IN_VOL:
    362      1.50  augustss 				v = 0;
    363      1.50  augustss 				break;
    364      1.50  augustss 			case SB_BASS:
    365      1.50  augustss 			case SB_TREBLE:
    366      1.50  augustss 				v = SB_ADJUST_GAIN(sc, AUDIO_MAX_GAIN/2);
    367      1.50  augustss 				break;
    368  1.63.2.2   thorpej 			case SB_CD_IN_MUTE:
    369  1.63.2.2   thorpej 			case SB_MIC_IN_MUTE:
    370  1.63.2.2   thorpej 			case SB_LINE_IN_MUTE:
    371  1.63.2.2   thorpej 			case SB_MIDI_IN_MUTE:
    372  1.63.2.2   thorpej 			case SB_CD_SWAP:
    373  1.63.2.2   thorpej 			case SB_MIC_SWAP:
    374  1.63.2.2   thorpej 			case SB_LINE_SWAP:
    375  1.63.2.2   thorpej 			case SB_MIDI_SWAP:
    376  1.63.2.2   thorpej 			case SB_CD_OUT_MUTE:
    377  1.63.2.2   thorpej 			case SB_MIC_OUT_MUTE:
    378  1.63.2.2   thorpej 			case SB_LINE_OUT_MUTE:
    379  1.63.2.2   thorpej 				v = 0;
    380  1.63.2.2   thorpej 				break;
    381      1.50  augustss 			default:
    382      1.50  augustss 				v = SB_ADJUST_GAIN(sc, AUDIO_MAX_GAIN * 3 / 4);
    383      1.50  augustss 				break;
    384      1.50  augustss 			}
    385      1.50  augustss 			sc->gain[i][SB_LEFT] = sc->gain[i][SB_RIGHT] = v;
    386      1.50  augustss 			sbdsp_set_mixer_gain(sc, i);
    387      1.50  augustss 		}
    388      1.17       jtk 		sc->in_filter = 0;	/* no filters turned on, please */
    389       1.1    brezak 	}
    390      1.16   mycroft 
    391      1.28  christos 	printf(": dsp v%d.%02d%s\n",
    392      1.52  augustss 	       SBVER_MAJOR(sc->sc_version), SBVER_MINOR(sc->sc_version),
    393      1.52  augustss 	       sc->sc_model == SB_JAZZ ? ": <Jazz16>" : "");
    394  1.63.2.3   thorpej 
    395  1.63.2.3   thorpej 	sc->sc_fullduplex = ISSB16CLASS(sc) &&
    396  1.63.2.3   thorpej 		sc->sc_drq8 != -1 && sc->sc_drq16 != -1 &&
    397  1.63.2.3   thorpej 		sc->sc_drq8 != sc->sc_drq16;
    398       1.1    brezak }
    399       1.1    brezak 
    400       1.1    brezak void
    401       1.1    brezak sbdsp_mix_write(sc, mixerport, val)
    402       1.1    brezak 	struct sbdsp_softc *sc;
    403       1.1    brezak 	int mixerport;
    404       1.1    brezak 	int val;
    405       1.1    brezak {
    406      1.31  christos 	bus_space_tag_t iot = sc->sc_iot;
    407      1.31  christos 	bus_space_handle_t ioh = sc->sc_ioh;
    408      1.48  augustss 	int s;
    409      1.31  christos 
    410      1.48  augustss 	s = splaudio();
    411      1.31  christos 	bus_space_write_1(iot, ioh, SBP_MIXER_ADDR, mixerport);
    412      1.48  augustss 	delay(20);
    413      1.31  christos 	bus_space_write_1(iot, ioh, SBP_MIXER_DATA, val);
    414       1.1    brezak 	delay(30);
    415      1.48  augustss 	splx(s);
    416       1.1    brezak }
    417       1.1    brezak 
    418       1.1    brezak int
    419       1.1    brezak sbdsp_mix_read(sc, mixerport)
    420       1.1    brezak 	struct sbdsp_softc *sc;
    421       1.1    brezak 	int mixerport;
    422       1.1    brezak {
    423      1.31  christos 	bus_space_tag_t iot = sc->sc_iot;
    424      1.31  christos 	bus_space_handle_t ioh = sc->sc_ioh;
    425      1.48  augustss 	int val;
    426      1.48  augustss 	int s;
    427      1.31  christos 
    428      1.48  augustss 	s = splaudio();
    429      1.31  christos 	bus_space_write_1(iot, ioh, SBP_MIXER_ADDR, mixerport);
    430      1.48  augustss 	delay(20);
    431      1.48  augustss 	val = bus_space_read_1(iot, ioh, SBP_MIXER_DATA);
    432      1.48  augustss 	delay(30);
    433      1.48  augustss 	splx(s);
    434      1.48  augustss 	return val;
    435       1.1    brezak }
    436       1.1    brezak 
    437      1.52  augustss /*
    438      1.52  augustss  * Various routines to interface to higher level audio driver
    439      1.52  augustss  */
    440      1.52  augustss 
    441       1.1    brezak int
    442       1.1    brezak sbdsp_query_encoding(addr, fp)
    443      1.16   mycroft 	void *addr;
    444      1.16   mycroft 	struct audio_encoding *fp;
    445       1.1    brezak {
    446      1.46  augustss 	struct sbdsp_softc *sc = addr;
    447      1.52  augustss 	int emul;
    448      1.52  augustss 
    449      1.54  augustss 	emul = ISSB16CLASS(sc) ? 0 : AUDIO_ENCODINGFLAG_EMULATED;
    450      1.46  augustss 
    451      1.16   mycroft 	switch (fp->index) {
    452      1.16   mycroft 	case 0:
    453      1.46  augustss 		strcpy(fp->name, AudioEulinear);
    454      1.46  augustss 		fp->encoding = AUDIO_ENCODING_ULINEAR;
    455      1.46  augustss 		fp->precision = 8;
    456      1.46  augustss 		fp->flags = 0;
    457      1.52  augustss 		return 0;
    458      1.46  augustss 	case 1:
    459      1.16   mycroft 		strcpy(fp->name, AudioEmulaw);
    460      1.44  augustss 		fp->encoding = AUDIO_ENCODING_ULAW;
    461      1.44  augustss 		fp->precision = 8;
    462      1.44  augustss 		fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
    463      1.52  augustss 		return 0;
    464      1.44  augustss 	case 2:
    465      1.55  augustss 		strcpy(fp->name, AudioEalaw);
    466      1.55  augustss 		fp->encoding = AUDIO_ENCODING_ALAW;
    467      1.55  augustss 		fp->precision = 8;
    468      1.55  augustss 		fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
    469      1.55  augustss 		return 0;
    470      1.55  augustss 	case 3:
    471      1.46  augustss 		strcpy(fp->name, AudioElinear);
    472      1.59  augustss 		fp->encoding = AUDIO_ENCODING_SLINEAR;
    473      1.44  augustss 		fp->precision = 8;
    474      1.52  augustss 		fp->flags = emul;
    475      1.52  augustss 		return 0;
    476      1.51  augustss         }
    477      1.54  augustss         if (!ISSB16CLASS(sc) && sc->sc_model != SB_JAZZ)
    478      1.51  augustss 		return EINVAL;
    479      1.51  augustss 
    480      1.51  augustss         switch(fp->index) {
    481      1.55  augustss         case 4:
    482      1.51  augustss 		strcpy(fp->name, AudioElinear_le);
    483      1.59  augustss 		fp->encoding = AUDIO_ENCODING_SLINEAR_LE;
    484      1.51  augustss 		fp->precision = 16;
    485      1.51  augustss 		fp->flags = 0;
    486      1.52  augustss 		return 0;
    487      1.55  augustss 	case 5:
    488      1.51  augustss 		strcpy(fp->name, AudioEulinear_le);
    489      1.51  augustss 		fp->encoding = AUDIO_ENCODING_ULINEAR_LE;
    490      1.51  augustss 		fp->precision = 16;
    491      1.52  augustss 		fp->flags = emul;
    492      1.52  augustss 		return 0;
    493      1.55  augustss 	case 6:
    494      1.51  augustss 		strcpy(fp->name, AudioElinear_be);
    495      1.59  augustss 		fp->encoding = AUDIO_ENCODING_SLINEAR_BE;
    496      1.51  augustss 		fp->precision = 16;
    497      1.51  augustss 		fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
    498      1.52  augustss 		return 0;
    499      1.55  augustss 	case 7:
    500      1.51  augustss 		strcpy(fp->name, AudioEulinear_be);
    501      1.51  augustss 		fp->encoding = AUDIO_ENCODING_ULINEAR_BE;
    502      1.51  augustss 		fp->precision = 16;
    503      1.51  augustss 		fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
    504      1.52  augustss 		return 0;
    505      1.16   mycroft 	default:
    506      1.51  augustss 		return EINVAL;
    507      1.16   mycroft 	}
    508      1.51  augustss 	return 0;
    509       1.1    brezak }
    510       1.1    brezak 
    511       1.1    brezak int
    512  1.63.2.2   thorpej sbdsp_set_params(addr, setmode, usemode, play, rec)
    513      1.46  augustss 	void *addr;
    514  1.63.2.2   thorpej 	int setmode, usemode;
    515  1.63.2.2   thorpej 	struct audio_params *play, *rec;
    516       1.1    brezak {
    517      1.46  augustss 	struct sbdsp_softc *sc = addr;
    518      1.52  augustss 	struct sbmode *m;
    519  1.63.2.2   thorpej 	u_int rate, tc, bmode;
    520      1.46  augustss 	void (*swcode) __P((void *, u_char *buf, int cnt));
    521  1.63.2.2   thorpej 	int factor;
    522  1.63.2.1   thorpej 	int model;
    523  1.63.2.3   thorpej 	int chan;
    524  1.63.2.2   thorpej 	struct audio_params *p;
    525  1.63.2.2   thorpej 	int mode;
    526      1.41  augustss 
    527  1.63.2.1   thorpej 	model = sc->sc_model;
    528  1.63.2.1   thorpej 	if (model > SB_16)
    529  1.63.2.1   thorpej 		model = SB_16;	/* later models work like SB16 */
    530  1.63.2.2   thorpej 
    531  1.63.2.2   thorpej 	/* Set first record info, then play info */
    532  1.63.2.2   thorpej 	for(mode = AUMODE_RECORD; mode != -1;
    533  1.63.2.2   thorpej 	    mode = mode == AUMODE_RECORD ? AUMODE_PLAY : -1) {
    534  1.63.2.2   thorpej 		if ((setmode & mode) == 0)
    535  1.63.2.2   thorpej 			continue;
    536  1.63.2.2   thorpej 
    537  1.63.2.2   thorpej 		p = mode == AUMODE_PLAY ? play : rec;
    538  1.63.2.3   thorpej 		/* Locate proper commands */
    539  1.63.2.2   thorpej 		for(m = mode == AUMODE_PLAY ? sbpmodes : sbrmodes;
    540  1.63.2.2   thorpej 		    m->model != -1; m++) {
    541  1.63.2.2   thorpej 			if (model == m->model &&
    542  1.63.2.2   thorpej 			    p->channels == m->channels &&
    543  1.63.2.2   thorpej 			    p->precision == m->precision &&
    544  1.63.2.2   thorpej 			    p->sample_rate >= m->lowrate &&
    545  1.63.2.2   thorpej 			    p->sample_rate < m->highrate)
    546  1.63.2.2   thorpej 				break;
    547      1.52  augustss 		}
    548  1.63.2.2   thorpej 		if (m->model == -1)
    549      1.46  augustss 			return EINVAL;
    550  1.63.2.2   thorpej 		rate = p->sample_rate;
    551  1.63.2.2   thorpej 		swcode = 0;
    552  1.63.2.2   thorpej 		factor = 1;
    553  1.63.2.2   thorpej 		tc = 1;
    554  1.63.2.2   thorpej 		bmode = -1;
    555  1.63.2.2   thorpej 		if (model == SB_16) {
    556  1.63.2.2   thorpej 			switch (p->encoding) {
    557  1.63.2.2   thorpej 			case AUDIO_ENCODING_SLINEAR_BE:
    558  1.63.2.2   thorpej 				if (p->precision == 16)
    559  1.63.2.2   thorpej 					swcode = swap_bytes;
    560  1.63.2.2   thorpej 				/* fall into */
    561  1.63.2.2   thorpej 			case AUDIO_ENCODING_SLINEAR_LE:
    562  1.63.2.2   thorpej 				bmode = SB_BMODE_SIGNED;
    563  1.63.2.2   thorpej 				break;
    564  1.63.2.2   thorpej 			case AUDIO_ENCODING_ULINEAR_BE:
    565  1.63.2.2   thorpej 				if (p->precision == 16)
    566  1.63.2.2   thorpej 					swcode = swap_bytes;
    567  1.63.2.2   thorpej 				/* fall into */
    568  1.63.2.2   thorpej 			case AUDIO_ENCODING_ULINEAR_LE:
    569  1.63.2.2   thorpej 				bmode = SB_BMODE_UNSIGNED;
    570  1.63.2.2   thorpej 				break;
    571  1.63.2.2   thorpej 			case AUDIO_ENCODING_ULAW:
    572  1.63.2.2   thorpej 				if (mode == AUMODE_PLAY) {
    573  1.63.2.2   thorpej 					swcode = mulaw_to_ulinear16;
    574  1.63.2.2   thorpej 					factor = 2;
    575  1.63.2.2   thorpej 					m = &sbpmodes[PLAY16];
    576  1.63.2.2   thorpej 				} else
    577  1.63.2.2   thorpej 					swcode = ulinear8_to_mulaw;
    578  1.63.2.2   thorpej 				bmode = SB_BMODE_UNSIGNED;
    579  1.63.2.2   thorpej 				break;
    580  1.63.2.2   thorpej 			case AUDIO_ENCODING_ALAW:
    581  1.63.2.2   thorpej 				if (mode == AUMODE_PLAY) {
    582  1.63.2.2   thorpej 					swcode = alaw_to_ulinear16;
    583  1.63.2.2   thorpej 					factor = 2;
    584  1.63.2.2   thorpej 					m = &sbpmodes[PLAY16];
    585  1.63.2.2   thorpej 				} else
    586  1.63.2.2   thorpej 					swcode = ulinear8_to_alaw;
    587  1.63.2.2   thorpej 				bmode = SB_BMODE_UNSIGNED;
    588  1.63.2.2   thorpej 				break;
    589  1.63.2.2   thorpej 			default:
    590  1.63.2.2   thorpej 				return EINVAL;
    591  1.63.2.2   thorpej 			}
    592  1.63.2.2   thorpej 			if (p->channels == 2)
    593  1.63.2.2   thorpej 				bmode |= SB_BMODE_STEREO;
    594  1.63.2.2   thorpej 		} else if (m->model == SB_JAZZ && m->precision == 16) {
    595  1.63.2.2   thorpej 			switch (p->encoding) {
    596  1.63.2.2   thorpej 			case AUDIO_ENCODING_SLINEAR_LE:
    597  1.63.2.2   thorpej 				break;
    598  1.63.2.2   thorpej 			case AUDIO_ENCODING_ULINEAR_LE:
    599  1.63.2.2   thorpej 				swcode = change_sign16;
    600  1.63.2.2   thorpej 				break;
    601  1.63.2.2   thorpej 			case AUDIO_ENCODING_SLINEAR_BE:
    602  1.63.2.2   thorpej 				swcode = swap_bytes;
    603  1.63.2.2   thorpej 				break;
    604  1.63.2.2   thorpej 			case AUDIO_ENCODING_ULINEAR_BE:
    605  1.63.2.2   thorpej 				swcode = mode == AUMODE_PLAY ?
    606  1.63.2.2   thorpej 					swap_bytes_change_sign16 : change_sign16_swap_bytes;
    607  1.63.2.2   thorpej 				break;
    608  1.63.2.2   thorpej 			case AUDIO_ENCODING_ULAW:
    609  1.63.2.2   thorpej 				swcode = mode == AUMODE_PLAY ?
    610  1.63.2.2   thorpej 					mulaw_to_ulinear8 : ulinear8_to_mulaw;
    611  1.63.2.2   thorpej 				break;
    612  1.63.2.2   thorpej 			case AUDIO_ENCODING_ALAW:
    613  1.63.2.2   thorpej 				swcode = mode == AUMODE_PLAY ?
    614  1.63.2.2   thorpej 					alaw_to_ulinear8 : ulinear8_to_alaw;
    615  1.63.2.2   thorpej 				break;
    616  1.63.2.2   thorpej 			default:
    617  1.63.2.2   thorpej 				return EINVAL;
    618  1.63.2.2   thorpej 			}
    619  1.63.2.2   thorpej 			tc = SB_RATE_TO_TC(p->sample_rate * p->channels);
    620  1.63.2.2   thorpej 			p->sample_rate = SB_TC_TO_RATE(tc) / p->channels;
    621  1.63.2.2   thorpej 		} else {
    622  1.63.2.2   thorpej 			switch (p->encoding) {
    623  1.63.2.2   thorpej 			case AUDIO_ENCODING_SLINEAR_BE:
    624  1.63.2.2   thorpej 			case AUDIO_ENCODING_SLINEAR_LE:
    625  1.63.2.2   thorpej 				swcode = change_sign8;
    626  1.63.2.2   thorpej 				break;
    627  1.63.2.2   thorpej 			case AUDIO_ENCODING_ULINEAR_BE:
    628  1.63.2.2   thorpej 			case AUDIO_ENCODING_ULINEAR_LE:
    629  1.63.2.2   thorpej 				break;
    630  1.63.2.2   thorpej 			case AUDIO_ENCODING_ULAW:
    631  1.63.2.2   thorpej 				swcode = mode == AUMODE_PLAY ?
    632  1.63.2.2   thorpej 					mulaw_to_ulinear8 : ulinear8_to_mulaw;
    633  1.63.2.2   thorpej 				break;
    634  1.63.2.2   thorpej 			case AUDIO_ENCODING_ALAW:
    635  1.63.2.2   thorpej 				swcode = mode == AUMODE_PLAY ?
    636  1.63.2.2   thorpej 					alaw_to_ulinear8 : ulinear8_to_alaw;
    637  1.63.2.2   thorpej 				break;
    638  1.63.2.2   thorpej 			default:
    639  1.63.2.2   thorpej 				return EINVAL;
    640  1.63.2.2   thorpej 			}
    641  1.63.2.2   thorpej 			tc = SB_RATE_TO_TC(p->sample_rate * p->channels);
    642  1.63.2.2   thorpej 			p->sample_rate = SB_TC_TO_RATE(tc) / p->channels;
    643      1.52  augustss 		}
    644  1.63.2.3   thorpej 
    645  1.63.2.3   thorpej 		chan = m->precision == 16 ? sc->sc_drq16 : sc->sc_drq8;
    646  1.63.2.2   thorpej 		if (mode == AUMODE_PLAY) {
    647  1.63.2.3   thorpej 			sc->sc_o.rate = rate;
    648  1.63.2.3   thorpej 			sc->sc_o.tc = tc;
    649  1.63.2.3   thorpej 			sc->sc_o.modep = m;
    650  1.63.2.3   thorpej 			sc->sc_o.bmode = bmode;
    651  1.63.2.3   thorpej 			sc->sc_o.dmachan = chan;
    652  1.63.2.2   thorpej 		} else {
    653  1.63.2.3   thorpej 			sc->sc_i.rate = rate;
    654  1.63.2.3   thorpej 			sc->sc_i.tc = tc;
    655  1.63.2.3   thorpej 			sc->sc_i.modep = m;
    656  1.63.2.3   thorpej 			sc->sc_i.bmode = bmode;
    657  1.63.2.3   thorpej 			sc->sc_i.dmachan = chan;
    658      1.52  augustss 		}
    659  1.63.2.3   thorpej 
    660  1.63.2.2   thorpej 		p->sw_code = swcode;
    661  1.63.2.2   thorpej 		p->factor = factor;
    662  1.63.2.3   thorpej 		DPRINTF(("sbdsp_set_params: model=%d, mode=%d, rate=%ld, prec=%d, chan=%d, enc=%d -> tc=%02x, cmd=%02x, bmode=%02x, cmdchan=%02x, swcode=%p, factor=%d\n",
    663  1.63.2.2   thorpej 			 sc->sc_model, mode, p->sample_rate, p->precision, p->channels,
    664  1.63.2.2   thorpej 			 p->encoding, tc, m->cmd, bmode, m->cmdchan, swcode, factor));
    665  1.63.2.3   thorpej 
    666      1.45  augustss 	}
    667      1.48  augustss 	/*
    668      1.48  augustss 	 * XXX
    669      1.48  augustss 	 * Should wait for chip to be idle.
    670      1.48  augustss 	 */
    671  1.63.2.3   thorpej 	sc->sc_i.run = SB_NOTRUNNING;
    672  1.63.2.3   thorpej 	sc->sc_o.run = SB_NOTRUNNING;
    673      1.48  augustss 
    674  1.63.2.3   thorpej 	if (sc->sc_fullduplex &&
    675  1.63.2.3   thorpej 	    (usemode & (AUMODE_PLAY | AUMODE_RECORD)) == (AUMODE_PLAY | AUMODE_RECORD) &&
    676  1.63.2.3   thorpej 	    sc->sc_i.dmachan == sc->sc_o.dmachan) {
    677  1.63.2.3   thorpej 		DPRINTF(("sbdsp_commit: fd=%d, usemode=%d, idma=%d, odma=%d\n", sc->sc_fullduplex, usemode, sc->sc_i.dmachan, sc->sc_o.dmachan));
    678  1.63.2.3   thorpej 		if (sc->sc_o.dmachan == sc->sc_drq8) {
    679  1.63.2.3   thorpej 			/* Use 16 bit DMA for playing by expanding the samples. */
    680  1.63.2.3   thorpej 			play->sw_code = linear8_to_linear16;
    681  1.63.2.3   thorpej 			play->factor = 2;
    682  1.63.2.3   thorpej 			sc->sc_o.modep = &sbpmodes[PLAY16];
    683  1.63.2.3   thorpej 			sc->sc_o.dmachan = sc->sc_drq16;
    684  1.63.2.3   thorpej 		} else {
    685  1.63.2.3   thorpej 			return EINVAL;
    686  1.63.2.3   thorpej 		}
    687  1.63.2.3   thorpej 	}
    688  1.63.2.3   thorpej 	DPRINTF(("sbdsp_set_params ichan=%d, ochan=%d\n", sc->sc_i.dmachan, sc->sc_o.dmachan));
    689      1.52  augustss 
    690      1.41  augustss 	return 0;
    691       1.1    brezak }
    692      1.45  augustss 
    693      1.50  augustss void
    694      1.17       jtk sbdsp_set_ifilter(addr, which)
    695      1.17       jtk 	void *addr;
    696      1.17       jtk 	int which;
    697      1.17       jtk {
    698      1.52  augustss 	struct sbdsp_softc *sc = addr;
    699      1.25  christos 	int mixval;
    700      1.17       jtk 
    701      1.50  augustss 	mixval = sbdsp_mix_read(sc, SBP_INFILTER) & ~SBP_IFILTER_MASK;
    702      1.50  augustss 	switch (which) {
    703      1.50  augustss 	case 0:
    704      1.50  augustss 		mixval |= SBP_FILTER_OFF;
    705      1.50  augustss 		break;
    706      1.50  augustss 	case SB_TREBLE:
    707      1.50  augustss 		mixval |= SBP_FILTER_ON | SBP_IFILTER_HIGH;
    708      1.50  augustss 		break;
    709      1.50  augustss 	case SB_BASS:
    710      1.50  augustss 		mixval |= SBP_FILTER_ON | SBP_IFILTER_LOW;
    711      1.50  augustss 		break;
    712      1.50  augustss 	default:
    713      1.50  augustss 		return;
    714      1.50  augustss 	}
    715      1.50  augustss 	sc->in_filter = mixval & SBP_IFILTER_MASK;
    716      1.50  augustss 	sbdsp_mix_write(sc, SBP_INFILTER, mixval);
    717      1.17       jtk }
    718      1.17       jtk 
    719      1.17       jtk int
    720      1.17       jtk sbdsp_get_ifilter(addr)
    721      1.17       jtk 	void *addr;
    722      1.17       jtk {
    723      1.52  augustss 	struct sbdsp_softc *sc = addr;
    724      1.17       jtk 
    725      1.50  augustss 	sc->in_filter =
    726      1.50  augustss 		sbdsp_mix_read(sc, SBP_INFILTER) & SBP_IFILTER_MASK;
    727      1.50  augustss 	switch (sc->in_filter) {
    728      1.50  augustss 	case SBP_FILTER_ON|SBP_IFILTER_HIGH:
    729      1.50  augustss 		return SB_TREBLE;
    730      1.50  augustss 	case SBP_FILTER_ON|SBP_IFILTER_LOW:
    731      1.50  augustss 		return SB_BASS;
    732      1.50  augustss 	default:
    733      1.50  augustss 		return 0;
    734      1.50  augustss 	}
    735      1.17       jtk }
    736      1.17       jtk 
    737      1.17       jtk int
    738       1.1    brezak sbdsp_set_out_port(addr, port)
    739       1.5   mycroft 	void *addr;
    740       1.1    brezak 	int port;
    741       1.1    brezak {
    742      1.50  augustss 	struct sbdsp_softc *sc = addr;
    743       1.1    brezak 
    744       1.1    brezak 	sc->out_port = port; /* Just record it */
    745       1.1    brezak 
    746      1.50  augustss 	return 0;
    747       1.1    brezak }
    748       1.1    brezak 
    749       1.1    brezak int
    750       1.1    brezak sbdsp_get_out_port(addr)
    751       1.5   mycroft 	void *addr;
    752       1.1    brezak {
    753      1.50  augustss 	struct sbdsp_softc *sc = addr;
    754       1.1    brezak 
    755      1.52  augustss 	return sc->out_port;
    756       1.1    brezak }
    757       1.1    brezak 
    758       1.1    brezak 
    759       1.1    brezak int
    760       1.1    brezak sbdsp_set_in_port(addr, port)
    761       1.5   mycroft 	void *addr;
    762       1.1    brezak 	int port;
    763       1.1    brezak {
    764      1.50  augustss 	return sbdsp_set_in_ports(addr, 1 << port);
    765      1.50  augustss }
    766      1.50  augustss 
    767      1.50  augustss int
    768      1.50  augustss sbdsp_set_in_ports(sc, mask)
    769      1.50  augustss 	struct sbdsp_softc *sc;
    770      1.50  augustss 	int mask;
    771      1.50  augustss {
    772      1.50  augustss 	int bitsl, bitsr;
    773      1.50  augustss 	int sbport;
    774      1.50  augustss 	int i;
    775      1.50  augustss 
    776      1.52  augustss 	DPRINTF(("sbdsp_set_in_ports: model=%d, mask=%x\n",
    777      1.52  augustss 		 sc->sc_mixer_model, mask));
    778      1.52  augustss 
    779      1.50  augustss 	switch(sc->sc_mixer_model) {
    780      1.50  augustss 	case SBM_NONE:
    781      1.50  augustss 		return EINVAL;
    782      1.50  augustss 	case SBM_CT1335:
    783      1.50  augustss 		if (mask != (1 << SB_MIC_VOL))
    784      1.50  augustss 			return EINVAL;
    785      1.50  augustss 		break;
    786      1.50  augustss 	case SBM_CT1345:
    787      1.50  augustss 		switch (mask) {
    788      1.50  augustss 		case 1 << SB_MIC_VOL:
    789      1.16   mycroft 			sbport = SBP_FROM_MIC;
    790      1.16   mycroft 			break;
    791      1.50  augustss 		case 1 << SB_LINE_IN_VOL:
    792      1.16   mycroft 			sbport = SBP_FROM_LINE;
    793      1.16   mycroft 			break;
    794      1.50  augustss 		case 1 << SB_CD_VOL:
    795      1.16   mycroft 			sbport = SBP_FROM_CD;
    796      1.16   mycroft 			break;
    797      1.16   mycroft 		default:
    798      1.60  augustss 			return (EINVAL);
    799      1.16   mycroft 		}
    800      1.50  augustss 		sbdsp_mix_write(sc, SBP_RECORD_SOURCE,
    801      1.50  augustss 		    SBP_RECORD_FROM(sbport, SBP_FILTER_OFF, SBP_IFILTER_HIGH));
    802      1.50  augustss 		break;
    803  1.63.2.1   thorpej 	case SBM_CT1XX5:
    804      1.50  augustss 	case SBM_CT1745:
    805      1.50  augustss 		if (mask & ~((1<<SB_MIDI_VOL) | (1<<SB_LINE_IN_VOL) |
    806      1.50  augustss 			     (1<<SB_CD_VOL) | (1<<SB_MIC_VOL)))
    807      1.50  augustss 			return EINVAL;
    808      1.50  augustss 		bitsr = 0;
    809      1.58  augustss 		if (mask & (1<<SB_MIDI_VOL))    bitsr |= SBP_MIDI_SRC_R;
    810      1.58  augustss 		if (mask & (1<<SB_LINE_IN_VOL)) bitsr |= SBP_LINE_SRC_R;
    811      1.58  augustss 		if (mask & (1<<SB_CD_VOL))      bitsr |= SBP_CD_SRC_R;
    812      1.50  augustss 		bitsl = SB_SRC_R_TO_L(bitsr);
    813      1.58  augustss 		if (mask & (1<<SB_MIC_VOL)) {
    814      1.50  augustss 			bitsl |= SBP_MIC_SRC;
    815      1.50  augustss 			bitsr |= SBP_MIC_SRC;
    816      1.16   mycroft 		}
    817      1.50  augustss 		sbdsp_mix_write(sc, SBP_RECORD_SOURCE_L, bitsl);
    818      1.50  augustss 		sbdsp_mix_write(sc, SBP_RECORD_SOURCE_R, bitsr);
    819      1.50  augustss 		break;
    820      1.50  augustss 	}
    821       1.1    brezak 
    822      1.50  augustss 	sc->in_mask = mask;
    823       1.1    brezak 
    824      1.50  augustss 	/* XXX
    825      1.50  augustss 	 * We have to fake a single port since the upper layer
    826      1.50  augustss 	 * expects one.
    827      1.50  augustss 	 */
    828      1.50  augustss 	for(i = 0; i < SB_NPORT; i++) {
    829      1.50  augustss 		if (mask & (1 << i)) {
    830      1.50  augustss 			sc->in_port = i;
    831      1.50  augustss 			break;
    832      1.50  augustss 		}
    833       1.1    brezak 	}
    834      1.50  augustss 	return 0;
    835       1.1    brezak }
    836       1.1    brezak 
    837       1.1    brezak int
    838       1.1    brezak sbdsp_get_in_port(addr)
    839       1.5   mycroft 	void *addr;
    840       1.1    brezak {
    841      1.50  augustss 	struct sbdsp_softc *sc = addr;
    842       1.1    brezak 
    843      1.50  augustss 	return sc->in_port;
    844       1.1    brezak }
    845       1.1    brezak 
    846       1.1    brezak 
    847       1.1    brezak int
    848       1.1    brezak sbdsp_speaker_ctl(addr, newstate)
    849       1.5   mycroft 	void *addr;
    850       1.1    brezak 	int newstate;
    851       1.1    brezak {
    852      1.50  augustss 	struct sbdsp_softc *sc = addr;
    853       1.1    brezak 
    854       1.1    brezak 	if ((newstate == SPKR_ON) &&
    855       1.1    brezak 	    (sc->spkr_state == SPKR_OFF)) {
    856       1.1    brezak 		sbdsp_spkron(sc);
    857       1.1    brezak 		sc->spkr_state = SPKR_ON;
    858       1.1    brezak 	}
    859       1.1    brezak 	if ((newstate == SPKR_OFF) &&
    860       1.1    brezak 	    (sc->spkr_state == SPKR_ON)) {
    861       1.1    brezak 		sbdsp_spkroff(sc);
    862       1.1    brezak 		sc->spkr_state = SPKR_OFF;
    863       1.1    brezak 	}
    864      1.52  augustss 	return 0;
    865       1.1    brezak }
    866       1.1    brezak 
    867       1.1    brezak int
    868       1.1    brezak sbdsp_round_blocksize(addr, blk)
    869       1.5   mycroft 	void *addr;
    870       1.1    brezak 	int blk;
    871       1.1    brezak {
    872      1.60  augustss 	blk &= -4;		/* round to biggest sample size */
    873      1.52  augustss 	return blk;
    874       1.1    brezak }
    875       1.1    brezak 
    876       1.1    brezak int
    877  1.63.2.1   thorpej sbdsp_open(addr, flags)
    878  1.63.2.1   thorpej 	void *addr;
    879       1.1    brezak 	int flags;
    880       1.1    brezak {
    881  1.63.2.1   thorpej 	struct sbdsp_softc *sc = addr;
    882  1.63.2.1   thorpej 
    883      1.52  augustss         DPRINTF(("sbdsp_open: sc=%p\n", sc));
    884       1.1    brezak 
    885       1.1    brezak 	if (sc->sc_open != 0 || sbdsp_reset(sc) != 0)
    886       1.1    brezak 		return ENXIO;
    887       1.1    brezak 
    888       1.1    brezak 	sc->sc_open = 1;
    889  1.63.2.3   thorpej 	sc->sc_openflags = flags;
    890       1.1    brezak 	sc->sc_mintr = 0;
    891      1.52  augustss 	if (ISSBPRO(sc) &&
    892      1.31  christos 	    sbdsp_wdsp(sc, SB_DSP_RECORD_MONO) < 0) {
    893       1.1    brezak 		DPRINTF(("sbdsp_open: can't set mono mode\n"));
    894       1.1    brezak 		/* we'll readjust when it's time for DMA. */
    895       1.1    brezak 	}
    896       1.1    brezak 
    897       1.1    brezak 	/*
    898       1.1    brezak 	 * Leave most things as they were; users must change things if
    899       1.1    brezak 	 * the previous process didn't leave it they way they wanted.
    900       1.1    brezak 	 * Looked at another way, it's easy to set up a configuration
    901       1.1    brezak 	 * in one program and leave it for another to inherit.
    902       1.1    brezak 	 */
    903       1.1    brezak 	DPRINTF(("sbdsp_open: opened\n"));
    904       1.1    brezak 
    905       1.1    brezak 	return 0;
    906       1.1    brezak }
    907       1.1    brezak 
    908       1.1    brezak void
    909       1.1    brezak sbdsp_close(addr)
    910       1.5   mycroft 	void *addr;
    911       1.1    brezak {
    912       1.5   mycroft 	struct sbdsp_softc *sc = addr;
    913       1.1    brezak 
    914      1.52  augustss         DPRINTF(("sbdsp_close: sc=%p\n", sc));
    915       1.1    brezak 
    916       1.1    brezak 	sc->sc_open = 0;
    917       1.1    brezak 	sbdsp_spkroff(sc);
    918       1.1    brezak 	sc->spkr_state = SPKR_OFF;
    919  1.63.2.3   thorpej 	sc->sc_intr8 = 0;
    920  1.63.2.3   thorpej 	sc->sc_intr16 = 0;
    921       1.1    brezak 	sc->sc_mintr = 0;
    922      1.15   mycroft 	sbdsp_haltdma(sc);
    923       1.1    brezak 
    924       1.1    brezak 	DPRINTF(("sbdsp_close: closed\n"));
    925       1.1    brezak }
    926       1.1    brezak 
    927       1.1    brezak /*
    928       1.1    brezak  * Lower-level routines
    929       1.1    brezak  */
    930       1.1    brezak 
    931       1.1    brezak /*
    932       1.1    brezak  * Reset the card.
    933       1.1    brezak  * Return non-zero if the card isn't detected.
    934       1.1    brezak  */
    935       1.1    brezak int
    936       1.1    brezak sbdsp_reset(sc)
    937      1.52  augustss 	struct sbdsp_softc *sc;
    938       1.1    brezak {
    939      1.31  christos 	bus_space_tag_t iot = sc->sc_iot;
    940      1.31  christos 	bus_space_handle_t ioh = sc->sc_ioh;
    941       1.1    brezak 
    942  1.63.2.3   thorpej 	sc->sc_intr8 = 0;
    943  1.63.2.3   thorpej 	sc->sc_intr16 = 0;
    944  1.63.2.3   thorpej 	if (sc->sc_i.run != SB_NOTRUNNING) {
    945  1.63.2.3   thorpej 		isa_dmaabort(sc->sc_isa, sc->sc_i.dmachan);
    946  1.63.2.3   thorpej 		sc->sc_i.run = SB_NOTRUNNING;
    947  1.63.2.3   thorpej 	}
    948  1.63.2.3   thorpej 	if (sc->sc_o.run != SB_NOTRUNNING) {
    949  1.63.2.3   thorpej 		isa_dmaabort(sc->sc_isa, sc->sc_o.dmachan);
    950  1.63.2.3   thorpej 		sc->sc_o.run = SB_NOTRUNNING;
    951      1.15   mycroft 	}
    952      1.15   mycroft 
    953       1.1    brezak 	/*
    954       1.1    brezak 	 * See SBK, section 11.3.
    955       1.1    brezak 	 * We pulse a reset signal into the card.
    956       1.1    brezak 	 * Gee, what a brilliant hardware design.
    957       1.1    brezak 	 */
    958      1.31  christos 	bus_space_write_1(iot, ioh, SBP_DSP_RESET, 1);
    959      1.15   mycroft 	delay(10);
    960      1.31  christos 	bus_space_write_1(iot, ioh, SBP_DSP_RESET, 0);
    961      1.15   mycroft 	delay(30);
    962      1.31  christos 	if (sbdsp_rdsp(sc) != SB_MAGIC)
    963       1.1    brezak 		return -1;
    964      1.15   mycroft 
    965       1.1    brezak 	return 0;
    966       1.1    brezak }
    967       1.1    brezak 
    968       1.1    brezak /*
    969       1.1    brezak  * Write a byte to the dsp.
    970  1.63.2.3   thorpej  * We are at the mercy of the card as we use a
    971       1.1    brezak  * polling loop and wait until it can take the byte.
    972       1.1    brezak  */
    973       1.1    brezak int
    974      1.31  christos sbdsp_wdsp(sc, v)
    975      1.31  christos 	struct sbdsp_softc *sc;
    976      1.31  christos 	int v;
    977       1.1    brezak {
    978      1.31  christos 	bus_space_tag_t iot = sc->sc_iot;
    979      1.31  christos 	bus_space_handle_t ioh = sc->sc_ioh;
    980      1.52  augustss 	int i;
    981      1.52  augustss 	u_char x;
    982       1.1    brezak 
    983       1.1    brezak 	for (i = SBDSP_NPOLL; --i >= 0; ) {
    984      1.31  christos 		x = bus_space_read_1(iot, ioh, SBP_DSP_WSTAT);
    985      1.15   mycroft 		delay(10);
    986  1.63.2.3   thorpej 		if ((x & SB_DSP_BUSY) == 0) {
    987  1.63.2.3   thorpej 			bus_space_write_1(iot, ioh, SBP_DSP_WRITE, v);
    988  1.63.2.3   thorpej 			delay(10);
    989  1.63.2.3   thorpej 			return 0;
    990  1.63.2.3   thorpej 		}
    991       1.1    brezak 	}
    992       1.1    brezak 	++sberr.wdsp;
    993       1.1    brezak 	return -1;
    994       1.1    brezak }
    995       1.1    brezak 
    996       1.1    brezak /*
    997       1.1    brezak  * Read a byte from the DSP, using polling.
    998       1.1    brezak  */
    999       1.1    brezak int
   1000      1.31  christos sbdsp_rdsp(sc)
   1001      1.31  christos 	struct sbdsp_softc *sc;
   1002       1.1    brezak {
   1003      1.31  christos 	bus_space_tag_t iot = sc->sc_iot;
   1004      1.31  christos 	bus_space_handle_t ioh = sc->sc_ioh;
   1005      1.52  augustss 	int i;
   1006      1.52  augustss 	u_char x;
   1007       1.1    brezak 
   1008       1.1    brezak 	for (i = SBDSP_NPOLL; --i >= 0; ) {
   1009      1.31  christos 		x = bus_space_read_1(iot, ioh, SBP_DSP_RSTAT);
   1010      1.15   mycroft 		delay(10);
   1011  1.63.2.3   thorpej 		if (x & SB_DSP_READY) {
   1012  1.63.2.3   thorpej 			x = bus_space_read_1(iot, ioh, SBP_DSP_READ);
   1013  1.63.2.3   thorpej 			delay(10);
   1014  1.63.2.3   thorpej 			return x;
   1015  1.63.2.3   thorpej 		}
   1016       1.1    brezak 	}
   1017       1.1    brezak 	++sberr.rdsp;
   1018       1.1    brezak 	return -1;
   1019       1.1    brezak }
   1020       1.1    brezak 
   1021       1.1    brezak /*
   1022       1.1    brezak  * Doing certain things (like toggling the speaker) make
   1023       1.1    brezak  * the SB hardware go away for a while, so pause a little.
   1024       1.1    brezak  */
   1025       1.1    brezak void
   1026       1.1    brezak sbdsp_to(arg)
   1027       1.1    brezak 	void *arg;
   1028       1.1    brezak {
   1029       1.1    brezak 	wakeup(arg);
   1030       1.1    brezak }
   1031       1.1    brezak 
   1032       1.1    brezak void
   1033       1.1    brezak sbdsp_pause(sc)
   1034       1.1    brezak 	struct sbdsp_softc *sc;
   1035       1.1    brezak {
   1036       1.1    brezak 	extern int hz;
   1037       1.1    brezak 
   1038       1.1    brezak 	timeout(sbdsp_to, sbdsp_to, hz/8);
   1039       1.5   mycroft 	(void)tsleep(sbdsp_to, PWAIT, "sbpause", 0);
   1040       1.1    brezak }
   1041       1.1    brezak 
   1042       1.1    brezak /*
   1043       1.1    brezak  * Turn on the speaker.  The SBK documention says this operation
   1044       1.1    brezak  * can take up to 1/10 of a second.  Higher level layers should
   1045       1.1    brezak  * probably let the task sleep for this amount of time after
   1046       1.1    brezak  * calling here.  Otherwise, things might not work (because
   1047       1.1    brezak  * sbdsp_wdsp() and sbdsp_rdsp() will probably timeout.)
   1048       1.1    brezak  *
   1049       1.1    brezak  * These engineers had their heads up their ass when
   1050       1.1    brezak  * they designed this card.
   1051       1.1    brezak  */
   1052       1.1    brezak void
   1053       1.1    brezak sbdsp_spkron(sc)
   1054       1.1    brezak 	struct sbdsp_softc *sc;
   1055       1.1    brezak {
   1056      1.31  christos 	(void)sbdsp_wdsp(sc, SB_DSP_SPKR_ON);
   1057       1.1    brezak 	sbdsp_pause(sc);
   1058       1.1    brezak }
   1059       1.1    brezak 
   1060       1.1    brezak /*
   1061       1.1    brezak  * Turn off the speaker; see comment above.
   1062       1.1    brezak  */
   1063       1.1    brezak void
   1064       1.1    brezak sbdsp_spkroff(sc)
   1065       1.1    brezak 	struct sbdsp_softc *sc;
   1066       1.1    brezak {
   1067      1.31  christos 	(void)sbdsp_wdsp(sc, SB_DSP_SPKR_OFF);
   1068       1.1    brezak 	sbdsp_pause(sc);
   1069       1.1    brezak }
   1070       1.1    brezak 
   1071       1.1    brezak /*
   1072      1.60  augustss  * Read the version number out of the card.
   1073      1.60  augustss  * Store version information in the softc.
   1074       1.1    brezak  */
   1075      1.52  augustss void
   1076       1.1    brezak sbversion(sc)
   1077       1.1    brezak 	struct sbdsp_softc *sc;
   1078       1.1    brezak {
   1079      1.52  augustss 	int v;
   1080       1.1    brezak 
   1081      1.52  augustss 	sc->sc_model = SB_UNK;
   1082      1.52  augustss 	sc->sc_version = 0;
   1083      1.31  christos 	if (sbdsp_wdsp(sc, SB_DSP_VERSION) < 0)
   1084      1.52  augustss 		return;
   1085      1.31  christos 	v = sbdsp_rdsp(sc) << 8;
   1086      1.31  christos 	v |= sbdsp_rdsp(sc);
   1087      1.52  augustss 	if (v < 0)
   1088      1.52  augustss 		return;
   1089      1.52  augustss 	sc->sc_version = v;
   1090      1.52  augustss 	switch(SBVER_MAJOR(v)) {
   1091      1.52  augustss 	case 1:
   1092      1.52  augustss 		sc->sc_mixer_model = SBM_NONE;
   1093      1.52  augustss 		sc->sc_model = SB_1;
   1094      1.52  augustss 		break;
   1095      1.52  augustss 	case 2:
   1096      1.52  augustss 		/* Some SB2 have a mixer, some don't. */
   1097      1.52  augustss 		sbdsp_mix_write(sc, SBP_1335_MASTER_VOL, 0x04);
   1098      1.52  augustss 		sbdsp_mix_write(sc, SBP_1335_MIDI_VOL,   0x06);
   1099      1.52  augustss 		/* Check if we can read back the mixer values. */
   1100      1.52  augustss 		if ((sbdsp_mix_read(sc, SBP_1335_MASTER_VOL) & 0x0e) == 0x04 &&
   1101      1.52  augustss 		    (sbdsp_mix_read(sc, SBP_1335_MIDI_VOL)   & 0x0e) == 0x06)
   1102      1.52  augustss 			sc->sc_mixer_model = SBM_CT1335;
   1103      1.52  augustss 		else
   1104      1.52  augustss 			sc->sc_mixer_model = SBM_NONE;
   1105      1.52  augustss 		if (SBVER_MINOR(v) == 0)
   1106      1.52  augustss 			sc->sc_model = SB_20;
   1107      1.52  augustss 		else
   1108      1.52  augustss 			sc->sc_model = SB_2x;
   1109      1.52  augustss 		break;
   1110      1.52  augustss 	case 3:
   1111      1.52  augustss 		sc->sc_mixer_model = SBM_CT1345;
   1112      1.52  augustss 		sc->sc_model = SB_PRO;
   1113      1.52  augustss 		break;
   1114      1.52  augustss 	case 4:
   1115  1.63.2.1   thorpej #if 0
   1116  1.63.2.1   thorpej /* XXX This does not work */
   1117  1.63.2.1   thorpej 		/* Most SB16 have a tone controls, but some don't. */
   1118  1.63.2.1   thorpej 		sbdsp_mix_write(sc, SB16P_TREBLE_L, 0x80);
   1119  1.63.2.1   thorpej 		/* Check if we can read back the mixer value. */
   1120  1.63.2.1   thorpej 		if ((sbdsp_mix_read(sc, SB16P_TREBLE_L) & 0xf0) == 0x80)
   1121  1.63.2.1   thorpej 			sc->sc_mixer_model = SBM_CT1745;
   1122  1.63.2.1   thorpej 		else
   1123  1.63.2.1   thorpej 			sc->sc_mixer_model = SBM_CT1XX5;
   1124  1.63.2.1   thorpej #else
   1125      1.52  augustss 		sc->sc_mixer_model = SBM_CT1745;
   1126  1.63.2.1   thorpej #endif
   1127  1.63.2.1   thorpej 		/* XXX what about SB_32 */
   1128  1.63.2.1   thorpej 		if (SBVER_MINOR(v) == 16)
   1129  1.63.2.1   thorpej 			sc->sc_model = SB_64;
   1130  1.63.2.1   thorpej 		else
   1131  1.63.2.1   thorpej 			sc->sc_model = SB_16;
   1132      1.52  augustss 		break;
   1133      1.52  augustss 	}
   1134       1.1    brezak }
   1135       1.1    brezak 
   1136       1.1    brezak /*
   1137       1.1    brezak  * Halt a DMA in progress.  A low-speed transfer can be
   1138       1.1    brezak  * resumed with sbdsp_contdma().
   1139       1.1    brezak  */
   1140       1.1    brezak int
   1141       1.1    brezak sbdsp_haltdma(addr)
   1142       1.5   mycroft 	void *addr;
   1143       1.1    brezak {
   1144      1.52  augustss 	struct sbdsp_softc *sc = addr;
   1145       1.1    brezak 
   1146      1.52  augustss 	DPRINTF(("sbdsp_haltdma: sc=%p\n", sc));
   1147       1.1    brezak 
   1148      1.15   mycroft 	sbdsp_reset(sc);
   1149      1.15   mycroft 	return 0;
   1150       1.1    brezak }
   1151       1.1    brezak 
   1152       1.1    brezak int
   1153       1.1    brezak sbdsp_contdma(addr)
   1154       1.5   mycroft 	void *addr;
   1155       1.1    brezak {
   1156      1.52  augustss 	struct sbdsp_softc *sc = addr;
   1157       1.1    brezak 
   1158      1.52  augustss 	DPRINTF(("sbdsp_contdma: sc=%p\n", sc));
   1159       1.1    brezak 
   1160       1.1    brezak 	/* XXX how do we reinitialize the DMA controller state?  do we care? */
   1161      1.31  christos 	(void)sbdsp_wdsp(sc, SB_DSP_CONT);
   1162      1.52  augustss 	return 0;
   1163       1.1    brezak }
   1164       1.1    brezak 
   1165       1.1    brezak int
   1166      1.52  augustss sbdsp_set_timeconst(sc, tc)
   1167      1.52  augustss 	struct sbdsp_softc *sc;
   1168       1.1    brezak 	int tc;
   1169       1.1    brezak {
   1170      1.52  augustss 	DPRINTF(("sbdsp_set_timeconst: sc=%p tc=%d\n", sc, tc));
   1171       1.1    brezak 
   1172      1.52  augustss 	if (sbdsp_wdsp(sc, SB_DSP_TIMECONST) < 0 ||
   1173      1.52  augustss 	    sbdsp_wdsp(sc, tc) < 0)
   1174      1.52  augustss 		return EIO;
   1175      1.52  augustss 
   1176      1.52  augustss 	return 0;
   1177       1.1    brezak }
   1178       1.1    brezak 
   1179       1.1    brezak int
   1180      1.52  augustss sbdsp16_set_rate(sc, cmd, rate)
   1181      1.52  augustss 	struct sbdsp_softc *sc;
   1182      1.52  augustss 	int cmd, rate;
   1183       1.1    brezak {
   1184  1.63.2.3   thorpej 	DPRINTF(("sbdsp16_set_rate: sc=%p cmd=0x%02x rate=%d\n", sc, cmd, rate));
   1185       1.1    brezak 
   1186      1.52  augustss 	if (sbdsp_wdsp(sc, cmd) < 0 ||
   1187      1.52  augustss 	    sbdsp_wdsp(sc, rate >> 8) < 0 ||
   1188      1.52  augustss 	    sbdsp_wdsp(sc, rate) < 0)
   1189      1.52  augustss 		return EIO;
   1190      1.52  augustss 	return 0;
   1191       1.1    brezak }
   1192       1.1    brezak 
   1193       1.1    brezak int
   1194      1.60  augustss sbdsp_dma_init_input(addr, buf, cc)
   1195      1.60  augustss 	void *addr;
   1196      1.60  augustss 	void *buf;
   1197      1.60  augustss 	int cc;
   1198      1.60  augustss {
   1199      1.60  augustss 	struct sbdsp_softc *sc = addr;
   1200      1.60  augustss 
   1201      1.60  augustss 	if (sc->sc_model == SB_1)
   1202      1.60  augustss 		return 0;
   1203  1.63.2.3   thorpej 	sc->sc_i.run = SB_DMARUNNING;
   1204      1.60  augustss 	DPRINTF(("sbdsp: dma start loop input addr=%p cc=%d chan=%d\n",
   1205  1.63.2.3   thorpej 		 buf, cc, sc->sc_i.dmachan));
   1206  1.63.2.3   thorpej 	isa_dmastart(sc->sc_isa, sc->sc_i.dmachan, buf,
   1207  1.63.2.3   thorpej 		     cc, NULL, DMAMODE_READ | DMAMODE_LOOP, BUS_DMA_NOWAIT);
   1208      1.60  augustss 	return 0;
   1209      1.60  augustss }
   1210      1.60  augustss 
   1211  1.63.2.3   thorpej static int
   1212  1.63.2.3   thorpej sbdsp_dma_setup_input(sc)
   1213  1.63.2.3   thorpej 	struct sbdsp_softc *sc;
   1214  1.63.2.3   thorpej {
   1215  1.63.2.3   thorpej 	int stereo = sc->sc_i.modep->channels == 2;
   1216  1.63.2.3   thorpej 	int filter;
   1217  1.63.2.3   thorpej 
   1218  1.63.2.3   thorpej 	/* Initialize the PCM */
   1219  1.63.2.3   thorpej 	if (ISSBPRO(sc)) {
   1220  1.63.2.3   thorpej 		if (sbdsp_wdsp(sc, sc->sc_i.modep->cmdchan) < 0)
   1221  1.63.2.3   thorpej 			return 0;
   1222  1.63.2.3   thorpej 		filter = stereo ? SBP_FILTER_OFF : sc->in_filter;
   1223  1.63.2.3   thorpej 		sbdsp_mix_write(sc, SBP_INFILTER,
   1224  1.63.2.3   thorpej 				(sbdsp_mix_read(sc, SBP_INFILTER) &
   1225  1.63.2.3   thorpej 				 ~SBP_IFILTER_MASK) | filter);
   1226  1.63.2.3   thorpej 	}
   1227  1.63.2.3   thorpej 
   1228  1.63.2.3   thorpej 	if (ISSB16CLASS(sc)) {
   1229  1.63.2.3   thorpej 		if (sbdsp16_set_rate(sc, SB_DSP16_INPUTRATE,
   1230  1.63.2.3   thorpej 				     sc->sc_i.rate)) {
   1231  1.63.2.3   thorpej 			DPRINTF(("sbdsp_dma_setup_input: rate=%d set failed\n",
   1232  1.63.2.3   thorpej 				 sc->sc_i.rate));
   1233  1.63.2.3   thorpej 			return 0;
   1234  1.63.2.3   thorpej 		}
   1235  1.63.2.3   thorpej 	} else {
   1236  1.63.2.3   thorpej 		if (sbdsp_set_timeconst(sc, sc->sc_i.tc)) {
   1237  1.63.2.3   thorpej 			DPRINTF(("sbdsp_dma_setup_input: tc=%d set failed\n",
   1238  1.63.2.3   thorpej 				 sc->sc_i.rate));
   1239  1.63.2.3   thorpej 			return 0;
   1240  1.63.2.3   thorpej 		}
   1241  1.63.2.3   thorpej 	}
   1242  1.63.2.3   thorpej 	return 1;
   1243  1.63.2.3   thorpej }
   1244  1.63.2.3   thorpej 
   1245      1.60  augustss int
   1246       1.1    brezak sbdsp_dma_input(addr, p, cc, intr, arg)
   1247       1.5   mycroft 	void *addr;
   1248       1.1    brezak 	void *p;
   1249       1.1    brezak 	int cc;
   1250      1.25  christos 	void (*intr) __P((void *));
   1251       1.1    brezak 	void *arg;
   1252       1.1    brezak {
   1253      1.52  augustss 	struct sbdsp_softc *sc = addr;
   1254       1.1    brezak 
   1255      1.12    brezak #ifdef AUDIO_DEBUG
   1256       1.1    brezak 	if (sbdspdebug > 1)
   1257  1.63.2.3   thorpej 		printf("sbdsp_dma_input: sc=%p buf=%p cc=%d intr=%p(%p)\n",
   1258  1.63.2.3   thorpej 		       addr, p, cc, intr, arg);
   1259       1.1    brezak #endif
   1260      1.52  augustss #ifdef DIAGNOSTIC
   1261  1.63.2.3   thorpej 	if (sc->sc_i.modep->channels == 2 && (cc & 1)) {
   1262      1.52  augustss 		DPRINTF(("stereo record odd bytes (%d)\n", cc));
   1263       1.1    brezak 		return EIO;
   1264       1.1    brezak 	}
   1265      1.52  augustss #endif
   1266      1.15   mycroft 
   1267  1.63.2.4   thorpej 	if (sc->sc_i.modep->precision == 8) {
   1268  1.63.2.4   thorpej #ifdef DIAGNOSTIC
   1269  1.63.2.4   thorpej 		if (sc->sc_i.dmachan != sc->sc_drq8) {
   1270  1.63.2.4   thorpej 			printf("sbdsp_dma_input: prec=%d bad chan %d\n",
   1271  1.63.2.4   thorpej 			       sc->sc_i.modep->precision, sc->sc_i.dmachan);
   1272  1.63.2.4   thorpej 			return EIO;
   1273  1.63.2.4   thorpej 		}
   1274  1.63.2.4   thorpej #endif
   1275  1.63.2.3   thorpej 		sc->sc_intr8 = intr;
   1276  1.63.2.3   thorpej 		sc->sc_arg8 = arg;
   1277      1.39   mycroft 	} else {
   1278  1.63.2.3   thorpej #ifdef DIAGNOSTIC
   1279  1.63.2.3   thorpej 		if (sc->sc_i.dmachan != sc->sc_drq16) {
   1280  1.63.2.4   thorpej 			printf("sbdsp_dma_input: prec=%d bad chan %d\n",
   1281  1.63.2.4   thorpej 			       sc->sc_i.modep->precision, sc->sc_i.dmachan);
   1282  1.63.2.3   thorpej 			return EIO;
   1283  1.63.2.3   thorpej 		}
   1284      1.53   mycroft #endif
   1285  1.63.2.3   thorpej 		sc->sc_intr16 = intr;
   1286  1.63.2.3   thorpej 		sc->sc_arg16 = arg;
   1287      1.60  augustss 	}
   1288  1.63.2.3   thorpej 
   1289  1.63.2.3   thorpej 	switch(sc->sc_i.run) {
   1290  1.63.2.3   thorpej 	case SB_NOTRUNNING:
   1291  1.63.2.3   thorpej 		/* Non-looping mode, not initialized */
   1292  1.63.2.3   thorpej 		sc->sc_i.run = SB_RUNNING;
   1293  1.63.2.3   thorpej 		if (!sbdsp_dma_setup_input(sc))
   1294  1.63.2.3   thorpej 			goto giveup;
   1295  1.63.2.3   thorpej 		/* fall into */
   1296  1.63.2.3   thorpej 	case SB_RUNNING:
   1297  1.63.2.3   thorpej 		/* Non-looping mode, start DMA */
   1298      1.60  augustss #ifdef AUDIO_DEBUG
   1299      1.60  augustss 		if (sbdspdebug > 2)
   1300  1.63.2.3   thorpej 			printf("sbdsp_dma_input: dmastart buf=%p cc=%d chan=%d\n",
   1301  1.63.2.3   thorpej 			       p, cc, sc->sc_i.dmachan);
   1302      1.60  augustss #endif
   1303  1.63.2.3   thorpej 		isa_dmastart(sc->sc_isa, sc->sc_i.dmachan, p,
   1304  1.63.2.3   thorpej 			     cc, NULL, DMAMODE_READ, BUS_DMA_NOWAIT);
   1305  1.63.2.3   thorpej 
   1306  1.63.2.3   thorpej 		/* Start PCM in non-looping mode */
   1307  1.63.2.3   thorpej 		if ((sc->sc_model == SB_JAZZ && sc->sc_i.dmachan > 3) ||
   1308  1.63.2.3   thorpej 		    (sc->sc_model != SB_JAZZ && sc->sc_i.modep->precision == 16))
   1309  1.63.2.3   thorpej 			cc >>= 1;
   1310  1.63.2.3   thorpej 		--cc;
   1311  1.63.2.3   thorpej 		if (sbdsp_wdsp(sc, sc->sc_i.modep->cmd) < 0 ||
   1312      1.31  christos 		    sbdsp_wdsp(sc, cc) < 0 ||
   1313      1.31  christos 		    sbdsp_wdsp(sc, cc >> 8) < 0) {
   1314  1.63.2.3   thorpej 			DPRINTF(("sbdsp_dma_input: SB1 DMA start failed\n"));
   1315      1.23   mycroft 			goto giveup;
   1316      1.23   mycroft 		}
   1317  1.63.2.3   thorpej 		break;
   1318  1.63.2.3   thorpej 	case SB_DMARUNNING:
   1319  1.63.2.3   thorpej 		/* Looping mode, not initialized */
   1320  1.63.2.3   thorpej 		sc->sc_i.run = SB_PCMRUNNING;
   1321  1.63.2.3   thorpej 		if (!sbdsp_dma_setup_input(sc))
   1322  1.63.2.3   thorpej 			goto giveup;
   1323  1.63.2.3   thorpej 		if ((sc->sc_model == SB_JAZZ && sc->sc_i.dmachan > 3) ||
   1324  1.63.2.3   thorpej 		    (sc->sc_model != SB_JAZZ && sc->sc_i.modep->precision == 16))
   1325  1.63.2.3   thorpej 			cc >>= 1;
   1326  1.63.2.3   thorpej 		--cc;
   1327  1.63.2.3   thorpej 		/* Initialize looping PCM */
   1328  1.63.2.3   thorpej 		if (ISSB16CLASS(sc)) {
   1329  1.63.2.3   thorpej #ifdef AUDIO_DEBUG
   1330  1.63.2.3   thorpej 			if (sbdspdebug > 2)
   1331  1.63.2.3   thorpej 				printf("sbdsp16 input command cmd=0x%02x bmode=0x%02x cc=%d\n",
   1332  1.63.2.3   thorpej 				       sc->sc_i.modep->cmd, sc->sc_i.bmode, cc);
   1333  1.63.2.3   thorpej #endif
   1334  1.63.2.3   thorpej 			if (sbdsp_wdsp(sc, sc->sc_i.modep->cmd) < 0 ||
   1335  1.63.2.3   thorpej 			    sbdsp_wdsp(sc, sc->sc_i.bmode) < 0 ||
   1336  1.63.2.3   thorpej 			    sbdsp_wdsp(sc, cc) < 0 ||
   1337  1.63.2.3   thorpej 			    sbdsp_wdsp(sc, cc >> 8) < 0) {
   1338  1.63.2.3   thorpej 				DPRINTF(("sbdsp_dma_input: SB16 DMA start failed\n"));
   1339  1.63.2.3   thorpej 				DPRINTF(("sbdsp16 input command cmd=0x%02x bmode=0x%02x cc=%d\n",
   1340  1.63.2.3   thorpej 					 sc->sc_i.modep->cmd, sc->sc_i.bmode, cc));
   1341  1.63.2.3   thorpej 				goto giveup;
   1342  1.63.2.3   thorpej 			}
   1343  1.63.2.3   thorpej 		} else {
   1344      1.53   mycroft 			DPRINTF(("sbdsp_dma_input: set blocksize=%d\n", cc));
   1345      1.31  christos 			if (sbdsp_wdsp(sc, SB_DSP_BLOCKSIZE) < 0 ||
   1346      1.31  christos 			    sbdsp_wdsp(sc, cc) < 0 ||
   1347      1.31  christos 			    sbdsp_wdsp(sc, cc >> 8) < 0) {
   1348      1.60  augustss 				DPRINTF(("sbdsp_dma_input: SB2 DMA blocksize failed\n"));
   1349       1.1    brezak 				goto giveup;
   1350      1.15   mycroft 			}
   1351  1.63.2.3   thorpej 			if (sbdsp_wdsp(sc, sc->sc_i.modep->cmd) < 0) {
   1352      1.60  augustss 				DPRINTF(("sbdsp_dma_input: SB2 DMA start failed\n"));
   1353      1.53   mycroft 				goto giveup;
   1354      1.53   mycroft 			}
   1355      1.15   mycroft 		}
   1356  1.63.2.3   thorpej 		break;
   1357  1.63.2.3   thorpej 	case SB_PCMRUNNING:
   1358  1.63.2.3   thorpej 		/* Looping mode, nothing to do */
   1359  1.63.2.3   thorpej 		break;
   1360       1.1    brezak 	}
   1361       1.1    brezak 	return 0;
   1362       1.1    brezak 
   1363       1.1    brezak giveup:
   1364       1.1    brezak 	sbdsp_reset(sc);
   1365       1.1    brezak 	return EIO;
   1366       1.1    brezak }
   1367       1.1    brezak 
   1368       1.1    brezak int
   1369      1.60  augustss sbdsp_dma_init_output(addr, buf, cc)
   1370      1.60  augustss 	void *addr;
   1371      1.60  augustss 	void *buf;
   1372      1.60  augustss 	int cc;
   1373      1.60  augustss {
   1374      1.60  augustss 	struct sbdsp_softc *sc = addr;
   1375      1.60  augustss 
   1376      1.60  augustss 	if (sc->sc_model == SB_1)
   1377      1.60  augustss 		return 0;
   1378  1.63.2.3   thorpej 	sc->sc_o.run = SB_DMARUNNING;
   1379  1.63.2.3   thorpej 	DPRINTF(("sbdsp: dma start loop output buf=%p cc=%d chan=%d\n",
   1380  1.63.2.3   thorpej 		 buf, cc, sc->sc_o.dmachan));
   1381  1.63.2.3   thorpej 	isa_dmastart(sc->sc_isa, sc->sc_o.dmachan, buf,
   1382  1.63.2.3   thorpej 		     cc, NULL, DMAMODE_WRITE | DMAMODE_LOOP, BUS_DMA_NOWAIT);
   1383      1.60  augustss 	return 0;
   1384      1.60  augustss }
   1385      1.60  augustss 
   1386  1.63.2.3   thorpej static int
   1387  1.63.2.3   thorpej sbdsp_dma_setup_output(sc)
   1388  1.63.2.3   thorpej 	struct sbdsp_softc *sc;
   1389  1.63.2.3   thorpej {
   1390  1.63.2.3   thorpej 	int stereo = sc->sc_o.modep->channels == 2;
   1391  1.63.2.3   thorpej 	int cmd;
   1392  1.63.2.3   thorpej 
   1393  1.63.2.3   thorpej 	if (ISSBPRO(sc)) {
   1394  1.63.2.3   thorpej 		/* make sure we re-set stereo mixer bit when we start output. */
   1395  1.63.2.3   thorpej 		sbdsp_mix_write(sc, SBP_STEREO,
   1396  1.63.2.3   thorpej 				(sbdsp_mix_read(sc, SBP_STEREO) & ~SBP_PLAYMODE_MASK) |
   1397  1.63.2.3   thorpej 				(stereo ?  SBP_PLAYMODE_STEREO : SBP_PLAYMODE_MONO));
   1398  1.63.2.3   thorpej 		cmd = sc->sc_o.modep->cmdchan;
   1399  1.63.2.3   thorpej 		if (cmd && sbdsp_wdsp(sc, cmd) < 0)
   1400  1.63.2.3   thorpej 			return 0;
   1401  1.63.2.3   thorpej 	}
   1402  1.63.2.3   thorpej 
   1403  1.63.2.3   thorpej 	if (ISSB16CLASS(sc)) {
   1404  1.63.2.3   thorpej 		if (sbdsp16_set_rate(sc, SB_DSP16_OUTPUTRATE,
   1405  1.63.2.3   thorpej 				     sc->sc_o.rate)) {
   1406  1.63.2.3   thorpej 			DPRINTF(("sbdsp_dma_setup_output: rate=%d set failed\n",
   1407  1.63.2.3   thorpej 				 sc->sc_o.rate));
   1408  1.63.2.3   thorpej 			return 0;
   1409  1.63.2.3   thorpej 		}
   1410  1.63.2.3   thorpej 	} else {
   1411  1.63.2.3   thorpej 		if (sbdsp_set_timeconst(sc, sc->sc_o.tc)) {
   1412  1.63.2.3   thorpej 			DPRINTF(("sbdsp_dma_setup_output: tc=%d set failed\n",
   1413  1.63.2.3   thorpej 				 sc->sc_o.rate));
   1414  1.63.2.3   thorpej 			return 0;
   1415  1.63.2.3   thorpej 		}
   1416  1.63.2.3   thorpej 	}
   1417  1.63.2.3   thorpej 	return 1;
   1418  1.63.2.3   thorpej }
   1419  1.63.2.3   thorpej 
   1420      1.60  augustss int
   1421       1.1    brezak sbdsp_dma_output(addr, p, cc, intr, arg)
   1422       1.5   mycroft 	void *addr;
   1423       1.1    brezak 	void *p;
   1424       1.1    brezak 	int cc;
   1425      1.25  christos 	void (*intr) __P((void *));
   1426       1.1    brezak 	void *arg;
   1427       1.1    brezak {
   1428      1.52  augustss 	struct sbdsp_softc *sc = addr;
   1429       1.1    brezak 
   1430      1.12    brezak #ifdef AUDIO_DEBUG
   1431       1.1    brezak 	if (sbdspdebug > 1)
   1432  1.63.2.3   thorpej 		printf("sbdsp_dma_output: sc=%p buf=%p cc=%d intr=%p(%p)\n", addr, p, cc, intr, arg);
   1433       1.1    brezak #endif
   1434      1.52  augustss #ifdef DIAGNOSTIC
   1435  1.63.2.3   thorpej 	if (sc->sc_o.modep->channels == 2 && (cc & 1)) {
   1436       1.1    brezak 		DPRINTF(("stereo playback odd bytes (%d)\n", cc));
   1437       1.1    brezak 		return EIO;
   1438       1.1    brezak 	}
   1439      1.52  augustss #endif
   1440       1.1    brezak 
   1441  1.63.2.4   thorpej 	if (sc->sc_o.modep->precision == 8) {
   1442  1.63.2.4   thorpej #ifdef DIAGNOSTIC
   1443  1.63.2.4   thorpej 		if (sc->sc_o.dmachan != sc->sc_drq8) {
   1444  1.63.2.4   thorpej 			printf("sbdsp_dma_output: prec=%d bad chan %d\n",
   1445  1.63.2.4   thorpej 			       sc->sc_o.modep->precision, sc->sc_o.dmachan);
   1446  1.63.2.4   thorpej 			return EIO;
   1447  1.63.2.4   thorpej 		}
   1448  1.63.2.4   thorpej #endif
   1449  1.63.2.3   thorpej 		sc->sc_intr8 = intr;
   1450  1.63.2.3   thorpej 		sc->sc_arg8 = arg;
   1451      1.39   mycroft 	} else {
   1452  1.63.2.3   thorpej #ifdef DIAGNOSTIC
   1453  1.63.2.3   thorpej 		if (sc->sc_o.dmachan != sc->sc_drq16) {
   1454  1.63.2.4   thorpej 			printf("sbdsp_dma_output: prec=%d bad chan %d\n",
   1455  1.63.2.4   thorpej 			       sc->sc_o.modep->precision, sc->sc_o.dmachan);
   1456  1.63.2.3   thorpej 			return EIO;
   1457  1.63.2.3   thorpej 		}
   1458  1.63.2.3   thorpej #endif
   1459  1.63.2.3   thorpej 		sc->sc_intr16 = intr;
   1460  1.63.2.3   thorpej 		sc->sc_arg16 = arg;
   1461       1.1    brezak 	}
   1462      1.15   mycroft 
   1463  1.63.2.3   thorpej 	switch(sc->sc_o.run) {
   1464  1.63.2.3   thorpej 	case SB_NOTRUNNING:
   1465  1.63.2.3   thorpej 		/* Non-looping mode, not initialized */
   1466  1.63.2.3   thorpej 		sc->sc_o.run = SB_RUNNING;
   1467  1.63.2.3   thorpej 		if (!sbdsp_dma_setup_output(sc))
   1468  1.63.2.3   thorpej 			goto giveup;
   1469  1.63.2.3   thorpej 		/* fall into */
   1470  1.63.2.3   thorpej 	case SB_RUNNING:
   1471  1.63.2.3   thorpej 		/* Non-looping mode, initialized. Start DMA and PCM */
   1472      1.52  augustss #ifdef AUDIO_DEBUG
   1473  1.63.2.3   thorpej 		if (sbdspdebug > 2)
   1474  1.63.2.3   thorpej 			printf("sbdsp: start dma out addr=%p, cc=%d, chan=%d\n",
   1475  1.63.2.3   thorpej 			       p, cc, sc->sc_o.dmachan);
   1476      1.52  augustss #endif
   1477  1.63.2.3   thorpej 		isa_dmastart(sc->sc_isa, sc->sc_o.dmachan, p,
   1478  1.63.2.3   thorpej 			     cc, NULL, DMAMODE_WRITE, BUS_DMA_NOWAIT);
   1479  1.63.2.3   thorpej 		if ((sc->sc_model == SB_JAZZ && sc->sc_o.dmachan > 3) ||
   1480  1.63.2.3   thorpej 		    (sc->sc_model != SB_JAZZ && sc->sc_o.modep->precision == 16))
   1481  1.63.2.3   thorpej 			cc >>= 1;
   1482  1.63.2.3   thorpej 		--cc;
   1483  1.63.2.3   thorpej 		if (sbdsp_wdsp(sc, sc->sc_o.modep->cmd) < 0 ||
   1484      1.31  christos 		    sbdsp_wdsp(sc, cc) < 0 ||
   1485      1.31  christos 		    sbdsp_wdsp(sc, cc >> 8) < 0) {
   1486  1.63.2.3   thorpej 			DPRINTF(("sbdsp_dma_output: SB1 DMA start failed\n"));
   1487      1.23   mycroft 			goto giveup;
   1488      1.23   mycroft 		}
   1489  1.63.2.3   thorpej 		break;
   1490  1.63.2.3   thorpej 	case SB_DMARUNNING:
   1491  1.63.2.3   thorpej 		/* Looping mode, not initialized */
   1492  1.63.2.3   thorpej 		sc->sc_o.run = SB_PCMRUNNING;
   1493  1.63.2.3   thorpej 		if (!sbdsp_dma_setup_output(sc))
   1494  1.63.2.3   thorpej 			goto giveup;
   1495  1.63.2.3   thorpej 		if ((sc->sc_model == SB_JAZZ && sc->sc_o.dmachan > 3) ||
   1496  1.63.2.3   thorpej 		    (sc->sc_model != SB_JAZZ && sc->sc_o.modep->precision == 16))
   1497  1.63.2.3   thorpej 			cc >>= 1;
   1498  1.63.2.3   thorpej 		--cc;
   1499  1.63.2.3   thorpej 		/* Initialize looping PCM */
   1500  1.63.2.3   thorpej 		if (ISSB16CLASS(sc)) {
   1501  1.63.2.3   thorpej 			DPRINTF(("sbdsp_dma_output: SB16 cmd=0x%02x bmode=0x%02x cc=%d\n",
   1502  1.63.2.3   thorpej 				 sc->sc_o.modep->cmd,sc->sc_o.bmode, cc));
   1503  1.63.2.3   thorpej 			if (sbdsp_wdsp(sc, sc->sc_o.modep->cmd) < 0 ||
   1504  1.63.2.3   thorpej 			    sbdsp_wdsp(sc, sc->sc_o.bmode) < 0 ||
   1505  1.63.2.3   thorpej 			    sbdsp_wdsp(sc, cc) < 0 ||
   1506  1.63.2.3   thorpej 			    sbdsp_wdsp(sc, cc >> 8) < 0) {
   1507  1.63.2.3   thorpej 				DPRINTF(("sbdsp_dma_output: SB16 DMA start failed\n"));
   1508  1.63.2.3   thorpej 				goto giveup;
   1509  1.63.2.3   thorpej 			}
   1510  1.63.2.3   thorpej 		} else {
   1511      1.52  augustss 			DPRINTF(("sbdsp_dma_output: set blocksize=%d\n", cc));
   1512      1.31  christos 			if (sbdsp_wdsp(sc, SB_DSP_BLOCKSIZE) < 0 ||
   1513      1.31  christos 			    sbdsp_wdsp(sc, cc) < 0 ||
   1514      1.31  christos 			    sbdsp_wdsp(sc, cc >> 8) < 0) {
   1515      1.52  augustss 				DPRINTF(("sbdsp_dma_output: SB2 DMA blocksize failed\n"));
   1516      1.52  augustss 				goto giveup;
   1517      1.52  augustss 			}
   1518  1.63.2.3   thorpej 			if (sbdsp_wdsp(sc, sc->sc_o.modep->cmd) < 0) {
   1519      1.39   mycroft 				DPRINTF(("sbdsp_dma_output: SB2 DMA start failed\n"));
   1520       1.1    brezak 				goto giveup;
   1521       1.1    brezak 			}
   1522       1.1    brezak 		}
   1523  1.63.2.3   thorpej 		break;
   1524  1.63.2.3   thorpej 	case SB_PCMRUNNING:
   1525  1.63.2.3   thorpej 		/* Looping mode, nothing to do */
   1526  1.63.2.3   thorpej 		break;
   1527       1.1    brezak 	}
   1528       1.1    brezak 	return 0;
   1529       1.1    brezak 
   1530      1.15   mycroft giveup:
   1531       1.1    brezak 	sbdsp_reset(sc);
   1532       1.1    brezak 	return EIO;
   1533       1.1    brezak }
   1534       1.1    brezak 
   1535       1.1    brezak /*
   1536       1.1    brezak  * Only the DSP unit on the sound blaster generates interrupts.
   1537       1.1    brezak  * There are three cases of interrupt: reception of a midi byte
   1538       1.1    brezak  * (when mode is enabled), completion of dma transmission, or
   1539  1.63.2.3   thorpej  * completion of a dma reception.
   1540      1.60  augustss  *
   1541      1.60  augustss  * If there is interrupt sharing or a spurious interrupt occurs
   1542  1.63.2.3   thorpej  * there is no way to distinguish this on an SB2.  So if you have
   1543  1.63.2.3   thorpej  * an SB2 and experience problems, buy an SB16 (it's only $40).
   1544       1.1    brezak  */
   1545       1.1    brezak int
   1546       1.6       cgd sbdsp_intr(arg)
   1547       1.6       cgd 	void *arg;
   1548       1.1    brezak {
   1549      1.52  augustss 	struct sbdsp_softc *sc = arg;
   1550      1.52  augustss 	int loop = sc->sc_model != SB_1;
   1551      1.52  augustss 	u_char irq;
   1552       1.1    brezak 
   1553      1.12    brezak #ifdef AUDIO_DEBUG
   1554       1.1    brezak 	if (sbdspdebug > 1)
   1555  1.63.2.3   thorpej 		printf("sbdsp_intr: intr8=%p, intr16=%p\n",
   1556  1.63.2.3   thorpej 		       sc->sc_intr8, sc->sc_intr16);
   1557       1.1    brezak #endif
   1558      1.39   mycroft 	if (ISSB16CLASS(sc)) {
   1559      1.52  augustss 		irq = sbdsp_mix_read(sc, SBP_IRQ_STATUS);
   1560  1.63.2.3   thorpej 		if ((irq & (SBP_IRQ_DMA8 | SBP_IRQ_DMA16)) == 0) {
   1561  1.63.2.3   thorpej 			DPRINTF(("sbdsp_intr: Spurious interrupt 0x%x\n", irq));
   1562      1.39   mycroft 			return 0;
   1563  1.63.2.3   thorpej 		}
   1564      1.39   mycroft 	} else {
   1565  1.63.2.3   thorpej 		if (!loop && !isa_dmafinished(sc->sc_isa, sc->sc_drq8))
   1566      1.39   mycroft 			return 0;
   1567      1.52  augustss 		irq = SBP_IRQ_DMA8;
   1568      1.20   mycroft 	}
   1569       1.1    brezak 	sc->sc_interrupts++;
   1570      1.52  augustss 	delay(10);		/* XXX why? */
   1571       1.1    brezak #if 0
   1572       1.1    brezak 	if (sc->sc_mintr != 0) {
   1573      1.31  christos 		x = sbdsp_rdsp(sc);
   1574      1.15   mycroft 		(*sc->sc_mintr)(sc->sc_arg, x);
   1575       1.1    brezak 	} else
   1576       1.1    brezak #endif
   1577  1.63.2.3   thorpej 	if (sc->sc_intr8 == 0 && sc->sc_intr16 == 0) {
   1578  1.63.2.3   thorpej 		DPRINTF(("sbdsp_intr: Unexpected interrupt 0x%x\n", irq));
   1579  1.63.2.3   thorpej 		/* XXX return 0;*/	/* Did not expect an interrupt */
   1580  1.63.2.3   thorpej 	}
   1581  1.63.2.3   thorpej 
   1582  1.63.2.3   thorpej 	/* clear interrupt */
   1583  1.63.2.3   thorpej 	if (irq & SBP_IRQ_DMA8) {
   1584  1.63.2.3   thorpej 		bus_space_read_1(sc->sc_iot, sc->sc_ioh, SBP_DSP_IRQACK8);
   1585      1.52  augustss 		if (!loop)
   1586  1.63.2.3   thorpej 			isa_dmadone(sc->sc_isa, sc->sc_drq8);
   1587  1.63.2.3   thorpej 		if (sc->sc_intr8)
   1588  1.63.2.3   thorpej 			(*sc->sc_intr8)(sc->sc_arg8);
   1589  1.63.2.3   thorpej 	}
   1590  1.63.2.3   thorpej 	if (irq & SBP_IRQ_DMA16) {
   1591  1.63.2.3   thorpej 		bus_space_read_1(sc->sc_iot, sc->sc_ioh, SBP_DSP_IRQACK16);
   1592  1.63.2.3   thorpej 		if (sc->sc_intr16)
   1593  1.63.2.3   thorpej 			(*sc->sc_intr16)(sc->sc_arg16);
   1594       1.1    brezak 	}
   1595       1.1    brezak 	return 1;
   1596       1.1    brezak }
   1597       1.1    brezak 
   1598       1.1    brezak #if 0
   1599       1.1    brezak /*
   1600       1.1    brezak  * Enter midi uart mode and arrange for read interrupts
   1601       1.1    brezak  * to vector to `intr'.  This puts the card in a mode
   1602       1.1    brezak  * which allows only midi I/O; the card must be reset
   1603       1.1    brezak  * to leave this mode.  Unfortunately, the card does not
   1604       1.1    brezak  * use transmit interrupts, so bytes must be output
   1605       1.1    brezak  * using polling.  To keep the polling overhead to a
   1606       1.1    brezak  * minimum, output should be driven off a timer.
   1607       1.1    brezak  * This is a little tricky since only 320us separate
   1608       1.1    brezak  * consecutive midi bytes.
   1609       1.1    brezak  */
   1610       1.1    brezak void
   1611       1.1    brezak sbdsp_set_midi_mode(sc, intr, arg)
   1612       1.1    brezak 	struct sbdsp_softc *sc;
   1613       1.1    brezak 	void (*intr)();
   1614       1.1    brezak 	void *arg;
   1615       1.1    brezak {
   1616       1.1    brezak 
   1617      1.31  christos 	sbdsp_wdsp(sc, SB_MIDI_UART_INTR);
   1618       1.1    brezak 	sc->sc_mintr = intr;
   1619       1.1    brezak 	sc->sc_intr = 0;
   1620       1.1    brezak 	sc->sc_arg = arg;
   1621       1.1    brezak }
   1622       1.1    brezak 
   1623       1.1    brezak /*
   1624       1.1    brezak  * Write a byte to the midi port, when in midi uart mode.
   1625       1.1    brezak  */
   1626       1.1    brezak void
   1627       1.1    brezak sbdsp_midi_output(sc, v)
   1628       1.1    brezak 	struct sbdsp_softc *sc;
   1629       1.1    brezak 	int v;
   1630       1.1    brezak {
   1631       1.1    brezak 
   1632      1.31  christos 	if (sbdsp_wdsp(sc, v) < 0)
   1633       1.1    brezak 		++sberr.wmidi;
   1634       1.1    brezak }
   1635       1.1    brezak #endif
   1636       1.1    brezak 
   1637  1.63.2.1   thorpej /* Mask a value 0-255, but round it first */
   1638  1.63.2.1   thorpej #define MAXVAL 256
   1639  1.63.2.1   thorpej static int
   1640  1.63.2.1   thorpej sbdsp_adjust(val, mask)
   1641  1.63.2.1   thorpej 	int val, mask;
   1642  1.63.2.1   thorpej {
   1643  1.63.2.1   thorpej 	val += (MAXVAL - mask) >> 1;
   1644  1.63.2.1   thorpej 	if (val >= MAXVAL)
   1645  1.63.2.1   thorpej 		val = MAXVAL-1;
   1646  1.63.2.1   thorpej 	return val & mask;
   1647  1.63.2.1   thorpej }
   1648  1.63.2.1   thorpej 
   1649      1.50  augustss void
   1650      1.50  augustss sbdsp_set_mixer_gain(sc, port)
   1651      1.50  augustss 	struct sbdsp_softc *sc;
   1652      1.50  augustss 	int port;
   1653      1.50  augustss {
   1654      1.50  augustss 	int src, gain;
   1655      1.50  augustss 
   1656      1.50  augustss 	switch(sc->sc_mixer_model) {
   1657      1.50  augustss 	case SBM_NONE:
   1658      1.50  augustss 		return;
   1659      1.50  augustss 	case SBM_CT1335:
   1660      1.50  augustss 		gain = SB_1335_GAIN(sc->gain[port][SB_LEFT]);
   1661      1.50  augustss 		switch(port) {
   1662      1.50  augustss 		case SB_MASTER_VOL:
   1663      1.50  augustss 			src = SBP_1335_MASTER_VOL;
   1664      1.50  augustss 			break;
   1665      1.50  augustss 		case SB_MIDI_VOL:
   1666      1.50  augustss 			src = SBP_1335_MIDI_VOL;
   1667      1.50  augustss 			break;
   1668      1.50  augustss 		case SB_CD_VOL:
   1669      1.50  augustss 			src = SBP_1335_CD_VOL;
   1670      1.50  augustss 			break;
   1671      1.50  augustss 		case SB_VOICE_VOL:
   1672      1.50  augustss 			src = SBP_1335_VOICE_VOL;
   1673      1.50  augustss 			gain = SB_1335_MASTER_GAIN(sc->gain[port][SB_LEFT]);
   1674      1.50  augustss 			break;
   1675      1.50  augustss 		default:
   1676      1.50  augustss 			return;
   1677      1.50  augustss 		}
   1678      1.50  augustss 		sbdsp_mix_write(sc, src, gain);
   1679      1.50  augustss 		break;
   1680      1.50  augustss 	case SBM_CT1345:
   1681      1.50  augustss 		gain = SB_STEREO_GAIN(sc->gain[port][SB_LEFT],
   1682      1.50  augustss 				      sc->gain[port][SB_RIGHT]);
   1683      1.50  augustss 		switch (port) {
   1684      1.50  augustss 		case SB_MIC_VOL:
   1685      1.50  augustss 			src = SBP_MIC_VOL;
   1686      1.50  augustss 			gain = SB_MIC_GAIN(sc->gain[port][SB_LEFT]);
   1687      1.50  augustss 			break;
   1688      1.50  augustss 		case SB_MASTER_VOL:
   1689      1.50  augustss 			src = SBP_MASTER_VOL;
   1690      1.50  augustss 			break;
   1691      1.50  augustss 		case SB_LINE_IN_VOL:
   1692      1.50  augustss 			src = SBP_LINE_VOL;
   1693      1.50  augustss 			break;
   1694      1.50  augustss 		case SB_VOICE_VOL:
   1695      1.50  augustss 			src = SBP_VOICE_VOL;
   1696      1.50  augustss 			break;
   1697      1.50  augustss 		case SB_MIDI_VOL:
   1698      1.50  augustss 			src = SBP_MIDI_VOL;
   1699      1.50  augustss 			break;
   1700      1.50  augustss 		case SB_CD_VOL:
   1701      1.50  augustss 			src = SBP_CD_VOL;
   1702      1.50  augustss 			break;
   1703      1.50  augustss 		default:
   1704      1.50  augustss 			return;
   1705      1.50  augustss 		}
   1706      1.50  augustss 		sbdsp_mix_write(sc, src, gain);
   1707      1.50  augustss 		break;
   1708  1.63.2.1   thorpej 	case SBM_CT1XX5:
   1709      1.50  augustss 	case SBM_CT1745:
   1710      1.50  augustss 		switch (port) {
   1711      1.50  augustss 		case SB_MIC_VOL:
   1712      1.50  augustss 			src = SB16P_MIC_L;
   1713      1.50  augustss 			break;
   1714      1.50  augustss 		case SB_MASTER_VOL:
   1715      1.50  augustss 			src = SB16P_MASTER_L;
   1716      1.50  augustss 			break;
   1717      1.50  augustss 		case SB_LINE_IN_VOL:
   1718      1.50  augustss 			src = SB16P_LINE_L;
   1719      1.50  augustss 			break;
   1720      1.50  augustss 		case SB_VOICE_VOL:
   1721      1.50  augustss 			src = SB16P_VOICE_L;
   1722      1.50  augustss 			break;
   1723      1.50  augustss 		case SB_MIDI_VOL:
   1724      1.50  augustss 			src = SB16P_MIDI_L;
   1725      1.50  augustss 			break;
   1726      1.50  augustss 		case SB_CD_VOL:
   1727      1.50  augustss 			src = SB16P_CD_L;
   1728      1.50  augustss 			break;
   1729      1.50  augustss 		case SB_INPUT_GAIN:
   1730      1.50  augustss 			src = SB16P_INPUT_GAIN_L;
   1731      1.50  augustss 			break;
   1732      1.50  augustss 		case SB_OUTPUT_GAIN:
   1733      1.50  augustss 			src = SB16P_OUTPUT_GAIN_L;
   1734      1.50  augustss 			break;
   1735      1.50  augustss 		case SB_TREBLE:
   1736      1.50  augustss 			src = SB16P_TREBLE_L;
   1737      1.50  augustss 			break;
   1738      1.50  augustss 		case SB_BASS:
   1739      1.50  augustss 			src = SB16P_BASS_L;
   1740      1.50  augustss 			break;
   1741      1.50  augustss 		case SB_PCSPEAKER:
   1742      1.50  augustss 			sbdsp_mix_write(sc, SB16P_PCSPEAKER, sc->gain[port][SB_LEFT]);
   1743      1.50  augustss 			return;
   1744      1.50  augustss 		default:
   1745      1.50  augustss 			return;
   1746      1.50  augustss 		}
   1747      1.50  augustss 		sbdsp_mix_write(sc, src, sc->gain[port][SB_LEFT]);
   1748      1.50  augustss 		sbdsp_mix_write(sc, SB16P_L_TO_R(src), sc->gain[port][SB_RIGHT]);
   1749      1.50  augustss 		break;
   1750      1.50  augustss 	}
   1751      1.50  augustss }
   1752      1.50  augustss 
   1753       1.1    brezak int
   1754       1.1    brezak sbdsp_mixer_set_port(addr, cp)
   1755      1.18   mycroft 	void *addr;
   1756      1.18   mycroft 	mixer_ctrl_t *cp;
   1757       1.1    brezak {
   1758      1.52  augustss 	struct sbdsp_softc *sc = addr;
   1759      1.50  augustss 	int lgain, rgain;
   1760  1.63.2.2   thorpej 	int mask, bits;
   1761  1.63.2.2   thorpej 	int lmask, rmask, lbits, rbits;
   1762  1.63.2.2   thorpej 	int mute, swap;
   1763       1.1    brezak 
   1764      1.18   mycroft 	DPRINTF(("sbdsp_mixer_set_port: port=%d num_channels=%d\n", cp->dev,
   1765      1.18   mycroft 	    cp->un.value.num_channels));
   1766       1.1    brezak 
   1767      1.50  augustss 	if (sc->sc_mixer_model == SBM_NONE)
   1768      1.22   mycroft 		return EINVAL;
   1769      1.22   mycroft 
   1770      1.18   mycroft 	switch (cp->dev) {
   1771      1.50  augustss 	case SB_TREBLE:
   1772      1.50  augustss 	case SB_BASS:
   1773  1.63.2.1   thorpej 		if (sc->sc_mixer_model == SBM_CT1345 ||
   1774  1.63.2.1   thorpej                     sc->sc_mixer_model == SBM_CT1XX5) {
   1775      1.50  augustss 			if (cp->type != AUDIO_MIXER_ENUM)
   1776      1.50  augustss 				return EINVAL;
   1777      1.50  augustss 			switch (cp->dev) {
   1778      1.50  augustss 			case SB_TREBLE:
   1779      1.50  augustss 				sbdsp_set_ifilter(addr, cp->un.ord ? SB_TREBLE : 0);
   1780      1.50  augustss 				return 0;
   1781      1.50  augustss 			case SB_BASS:
   1782      1.50  augustss 				sbdsp_set_ifilter(addr, cp->un.ord ? SB_BASS : 0);
   1783      1.50  augustss 				return 0;
   1784      1.50  augustss 			}
   1785      1.50  augustss 		}
   1786      1.50  augustss 	case SB_PCSPEAKER:
   1787      1.50  augustss 	case SB_INPUT_GAIN:
   1788      1.50  augustss 	case SB_OUTPUT_GAIN:
   1789  1.63.2.1   thorpej 		if (!ISSBM1745(sc))
   1790      1.50  augustss 			return EINVAL;
   1791      1.50  augustss 	case SB_MIC_VOL:
   1792      1.50  augustss 	case SB_LINE_IN_VOL:
   1793      1.50  augustss 		if (sc->sc_mixer_model == SBM_CT1335)
   1794      1.50  augustss 			return EINVAL;
   1795      1.50  augustss 	case SB_VOICE_VOL:
   1796      1.50  augustss 	case SB_MIDI_VOL:
   1797      1.50  augustss 	case SB_CD_VOL:
   1798      1.18   mycroft 	case SB_MASTER_VOL:
   1799      1.18   mycroft 		if (cp->type != AUDIO_MIXER_VALUE)
   1800      1.18   mycroft 			return EINVAL;
   1801      1.18   mycroft 
   1802      1.18   mycroft 		/*
   1803      1.18   mycroft 		 * All the mixer ports are stereo except for the microphone.
   1804      1.18   mycroft 		 * If we get a single-channel gain value passed in, then we
   1805      1.18   mycroft 		 * duplicate it to both left and right channels.
   1806      1.18   mycroft 		 */
   1807      1.18   mycroft 
   1808      1.18   mycroft 		switch (cp->dev) {
   1809      1.50  augustss 		case SB_MIC_VOL:
   1810      1.18   mycroft 			if (cp->un.value.num_channels != 1)
   1811      1.18   mycroft 				return EINVAL;
   1812      1.18   mycroft 
   1813      1.50  augustss 			lgain = rgain = SB_ADJUST_MIC_GAIN(sc,
   1814      1.50  augustss 			  cp->un.value.level[AUDIO_MIXER_LEVEL_MONO]);
   1815      1.18   mycroft 			break;
   1816      1.50  augustss 		case SB_PCSPEAKER:
   1817      1.50  augustss 			if (cp->un.value.num_channels != 1)
   1818      1.50  augustss 				return EINVAL;
   1819      1.50  augustss 			/* fall into */
   1820      1.50  augustss 		case SB_INPUT_GAIN:
   1821      1.50  augustss 		case SB_OUTPUT_GAIN:
   1822      1.50  augustss 			lgain = rgain = SB_ADJUST_2_GAIN(sc,
   1823      1.50  augustss 			  cp->un.value.level[AUDIO_MIXER_LEVEL_MONO]);
   1824      1.50  augustss 			break;
   1825      1.50  augustss 		default:
   1826      1.18   mycroft 			switch (cp->un.value.num_channels) {
   1827      1.18   mycroft 			case 1:
   1828      1.50  augustss 				lgain = rgain = SB_ADJUST_GAIN(sc,
   1829      1.50  augustss 				  cp->un.value.level[AUDIO_MIXER_LEVEL_MONO]);
   1830      1.18   mycroft 				break;
   1831      1.18   mycroft 			case 2:
   1832      1.50  augustss 				if (sc->sc_mixer_model == SBM_CT1335)
   1833      1.50  augustss 					return EINVAL;
   1834      1.50  augustss 				lgain = SB_ADJUST_GAIN(sc,
   1835      1.50  augustss 				  cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT]);
   1836      1.50  augustss 				rgain = SB_ADJUST_GAIN(sc,
   1837      1.50  augustss 				  cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT]);
   1838      1.18   mycroft 				break;
   1839      1.18   mycroft 			default:
   1840      1.18   mycroft 				return EINVAL;
   1841      1.18   mycroft 			}
   1842      1.18   mycroft 			break;
   1843      1.18   mycroft 		}
   1844      1.50  augustss 		sc->gain[cp->dev][SB_LEFT]  = lgain;
   1845      1.50  augustss 		sc->gain[cp->dev][SB_RIGHT] = rgain;
   1846      1.18   mycroft 
   1847      1.50  augustss 		sbdsp_set_mixer_gain(sc, cp->dev);
   1848      1.18   mycroft 		break;
   1849      1.18   mycroft 
   1850       1.1    brezak 	case SB_RECORD_SOURCE:
   1851  1.63.2.1   thorpej 		if (ISSBM1745(sc)) {
   1852      1.50  augustss 			if (cp->type != AUDIO_MIXER_SET)
   1853      1.50  augustss 				return EINVAL;
   1854      1.50  augustss 			return sbdsp_set_in_ports(sc, cp->un.mask);
   1855      1.50  augustss 		} else {
   1856      1.50  augustss 			if (cp->type != AUDIO_MIXER_ENUM)
   1857      1.50  augustss 				return EINVAL;
   1858      1.50  augustss 			return sbdsp_set_in_port(sc, cp->un.ord);
   1859      1.18   mycroft 		}
   1860      1.50  augustss 		break;
   1861       1.1    brezak 
   1862      1.50  augustss 	case SB_AGC:
   1863  1.63.2.1   thorpej 		if (!ISSBM1745(sc) || cp->type != AUDIO_MIXER_ENUM)
   1864      1.50  augustss 			return EINVAL;
   1865      1.50  augustss 		sbdsp_mix_write(sc, SB16P_AGC, cp->un.ord & 1);
   1866      1.18   mycroft 		break;
   1867      1.22   mycroft 
   1868  1.63.2.2   thorpej 	case SB_CD_OUT_MUTE:
   1869  1.63.2.2   thorpej 		mask = SB16P_SW_CD;
   1870  1.63.2.2   thorpej 		goto omute;
   1871  1.63.2.2   thorpej 	case SB_MIC_OUT_MUTE:
   1872  1.63.2.2   thorpej 		mask = SB16P_SW_MIC;
   1873  1.63.2.2   thorpej 		goto omute;
   1874  1.63.2.2   thorpej 	case SB_LINE_OUT_MUTE:
   1875  1.63.2.2   thorpej 		mask = SB16P_SW_LINE;
   1876  1.63.2.2   thorpej 	omute:
   1877  1.63.2.2   thorpej 		if (cp->type != AUDIO_MIXER_ENUM)
   1878  1.63.2.2   thorpej 			return EINVAL;
   1879  1.63.2.2   thorpej 		bits = sbdsp_mix_read(sc, SB16P_OSWITCH);
   1880  1.63.2.2   thorpej 		sc->gain[cp->dev][SB_LR] = cp->un.ord != 0;
   1881  1.63.2.2   thorpej 		if (cp->un.ord)
   1882  1.63.2.2   thorpej 			bits = bits & ~mask;
   1883  1.63.2.2   thorpej 		else
   1884  1.63.2.2   thorpej 			bits = bits | mask;
   1885  1.63.2.2   thorpej 		sbdsp_mix_write(sc, SB16P_OSWITCH, bits);
   1886  1.63.2.2   thorpej 		break;
   1887  1.63.2.2   thorpej 
   1888  1.63.2.2   thorpej 	case SB_MIC_IN_MUTE:
   1889  1.63.2.2   thorpej 	case SB_MIC_SWAP:
   1890  1.63.2.2   thorpej 		lmask = rmask = SB16P_SW_MIC;
   1891  1.63.2.2   thorpej 		goto imute;
   1892  1.63.2.2   thorpej 	case SB_CD_IN_MUTE:
   1893  1.63.2.2   thorpej 	case SB_CD_SWAP:
   1894  1.63.2.2   thorpej 		lmask = SB16P_SW_CD_L;
   1895  1.63.2.2   thorpej 		rmask = SB16P_SW_CD_R;
   1896  1.63.2.2   thorpej 		goto imute;
   1897  1.63.2.2   thorpej 	case SB_LINE_IN_MUTE:
   1898  1.63.2.2   thorpej 	case SB_LINE_SWAP:
   1899  1.63.2.2   thorpej 		lmask = SB16P_SW_LINE_L;
   1900  1.63.2.2   thorpej 		rmask = SB16P_SW_LINE_R;
   1901  1.63.2.2   thorpej 		goto imute;
   1902  1.63.2.2   thorpej 	case SB_MIDI_IN_MUTE:
   1903  1.63.2.2   thorpej 	case SB_MIDI_SWAP:
   1904  1.63.2.2   thorpej 		lmask = SB16P_SW_MIDI_L;
   1905  1.63.2.2   thorpej 		rmask = SB16P_SW_MIDI_R;
   1906  1.63.2.2   thorpej 	imute:
   1907  1.63.2.2   thorpej 		if (cp->type != AUDIO_MIXER_ENUM)
   1908  1.63.2.2   thorpej 			return EINVAL;
   1909  1.63.2.2   thorpej 		mask = lmask | rmask;
   1910  1.63.2.2   thorpej 		lbits = sbdsp_mix_read(sc, SB16P_ISWITCH_L) & ~mask;
   1911  1.63.2.2   thorpej 		rbits = sbdsp_mix_read(sc, SB16P_ISWITCH_R) & ~mask;
   1912  1.63.2.2   thorpej 		sc->gain[cp->dev][SB_LR] = cp->un.ord != 0;
   1913  1.63.2.2   thorpej 		if (SB_IS_IN_MUTE(cp->dev)) {
   1914  1.63.2.2   thorpej 			mute = cp->dev;
   1915  1.63.2.2   thorpej 			swap = mute - SB_CD_IN_MUTE + SB_CD_SWAP;
   1916  1.63.2.2   thorpej 		} else {
   1917  1.63.2.2   thorpej 			swap = cp->dev;
   1918  1.63.2.2   thorpej 			mute = swap + SB_CD_IN_MUTE - SB_CD_SWAP;
   1919  1.63.2.2   thorpej 		}
   1920  1.63.2.2   thorpej 		if (sc->gain[swap][SB_LR]) {
   1921  1.63.2.2   thorpej 			mask = lmask;
   1922  1.63.2.2   thorpej 			lmask = rmask;
   1923  1.63.2.2   thorpej 			rmask = mask;
   1924  1.63.2.2   thorpej 		}
   1925  1.63.2.2   thorpej 		if (!sc->gain[mute][SB_LR]) {
   1926  1.63.2.2   thorpej 			lbits = lbits | lmask;
   1927  1.63.2.2   thorpej 			rbits = rbits | rmask;
   1928  1.63.2.2   thorpej 		}
   1929  1.63.2.2   thorpej 		sbdsp_mix_write(sc, SB16P_ISWITCH_L, lbits);
   1930  1.63.2.2   thorpej 		sbdsp_mix_write(sc, SB16P_ISWITCH_L, rbits);
   1931  1.63.2.2   thorpej 		break;
   1932  1.63.2.2   thorpej 
   1933      1.22   mycroft 	default:
   1934      1.22   mycroft 		return EINVAL;
   1935      1.18   mycroft 	}
   1936       1.1    brezak 
   1937      1.50  augustss 	return 0;
   1938       1.1    brezak }
   1939       1.1    brezak 
   1940       1.1    brezak int
   1941       1.1    brezak sbdsp_mixer_get_port(addr, cp)
   1942      1.18   mycroft 	void *addr;
   1943      1.18   mycroft 	mixer_ctrl_t *cp;
   1944       1.1    brezak {
   1945      1.52  augustss 	struct sbdsp_softc *sc = addr;
   1946       1.1    brezak 
   1947      1.48  augustss 	DPRINTF(("sbdsp_mixer_get_port: port=%d\n", cp->dev));
   1948       1.1    brezak 
   1949      1.50  augustss 	if (sc->sc_mixer_model == SBM_NONE)
   1950      1.22   mycroft 		return EINVAL;
   1951      1.22   mycroft 
   1952      1.18   mycroft 	switch (cp->dev) {
   1953      1.50  augustss 	case SB_TREBLE:
   1954      1.50  augustss 	case SB_BASS:
   1955  1.63.2.1   thorpej 		if (sc->sc_mixer_model == SBM_CT1345 ||
   1956  1.63.2.1   thorpej                     sc->sc_mixer_model == SBM_CT1XX5) {
   1957      1.50  augustss 			switch (cp->dev) {
   1958      1.50  augustss 			case SB_TREBLE:
   1959      1.50  augustss 				cp->un.ord = sbdsp_get_ifilter(addr) == SB_TREBLE;
   1960      1.50  augustss 				return 0;
   1961      1.50  augustss 			case SB_BASS:
   1962      1.50  augustss 				cp->un.ord = sbdsp_get_ifilter(addr) == SB_BASS;
   1963      1.50  augustss 				return 0;
   1964      1.50  augustss 			}
   1965      1.50  augustss 		}
   1966      1.50  augustss 	case SB_PCSPEAKER:
   1967      1.50  augustss 	case SB_INPUT_GAIN:
   1968      1.50  augustss 	case SB_OUTPUT_GAIN:
   1969  1.63.2.1   thorpej 		if (!ISSBM1745(sc))
   1970      1.50  augustss 			return EINVAL;
   1971      1.50  augustss 	case SB_MIC_VOL:
   1972      1.50  augustss 	case SB_LINE_IN_VOL:
   1973      1.50  augustss 		if (sc->sc_mixer_model == SBM_CT1335)
   1974      1.50  augustss 			return EINVAL;
   1975      1.50  augustss 	case SB_VOICE_VOL:
   1976      1.50  augustss 	case SB_MIDI_VOL:
   1977      1.50  augustss 	case SB_CD_VOL:
   1978      1.18   mycroft 	case SB_MASTER_VOL:
   1979      1.18   mycroft 		switch (cp->dev) {
   1980      1.50  augustss 		case SB_MIC_VOL:
   1981      1.50  augustss 		case SB_PCSPEAKER:
   1982      1.18   mycroft 			if (cp->un.value.num_channels != 1)
   1983      1.18   mycroft 				return EINVAL;
   1984      1.50  augustss 			/* fall into */
   1985      1.50  augustss 		default:
   1986      1.18   mycroft 			switch (cp->un.value.num_channels) {
   1987      1.18   mycroft 			case 1:
   1988      1.50  augustss 				cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] =
   1989      1.50  augustss 					sc->gain[cp->dev][SB_LEFT];
   1990      1.18   mycroft 				break;
   1991      1.18   mycroft 			case 2:
   1992      1.50  augustss 				cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT] =
   1993      1.50  augustss 					sc->gain[cp->dev][SB_LEFT];
   1994      1.50  augustss 				cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] =
   1995      1.50  augustss 					sc->gain[cp->dev][SB_RIGHT];
   1996      1.18   mycroft 				break;
   1997      1.18   mycroft 			default:
   1998      1.18   mycroft 				return EINVAL;
   1999      1.18   mycroft 			}
   2000      1.18   mycroft 			break;
   2001      1.18   mycroft 		}
   2002      1.22   mycroft 		break;
   2003      1.22   mycroft 
   2004      1.18   mycroft 	case SB_RECORD_SOURCE:
   2005  1.63.2.1   thorpej 		if (ISSBM1745(sc))
   2006      1.50  augustss 			cp->un.mask = sc->in_mask;
   2007      1.50  augustss 		else
   2008      1.50  augustss 			cp->un.ord = sc->in_port;
   2009      1.50  augustss 		break;
   2010      1.18   mycroft 
   2011      1.50  augustss 	case SB_AGC:
   2012  1.63.2.1   thorpej 		if (!ISSBM1745(sc))
   2013      1.50  augustss 			return EINVAL;
   2014      1.50  augustss 		cp->un.ord = sbdsp_mix_read(sc, SB16P_AGC);
   2015       1.1    brezak 		break;
   2016      1.22   mycroft 
   2017  1.63.2.2   thorpej 	case SB_CD_IN_MUTE:
   2018  1.63.2.2   thorpej 	case SB_MIC_IN_MUTE:
   2019  1.63.2.2   thorpej 	case SB_LINE_IN_MUTE:
   2020  1.63.2.2   thorpej 	case SB_MIDI_IN_MUTE:
   2021  1.63.2.2   thorpej 	case SB_CD_SWAP:
   2022  1.63.2.2   thorpej 	case SB_MIC_SWAP:
   2023  1.63.2.2   thorpej 	case SB_LINE_SWAP:
   2024  1.63.2.2   thorpej 	case SB_MIDI_SWAP:
   2025  1.63.2.2   thorpej 	case SB_CD_OUT_MUTE:
   2026  1.63.2.2   thorpej 	case SB_MIC_OUT_MUTE:
   2027  1.63.2.2   thorpej 	case SB_LINE_OUT_MUTE:
   2028  1.63.2.2   thorpej 		cp->un.ord = sc->gain[cp->dev][SB_LR];
   2029  1.63.2.2   thorpej 		break;
   2030  1.63.2.2   thorpej 
   2031      1.22   mycroft 	default:
   2032      1.22   mycroft 		return EINVAL;
   2033      1.18   mycroft 	}
   2034      1.18   mycroft 
   2035      1.52  augustss 	return 0;
   2036       1.1    brezak }
   2037       1.1    brezak 
   2038       1.1    brezak int
   2039       1.1    brezak sbdsp_mixer_query_devinfo(addr, dip)
   2040      1.18   mycroft 	void *addr;
   2041      1.50  augustss 	mixer_devinfo_t *dip;
   2042       1.1    brezak {
   2043      1.50  augustss 	struct sbdsp_softc *sc = addr;
   2044  1.63.2.2   thorpej 	int chan, class, is1745;
   2045      1.18   mycroft 
   2046      1.52  augustss 	DPRINTF(("sbdsp_mixer_query_devinfo: model=%d index=%d\n",
   2047      1.52  augustss 		 sc->sc_mixer_model, dip->index));
   2048      1.18   mycroft 
   2049      1.50  augustss 	if (sc->sc_mixer_model == SBM_NONE)
   2050      1.50  augustss 		return ENXIO;
   2051      1.50  augustss 
   2052      1.50  augustss 	chan = sc->sc_mixer_model == SBM_CT1335 ? 1 : 2;
   2053  1.63.2.2   thorpej 	is1745 = ISSBM1745(sc);
   2054  1.63.2.2   thorpej 	class = is1745 ? SB_INPUT_CLASS : SB_OUTPUT_CLASS;
   2055      1.50  augustss 
   2056      1.18   mycroft 	switch (dip->index) {
   2057      1.50  augustss 	case SB_MASTER_VOL:
   2058      1.18   mycroft 		dip->type = AUDIO_MIXER_VALUE;
   2059      1.50  augustss 		dip->mixer_class = SB_OUTPUT_CLASS;
   2060      1.50  augustss 		dip->prev = dip->next = AUDIO_MIXER_LAST;
   2061      1.50  augustss 		strcpy(dip->label.name, AudioNmaster);
   2062      1.50  augustss 		dip->un.v.num_channels = chan;
   2063      1.50  augustss 		strcpy(dip->un.v.units.name, AudioNvolume);
   2064      1.50  augustss 		return 0;
   2065      1.50  augustss 	case SB_MIDI_VOL:
   2066      1.50  augustss 		dip->type = AUDIO_MIXER_VALUE;
   2067      1.50  augustss 		dip->mixer_class = class;
   2068      1.18   mycroft 		dip->prev = AUDIO_MIXER_LAST;
   2069  1.63.2.2   thorpej 		dip->next = is1745 ? SB_MIDI_IN_MUTE : AUDIO_MIXER_LAST;
   2070      1.50  augustss 		strcpy(dip->label.name, AudioNfmsynth);
   2071      1.50  augustss 		dip->un.v.num_channels = chan;
   2072      1.18   mycroft 		strcpy(dip->un.v.units.name, AudioNvolume);
   2073      1.18   mycroft 		return 0;
   2074      1.50  augustss 	case SB_CD_VOL:
   2075      1.18   mycroft 		dip->type = AUDIO_MIXER_VALUE;
   2076      1.50  augustss 		dip->mixer_class = class;
   2077      1.18   mycroft 		dip->prev = AUDIO_MIXER_LAST;
   2078  1.63.2.2   thorpej 		dip->next = is1745 ? SB_CD_IN_MUTE : AUDIO_MIXER_LAST;
   2079      1.50  augustss 		strcpy(dip->label.name, AudioNcd);
   2080      1.50  augustss 		dip->un.v.num_channels = chan;
   2081      1.18   mycroft 		strcpy(dip->un.v.units.name, AudioNvolume);
   2082      1.18   mycroft 		return 0;
   2083      1.50  augustss 	case SB_VOICE_VOL:
   2084      1.50  augustss 		dip->type = AUDIO_MIXER_VALUE;
   2085      1.50  augustss 		dip->mixer_class = class;
   2086      1.50  augustss 		dip->prev = AUDIO_MIXER_LAST;
   2087      1.50  augustss 		dip->next = AUDIO_MIXER_LAST;
   2088      1.50  augustss 		strcpy(dip->label.name, AudioNdac);
   2089      1.50  augustss 		dip->un.v.num_channels = chan;
   2090      1.50  augustss 		strcpy(dip->un.v.units.name, AudioNvolume);
   2091      1.18   mycroft 		return 0;
   2092      1.18   mycroft 	case SB_OUTPUT_CLASS:
   2093      1.18   mycroft 		dip->type = AUDIO_MIXER_CLASS;
   2094      1.18   mycroft 		dip->mixer_class = SB_OUTPUT_CLASS;
   2095      1.18   mycroft 		dip->next = dip->prev = AUDIO_MIXER_LAST;
   2096      1.18   mycroft 		strcpy(dip->label.name, AudioCOutputs);
   2097      1.18   mycroft 		return 0;
   2098      1.18   mycroft 	}
   2099      1.18   mycroft 
   2100      1.50  augustss 	if (sc->sc_mixer_model == SBM_CT1335)
   2101      1.50  augustss 		return ENXIO;
   2102       1.1    brezak 
   2103      1.50  augustss 	switch (dip->index) {
   2104      1.50  augustss 	case SB_MIC_VOL:
   2105      1.50  augustss 		dip->type = AUDIO_MIXER_VALUE;
   2106      1.50  augustss 		dip->mixer_class = class;
   2107      1.50  augustss 		dip->prev = AUDIO_MIXER_LAST;
   2108  1.63.2.2   thorpej 		dip->next = is1745 ? SB_MIC_IN_MUTE : AUDIO_MIXER_LAST;
   2109      1.50  augustss 		strcpy(dip->label.name, AudioNmicrophone);
   2110      1.50  augustss 		dip->un.v.num_channels = 1;
   2111      1.50  augustss 		strcpy(dip->un.v.units.name, AudioNvolume);
   2112      1.50  augustss 		return 0;
   2113      1.17       jtk 
   2114      1.50  augustss 	case SB_LINE_IN_VOL:
   2115      1.50  augustss 		dip->type = AUDIO_MIXER_VALUE;
   2116      1.50  augustss 		dip->mixer_class = class;
   2117      1.50  augustss 		dip->prev = AUDIO_MIXER_LAST;
   2118  1.63.2.2   thorpej 		dip->next = is1745 ? SB_LINE_IN_MUTE : AUDIO_MIXER_LAST;
   2119      1.50  augustss 		strcpy(dip->label.name, AudioNline);
   2120      1.50  augustss 		dip->un.v.num_channels = 2;
   2121      1.50  augustss 		strcpy(dip->un.v.units.name, AudioNvolume);
   2122      1.50  augustss 		return 0;
   2123       1.1    brezak 
   2124      1.50  augustss 	case SB_RECORD_SOURCE:
   2125      1.50  augustss 		dip->mixer_class = SB_RECORD_CLASS;
   2126      1.50  augustss 		dip->prev = dip->next = AUDIO_MIXER_LAST;
   2127      1.50  augustss 		strcpy(dip->label.name, AudioNsource);
   2128  1.63.2.1   thorpej 		if (ISSBM1745(sc)) {
   2129      1.50  augustss 			dip->type = AUDIO_MIXER_SET;
   2130      1.50  augustss 			dip->un.s.num_mem = 4;
   2131      1.50  augustss 			strcpy(dip->un.s.member[0].label.name, AudioNmicrophone);
   2132      1.50  augustss 			dip->un.s.member[0].mask = 1 << SB_MIC_VOL;
   2133      1.50  augustss 			strcpy(dip->un.s.member[1].label.name, AudioNcd);
   2134      1.50  augustss 			dip->un.s.member[1].mask = 1 << SB_CD_VOL;
   2135      1.50  augustss 			strcpy(dip->un.s.member[2].label.name, AudioNline);
   2136      1.50  augustss 			dip->un.s.member[2].mask = 1 << SB_LINE_IN_VOL;
   2137      1.50  augustss 			strcpy(dip->un.s.member[3].label.name, AudioNfmsynth);
   2138      1.50  augustss 			dip->un.s.member[3].mask = 1 << SB_MIDI_VOL;
   2139      1.50  augustss 		} else {
   2140      1.18   mycroft 			dip->type = AUDIO_MIXER_ENUM;
   2141      1.18   mycroft 			dip->un.e.num_mem = 3;
   2142      1.18   mycroft 			strcpy(dip->un.e.member[0].label.name, AudioNmicrophone);
   2143      1.50  augustss 			dip->un.e.member[0].ord = SB_MIC_VOL;
   2144      1.18   mycroft 			strcpy(dip->un.e.member[1].label.name, AudioNcd);
   2145      1.50  augustss 			dip->un.e.member[1].ord = SB_CD_VOL;
   2146      1.18   mycroft 			strcpy(dip->un.e.member[2].label.name, AudioNline);
   2147      1.50  augustss 			dip->un.e.member[2].ord = SB_LINE_IN_VOL;
   2148      1.50  augustss 		}
   2149      1.50  augustss 		return 0;
   2150      1.18   mycroft 
   2151      1.50  augustss 	case SB_BASS:
   2152      1.50  augustss 		dip->prev = dip->next = AUDIO_MIXER_LAST;
   2153      1.50  augustss 		strcpy(dip->label.name, AudioNbass);
   2154      1.51  augustss 		if (sc->sc_mixer_model == SBM_CT1745) {
   2155      1.50  augustss 			dip->type = AUDIO_MIXER_VALUE;
   2156      1.50  augustss 			dip->mixer_class = SB_EQUALIZATION_CLASS;
   2157      1.50  augustss 			dip->un.v.num_channels = 2;
   2158      1.50  augustss 			strcpy(dip->un.v.units.name, AudioNbass);
   2159      1.50  augustss 		} else {
   2160      1.18   mycroft 			dip->type = AUDIO_MIXER_ENUM;
   2161      1.18   mycroft 			dip->mixer_class = SB_INPUT_CLASS;
   2162      1.18   mycroft 			dip->un.e.num_mem = 2;
   2163      1.18   mycroft 			strcpy(dip->un.e.member[0].label.name, AudioNoff);
   2164      1.18   mycroft 			dip->un.e.member[0].ord = 0;
   2165      1.18   mycroft 			strcpy(dip->un.e.member[1].label.name, AudioNon);
   2166      1.18   mycroft 			dip->un.e.member[1].ord = 1;
   2167      1.50  augustss 		}
   2168      1.50  augustss 		return 0;
   2169      1.50  augustss 
   2170      1.50  augustss 	case SB_TREBLE:
   2171      1.50  augustss 		dip->prev = dip->next = AUDIO_MIXER_LAST;
   2172      1.50  augustss 		strcpy(dip->label.name, AudioNtreble);
   2173      1.51  augustss 		if (sc->sc_mixer_model == SBM_CT1745) {
   2174      1.50  augustss 			dip->type = AUDIO_MIXER_VALUE;
   2175      1.50  augustss 			dip->mixer_class = SB_EQUALIZATION_CLASS;
   2176      1.50  augustss 			dip->un.v.num_channels = 2;
   2177      1.50  augustss 			strcpy(dip->un.v.units.name, AudioNtreble);
   2178      1.50  augustss 		} else {
   2179      1.18   mycroft 			dip->type = AUDIO_MIXER_ENUM;
   2180      1.18   mycroft 			dip->mixer_class = SB_INPUT_CLASS;
   2181      1.18   mycroft 			dip->un.e.num_mem = 2;
   2182      1.18   mycroft 			strcpy(dip->un.e.member[0].label.name, AudioNoff);
   2183      1.18   mycroft 			dip->un.e.member[0].ord = 0;
   2184      1.18   mycroft 			strcpy(dip->un.e.member[1].label.name, AudioNon);
   2185      1.18   mycroft 			dip->un.e.member[1].ord = 1;
   2186      1.50  augustss 		}
   2187      1.50  augustss 		return 0;
   2188      1.50  augustss 
   2189      1.50  augustss 	case SB_RECORD_CLASS:			/* record source class */
   2190      1.50  augustss 		dip->type = AUDIO_MIXER_CLASS;
   2191      1.50  augustss 		dip->mixer_class = SB_RECORD_CLASS;
   2192      1.50  augustss 		dip->next = dip->prev = AUDIO_MIXER_LAST;
   2193      1.50  augustss 		strcpy(dip->label.name, AudioCRecord);
   2194      1.50  augustss 		return 0;
   2195      1.50  augustss 
   2196      1.50  augustss 	}
   2197      1.50  augustss 
   2198      1.50  augustss 	if (sc->sc_mixer_model == SBM_CT1345)
   2199      1.50  augustss 		return ENXIO;
   2200      1.50  augustss 
   2201      1.50  augustss 	switch(dip->index) {
   2202      1.50  augustss 	case SB_PCSPEAKER:
   2203      1.50  augustss 		dip->type = AUDIO_MIXER_VALUE;
   2204      1.50  augustss 		dip->mixer_class = SB_INPUT_CLASS;
   2205      1.50  augustss 		dip->prev = dip->next = AUDIO_MIXER_LAST;
   2206      1.50  augustss 		strcpy(dip->label.name, "pc_speaker");
   2207      1.50  augustss 		dip->un.v.num_channels = 1;
   2208      1.50  augustss 		strcpy(dip->un.v.units.name, AudioNvolume);
   2209      1.50  augustss 		return 0;
   2210      1.50  augustss 
   2211      1.50  augustss 	case SB_INPUT_GAIN:
   2212      1.50  augustss 		dip->type = AUDIO_MIXER_VALUE;
   2213      1.50  augustss 		dip->mixer_class = SB_INPUT_CLASS;
   2214      1.50  augustss 		dip->prev = dip->next = AUDIO_MIXER_LAST;
   2215      1.50  augustss 		strcpy(dip->label.name, AudioNinput);
   2216      1.50  augustss 		dip->un.v.num_channels = 2;
   2217      1.50  augustss 		strcpy(dip->un.v.units.name, AudioNvolume);
   2218      1.50  augustss 		return 0;
   2219      1.50  augustss 
   2220      1.50  augustss 	case SB_OUTPUT_GAIN:
   2221      1.50  augustss 		dip->type = AUDIO_MIXER_VALUE;
   2222      1.50  augustss 		dip->mixer_class = SB_OUTPUT_CLASS;
   2223      1.50  augustss 		dip->prev = dip->next = AUDIO_MIXER_LAST;
   2224      1.50  augustss 		strcpy(dip->label.name, AudioNoutput);
   2225      1.50  augustss 		dip->un.v.num_channels = 2;
   2226      1.50  augustss 		strcpy(dip->un.v.units.name, AudioNvolume);
   2227      1.50  augustss 		return 0;
   2228      1.50  augustss 
   2229      1.50  augustss 	case SB_AGC:
   2230      1.50  augustss 		dip->type = AUDIO_MIXER_ENUM;
   2231      1.50  augustss 		dip->mixer_class = SB_INPUT_CLASS;
   2232      1.50  augustss 		dip->prev = dip->next = AUDIO_MIXER_LAST;
   2233      1.50  augustss 		strcpy(dip->label.name, "AGC");
   2234      1.50  augustss 		dip->un.e.num_mem = 2;
   2235      1.50  augustss 		strcpy(dip->un.e.member[0].label.name, AudioNoff);
   2236      1.50  augustss 		dip->un.e.member[0].ord = 0;
   2237      1.50  augustss 		strcpy(dip->un.e.member[1].label.name, AudioNon);
   2238      1.50  augustss 		dip->un.e.member[1].ord = 1;
   2239      1.50  augustss 		return 0;
   2240      1.50  augustss 
   2241      1.50  augustss 	case SB_INPUT_CLASS:
   2242      1.50  augustss 		dip->type = AUDIO_MIXER_CLASS;
   2243      1.50  augustss 		dip->mixer_class = SB_INPUT_CLASS;
   2244      1.50  augustss 		dip->next = dip->prev = AUDIO_MIXER_LAST;
   2245      1.50  augustss 		strcpy(dip->label.name, AudioCInputs);
   2246      1.50  augustss 		return 0;
   2247      1.18   mycroft 
   2248      1.50  augustss 	case SB_EQUALIZATION_CLASS:
   2249      1.50  augustss 		dip->type = AUDIO_MIXER_CLASS;
   2250      1.50  augustss 		dip->mixer_class = SB_EQUALIZATION_CLASS;
   2251      1.50  augustss 		dip->next = dip->prev = AUDIO_MIXER_LAST;
   2252      1.50  augustss 		strcpy(dip->label.name, AudioCEqualization);
   2253      1.50  augustss 		return 0;
   2254  1.63.2.2   thorpej 
   2255  1.63.2.2   thorpej 	case SB_CD_IN_MUTE:
   2256  1.63.2.2   thorpej 		dip->prev = SB_CD_VOL;
   2257  1.63.2.2   thorpej 		dip->next = SB_CD_SWAP;
   2258  1.63.2.2   thorpej 		dip->mixer_class = SB_INPUT_CLASS;
   2259  1.63.2.2   thorpej 		goto mute;
   2260  1.63.2.2   thorpej 
   2261  1.63.2.2   thorpej 	case SB_MIC_IN_MUTE:
   2262  1.63.2.2   thorpej 		dip->prev = SB_MIC_VOL;
   2263  1.63.2.2   thorpej 		dip->next = SB_MIC_SWAP;
   2264  1.63.2.2   thorpej 		dip->mixer_class = SB_INPUT_CLASS;
   2265  1.63.2.2   thorpej 		goto mute;
   2266  1.63.2.2   thorpej 
   2267  1.63.2.2   thorpej 	case SB_LINE_IN_MUTE:
   2268  1.63.2.2   thorpej 		dip->prev = SB_LINE_IN_VOL;
   2269  1.63.2.2   thorpej 		dip->next = SB_LINE_SWAP;
   2270  1.63.2.2   thorpej 		dip->mixer_class = SB_INPUT_CLASS;
   2271  1.63.2.2   thorpej 		goto mute;
   2272  1.63.2.2   thorpej 
   2273  1.63.2.2   thorpej 	case SB_MIDI_IN_MUTE:
   2274  1.63.2.2   thorpej 		dip->prev = SB_MIDI_VOL;
   2275  1.63.2.2   thorpej 		dip->next = SB_MIDI_SWAP;
   2276  1.63.2.2   thorpej 		dip->mixer_class = SB_INPUT_CLASS;
   2277  1.63.2.2   thorpej 		goto mute;
   2278  1.63.2.2   thorpej 
   2279  1.63.2.2   thorpej 	case SB_CD_SWAP:
   2280  1.63.2.2   thorpej 		dip->prev = SB_CD_IN_MUTE;
   2281  1.63.2.2   thorpej 		dip->next = SB_CD_OUT_MUTE;
   2282  1.63.2.2   thorpej 		goto swap;
   2283  1.63.2.2   thorpej 
   2284  1.63.2.2   thorpej 	case SB_MIC_SWAP:
   2285  1.63.2.2   thorpej 		dip->prev = SB_MIC_IN_MUTE;
   2286  1.63.2.2   thorpej 		dip->next = SB_MIC_OUT_MUTE;
   2287  1.63.2.2   thorpej 		goto swap;
   2288  1.63.2.2   thorpej 
   2289  1.63.2.2   thorpej 	case SB_LINE_SWAP:
   2290  1.63.2.2   thorpej 		dip->prev = SB_LINE_IN_MUTE;
   2291  1.63.2.2   thorpej 		dip->next = SB_LINE_OUT_MUTE;
   2292  1.63.2.2   thorpej 		goto swap;
   2293  1.63.2.2   thorpej 
   2294  1.63.2.2   thorpej 	case SB_MIDI_SWAP:
   2295  1.63.2.2   thorpej 		dip->prev = SB_MIDI_IN_MUTE;
   2296  1.63.2.2   thorpej 		dip->next = AUDIO_MIXER_LAST;
   2297  1.63.2.2   thorpej 	swap:
   2298  1.63.2.2   thorpej 		dip->mixer_class = SB_INPUT_CLASS;
   2299  1.63.2.2   thorpej 		strcpy(dip->label.name, AudioNswap);
   2300  1.63.2.2   thorpej 		goto mute1;
   2301  1.63.2.2   thorpej 
   2302  1.63.2.2   thorpej 	case SB_CD_OUT_MUTE:
   2303  1.63.2.2   thorpej 		dip->prev = SB_CD_SWAP;
   2304  1.63.2.2   thorpej 		dip->next = AUDIO_MIXER_LAST;
   2305  1.63.2.2   thorpej 		dip->mixer_class = SB_OUTPUT_CLASS;
   2306  1.63.2.2   thorpej 		goto mute;
   2307  1.63.2.2   thorpej 
   2308  1.63.2.2   thorpej 	case SB_MIC_OUT_MUTE:
   2309  1.63.2.2   thorpej 		dip->prev = SB_MIC_SWAP;
   2310  1.63.2.2   thorpej 		dip->next = AUDIO_MIXER_LAST;
   2311  1.63.2.2   thorpej 		dip->mixer_class = SB_OUTPUT_CLASS;
   2312  1.63.2.2   thorpej 		goto mute;
   2313  1.63.2.2   thorpej 
   2314  1.63.2.2   thorpej 	case SB_LINE_OUT_MUTE:
   2315  1.63.2.2   thorpej 		dip->prev = SB_LINE_SWAP;
   2316  1.63.2.2   thorpej 		dip->next = AUDIO_MIXER_LAST;
   2317  1.63.2.2   thorpej 		dip->mixer_class = SB_OUTPUT_CLASS;
   2318  1.63.2.2   thorpej 	mute:
   2319  1.63.2.2   thorpej 		strcpy(dip->label.name, AudioNmute);
   2320  1.63.2.2   thorpej 	mute1:
   2321  1.63.2.2   thorpej 		dip->type = AUDIO_MIXER_ENUM;
   2322  1.63.2.2   thorpej 		dip->un.e.num_mem = 2;
   2323  1.63.2.2   thorpej 		strcpy(dip->un.e.member[0].label.name, AudioNoff);
   2324  1.63.2.2   thorpej 		dip->un.e.member[0].ord = 0;
   2325  1.63.2.2   thorpej 		strcpy(dip->un.e.member[1].label.name, AudioNon);
   2326  1.63.2.2   thorpej 		dip->un.e.member[1].ord = 1;
   2327  1.63.2.2   thorpej 		return 0;
   2328  1.63.2.2   thorpej 
   2329      1.18   mycroft 	}
   2330       1.1    brezak 
   2331      1.18   mycroft 	return ENXIO;
   2332      1.60  augustss }
   2333      1.60  augustss 
   2334      1.60  augustss void *
   2335      1.60  augustss sb_malloc(addr, size, pool, flags)
   2336      1.60  augustss 	void *addr;
   2337      1.60  augustss 	unsigned long size;
   2338      1.60  augustss 	int pool;
   2339      1.60  augustss 	int flags;
   2340      1.60  augustss {
   2341      1.60  augustss 	struct sbdsp_softc *sc = addr;
   2342      1.60  augustss 
   2343      1.60  augustss 	return isa_malloc(sc->sc_isa, 4, size, pool, flags);
   2344      1.60  augustss }
   2345      1.60  augustss 
   2346      1.60  augustss void
   2347      1.60  augustss sb_free(addr, ptr, pool)
   2348      1.60  augustss 	void *addr;
   2349      1.60  augustss 	void *ptr;
   2350      1.60  augustss 	int pool;
   2351      1.60  augustss {
   2352      1.60  augustss 	isa_free(ptr, pool);
   2353      1.60  augustss }
   2354      1.60  augustss 
   2355      1.60  augustss unsigned long
   2356      1.60  augustss sb_round(addr, size)
   2357      1.60  augustss 	void *addr;
   2358      1.60  augustss 	unsigned long size;
   2359      1.60  augustss {
   2360      1.60  augustss 	if (size > MAX_ISADMA)
   2361      1.60  augustss 		size = MAX_ISADMA;
   2362      1.60  augustss 	return size;
   2363      1.63  augustss }
   2364      1.63  augustss 
   2365      1.63  augustss int
   2366      1.63  augustss sb_mappage(addr, mem, off, prot)
   2367      1.63  augustss 	void *addr;
   2368      1.63  augustss         void *mem;
   2369      1.63  augustss         int off;
   2370      1.63  augustss 	int prot;
   2371      1.63  augustss {
   2372      1.63  augustss 	return isa_mappage(mem, off, prot);
   2373  1.63.2.1   thorpej }
   2374  1.63.2.1   thorpej 
   2375  1.63.2.1   thorpej int
   2376  1.63.2.1   thorpej sbdsp_get_props(addr)
   2377  1.63.2.1   thorpej 	void *addr;
   2378  1.63.2.1   thorpej {
   2379  1.63.2.3   thorpej 	struct sbdsp_softc *sc = addr;
   2380  1.63.2.3   thorpej 	return AUDIO_PROP_MMAP |
   2381  1.63.2.3   thorpej 	       (sc->sc_fullduplex ? AUDIO_PROP_FULLDUPLEX : 0);
   2382       1.1    brezak }
   2383