Home | History | Annotate | Line # | Download | only in isa
wss.c revision 1.45
      1 /*	$NetBSD: wss.c,v 1.45 1998/05/20 16:19:43 augustss Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1994 John Brezak
      5  * Copyright (c) 1991-1993 Regents of the University of California.
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *	This product includes software developed by the Computer Systems
     19  *	Engineering Group at Lawrence Berkeley Laboratory.
     20  * 4. Neither the name of the University nor of the Laboratory may be used
     21  *    to endorse or promote products derived from this software without
     22  *    specific prior written permission.
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  * SUCH DAMAGE.
     35  *
     36  */
     37 
     38 #include <sys/param.h>
     39 #include <sys/systm.h>
     40 #include <sys/errno.h>
     41 #include <sys/ioctl.h>
     42 #include <sys/syslog.h>
     43 #include <sys/device.h>
     44 #include <sys/proc.h>
     45 #include <sys/buf.h>
     46 
     47 #include <machine/cpu.h>
     48 #include <machine/intr.h>
     49 #include <machine/bus.h>
     50 
     51 #include <sys/audioio.h>
     52 #include <dev/audio_if.h>
     53 
     54 #include <dev/isa/isavar.h>
     55 #include <dev/isa/isadmavar.h>
     56 
     57 #include <dev/ic/ad1848reg.h>
     58 #include <dev/isa/ad1848var.h>
     59 #include <dev/isa/wssreg.h>
     60 #include <dev/isa/wssvar.h>
     61 #include <dev/isa/madreg.h>
     62 
     63 #ifdef AUDIO_DEBUG
     64 #define DPRINTF(x)	if (wssdebug) printf x
     65 int	wssdebug = 0;
     66 #else
     67 #define DPRINTF(x)
     68 #endif
     69 
     70 struct audio_device wss_device = {
     71 	"wss,ad1848",
     72 	"",
     73 	"WSS"
     74 };
     75 
     76 int	wss_getdev __P((void *, struct audio_device *));
     77 
     78 int	wss_mixer_set_port __P((void *, mixer_ctrl_t *));
     79 int	wss_mixer_get_port __P((void *, mixer_ctrl_t *));
     80 int	wss_query_devinfo __P((void *, mixer_devinfo_t *));
     81 
     82 /*
     83  * Define our interface to the higher level audio driver.
     84  */
     85 
     86 struct audio_hw_if wss_hw_if = {
     87 	ad1848_open,
     88 	ad1848_close,
     89 	NULL,
     90 	ad1848_query_encoding,
     91 	ad1848_set_params,
     92 	ad1848_round_blocksize,
     93 	ad1848_commit_settings,
     94 	ad1848_dma_init_output,
     95 	ad1848_dma_init_input,
     96 	ad1848_dma_output,
     97 	ad1848_dma_input,
     98 	ad1848_halt_out_dma,
     99 	ad1848_halt_in_dma,
    100 	NULL,
    101 	wss_getdev,
    102 	NULL,
    103 	wss_mixer_set_port,
    104 	wss_mixer_get_port,
    105 	wss_query_devinfo,
    106 	ad1848_malloc,
    107 	ad1848_free,
    108 	ad1848_round,
    109 	ad1848_mappage,
    110 	ad1848_get_props,
    111 };
    112 
    113 /*
    114  * Attach hardware to driver, attach hardware driver to audio
    115  * pseudo-device driver .
    116  */
    117 void
    118 wssattach(sc)
    119     struct wss_softc *sc;
    120 {
    121     int version;
    122 
    123     madattach(sc);
    124 
    125     sc->sc_ih = isa_intr_establish(sc->sc_ic, sc->wss_irq, IST_EDGE, IPL_AUDIO,
    126         ad1848_intr, &sc->sc_ad1848);
    127 
    128     ad1848_attach(&sc->sc_ad1848);
    129     printf(": %s", sc->sc_ad1848.chip_name);
    130 
    131     version = bus_space_read_1(sc->sc_iot, sc->sc_ioh, WSS_STATUS) & WSS_VERSMASK;
    132     printf(" (vers %d)", version);
    133     switch(sc->mad_chip_type) {
    134     case MAD_82C928:
    135 	printf(", 82C928");
    136 	break;
    137     case MAD_OTI601D:
    138 	printf(", OTI-601D");
    139 	break;
    140     case MAD_82C929:
    141 	printf(", 82C929");
    142 	break;
    143     case MAD_82C931:
    144 	printf(", 82C931");
    145 	break;
    146     default:
    147 	break;
    148     }
    149     printf("\n");
    150 
    151     sc->sc_ad1848.parent = sc;
    152 
    153     audio_attach_mi(&wss_hw_if, 0, &sc->sc_ad1848, &sc->sc_dev);
    154 }
    155 
    156 int
    157 wss_getdev(addr, retp)
    158     void *addr;
    159     struct audio_device *retp;
    160 {
    161     *retp = wss_device;
    162     return 0;
    163 }
    164 
    165 static ad1848_devmap_t mappings[] = {
    166 { WSS_MIC_IN_LVL, AD1848_KIND_LVL, AD1848_AUX2_CHANNEL },
    167 { WSS_LINE_IN_LVL, AD1848_KIND_LVL, AD1848_AUX1_CHANNEL },
    168 { WSS_DAC_LVL, AD1848_KIND_LVL, AD1848_DAC_CHANNEL },
    169 { WSS_MON_LVL, AD1848_KIND_LVL, AD1848_MONO_CHANNEL },
    170 { WSS_MIC_IN_MUTE, AD1848_KIND_MUTE, AD1848_AUX2_CHANNEL },
    171 { WSS_LINE_IN_MUTE, AD1848_KIND_MUTE, AD1848_AUX1_CHANNEL },
    172 { WSS_DAC_MUTE, AD1848_KIND_MUTE, AD1848_DAC_CHANNEL },
    173 { WSS_REC_LVL, AD1848_KIND_RECORDGAIN, -1 },
    174 { WSS_RECORD_SOURCE, AD1848_KIND_RECORDSOURCE, -1}
    175 };
    176 
    177 static int nummap = sizeof(mappings) / sizeof(mappings[0]);
    178 
    179 int
    180 wss_mixer_set_port(addr, cp)
    181     void *addr;
    182     mixer_ctrl_t *cp;
    183 {
    184     struct ad1848_softc *ac = addr;
    185 
    186     return (ad1848_mixer_set_port(ac, mappings, nummap, cp));
    187 }
    188 
    189 int
    190 wss_mixer_get_port(addr, cp)
    191     void *addr;
    192     mixer_ctrl_t *cp;
    193 {
    194     struct ad1848_softc *ac = addr;
    195 
    196     return (ad1848_mixer_get_port(ac, mappings, nummap, cp));
    197 }
    198 
    199 int
    200 wss_query_devinfo(addr, dip)
    201     void *addr;
    202     mixer_devinfo_t *dip;
    203 {
    204     DPRINTF(("wss_query_devinfo: index=%d\n", dip->index));
    205 
    206     switch(dip->index) {
    207     case WSS_MIC_IN_LVL:	/* Microphone */
    208 	dip->type = AUDIO_MIXER_VALUE;
    209 	dip->mixer_class = WSS_INPUT_CLASS;
    210 	dip->prev = AUDIO_MIXER_LAST;
    211 	dip->next = WSS_MIC_IN_MUTE;
    212 	strcpy(dip->label.name, AudioNmicrophone);
    213 	dip->un.v.num_channels = 2;
    214 	strcpy(dip->un.v.units.name, AudioNvolume);
    215 	break;
    216 
    217     case WSS_LINE_IN_LVL:	/* line/CD */
    218 	dip->type = AUDIO_MIXER_VALUE;
    219 	dip->mixer_class = WSS_INPUT_CLASS;
    220 	dip->prev = AUDIO_MIXER_LAST;
    221 	dip->next = WSS_LINE_IN_MUTE;
    222 	strcpy(dip->label.name, AudioNcd);
    223 	dip->un.v.num_channels = 2;
    224 	strcpy(dip->un.v.units.name, AudioNvolume);
    225 	break;
    226 
    227     case WSS_DAC_LVL:		/*  dacout */
    228 	dip->type = AUDIO_MIXER_VALUE;
    229 	dip->mixer_class = WSS_INPUT_CLASS;
    230 	dip->prev = AUDIO_MIXER_LAST;
    231 	dip->next = WSS_DAC_MUTE;
    232 	strcpy(dip->label.name, AudioNdac);
    233 	dip->un.v.num_channels = 2;
    234 	strcpy(dip->un.v.units.name, AudioNvolume);
    235 	break;
    236 
    237     case WSS_REC_LVL:	/* record level */
    238 	dip->type = AUDIO_MIXER_VALUE;
    239 	dip->mixer_class = WSS_RECORD_CLASS;
    240 	dip->prev = AUDIO_MIXER_LAST;
    241 	dip->next = WSS_RECORD_SOURCE;
    242 	strcpy(dip->label.name, AudioNrecord);
    243 	dip->un.v.num_channels = 2;
    244 	strcpy(dip->un.v.units.name, AudioNvolume);
    245 	break;
    246 
    247     case WSS_MON_LVL:	/* monitor level */
    248 	dip->type = AUDIO_MIXER_VALUE;
    249 	dip->mixer_class = WSS_MONITOR_CLASS;
    250 	dip->next = dip->prev = AUDIO_MIXER_LAST;
    251 	strcpy(dip->label.name, AudioNmonitor);
    252 	dip->un.v.num_channels = 1;
    253 	strcpy(dip->un.v.units.name, AudioNvolume);
    254 	break;
    255 
    256     case WSS_INPUT_CLASS:			/* input class descriptor */
    257 	dip->type = AUDIO_MIXER_CLASS;
    258 	dip->mixer_class = WSS_INPUT_CLASS;
    259 	dip->next = dip->prev = AUDIO_MIXER_LAST;
    260 	strcpy(dip->label.name, AudioCinputs);
    261 	break;
    262 
    263     case WSS_MONITOR_CLASS:			/* monitor class descriptor */
    264 	dip->type = AUDIO_MIXER_CLASS;
    265 	dip->mixer_class = WSS_MONITOR_CLASS;
    266 	dip->next = dip->prev = AUDIO_MIXER_LAST;
    267 	strcpy(dip->label.name, AudioCmonitor);
    268 	break;
    269 
    270     case WSS_RECORD_CLASS:			/* record source class */
    271 	dip->type = AUDIO_MIXER_CLASS;
    272 	dip->mixer_class = WSS_RECORD_CLASS;
    273 	dip->next = dip->prev = AUDIO_MIXER_LAST;
    274 	strcpy(dip->label.name, AudioCrecord);
    275 	break;
    276 
    277     case WSS_MIC_IN_MUTE:
    278 	dip->mixer_class = WSS_INPUT_CLASS;
    279 	dip->type = AUDIO_MIXER_ENUM;
    280 	dip->prev = WSS_MIC_IN_LVL;
    281 	dip->next = AUDIO_MIXER_LAST;
    282 	goto mute;
    283 
    284     case WSS_LINE_IN_MUTE:
    285 	dip->mixer_class = WSS_INPUT_CLASS;
    286 	dip->type = AUDIO_MIXER_ENUM;
    287 	dip->prev = WSS_LINE_IN_LVL;
    288 	dip->next = AUDIO_MIXER_LAST;
    289 	goto mute;
    290 
    291     case WSS_DAC_MUTE:
    292 	dip->mixer_class = WSS_INPUT_CLASS;
    293 	dip->type = AUDIO_MIXER_ENUM;
    294 	dip->prev = WSS_DAC_LVL;
    295 	dip->next = AUDIO_MIXER_LAST;
    296     mute:
    297 	strcpy(dip->label.name, AudioNmute);
    298 	dip->un.e.num_mem = 2;
    299 	strcpy(dip->un.e.member[0].label.name, AudioNoff);
    300 	dip->un.e.member[0].ord = 0;
    301 	strcpy(dip->un.e.member[1].label.name, AudioNon);
    302 	dip->un.e.member[1].ord = 1;
    303 	break;
    304 
    305     case WSS_RECORD_SOURCE:
    306 	dip->mixer_class = WSS_RECORD_CLASS;
    307 	dip->type = AUDIO_MIXER_ENUM;
    308 	dip->prev = WSS_REC_LVL;
    309 	dip->next = AUDIO_MIXER_LAST;
    310 	strcpy(dip->label.name, AudioNsource);
    311 	dip->un.e.num_mem = 3;
    312 	strcpy(dip->un.e.member[0].label.name, AudioNmicrophone);
    313 	dip->un.e.member[0].ord = WSS_MIC_IN_LVL;
    314 	strcpy(dip->un.e.member[1].label.name, AudioNcd);
    315 	dip->un.e.member[1].ord = WSS_LINE_IN_LVL;
    316 	strcpy(dip->un.e.member[2].label.name, AudioNdac);
    317 	dip->un.e.member[2].ord = WSS_DAC_LVL;
    318 	break;
    319 
    320     default:
    321 	return ENXIO;
    322 	/*NOTREACHED*/
    323     }
    324     DPRINTF(("AUDIO_MIXER_DEVINFO: name=%s\n", dip->label.name));
    325 
    326     return 0;
    327 }
    328 
    329 
    330 /*
    331  * Copyright by Hannu Savolainen 1994
    332  *
    333  * Redistribution and use in source and binary forms, with or without
    334  * modification, are permitted provided that the following conditions are
    335  * met: 1. Redistributions of source code must retain the above copyright
    336  * notice, this list of conditions and the following disclaimer. 2.
    337  * Redistributions in binary form must reproduce the above copyright notice,
    338  * this list of conditions and the following disclaimer in the documentation
    339  * and/or other materials provided with the distribution.
    340  *
    341  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
    342  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    343  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    344  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
    345  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    346  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    347  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
    348  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    349  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    350  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    351  * SUCH DAMAGE.
    352  *
    353  */
    354 /*
    355  * Initialization code for OPTi MAD16 compatible audio chips. Including
    356  *
    357  *      OPTi 82C928     MAD16           (replaced by C929)
    358  *      OAK OTI-601D    Mozart
    359  *      OPTi 82C929     MAD16 Pro
    360  *
    361  */
    362 
    363 u_int
    364 mad_read(sc, port)
    365     struct wss_softc *sc;
    366     int port;
    367 {
    368     u_int tmp;
    369     int pwd;
    370     int s;
    371 
    372     switch (sc->mad_chip_type) {	/* Output password */
    373     case MAD_82C928:
    374     case MAD_OTI601D:
    375 	pwd = M_PASSWD_928;
    376 	break;
    377     case MAD_82C929:
    378 	pwd = M_PASSWD_929;
    379 	break;
    380     case MAD_82C931:
    381 	pwd = M_PASSWD_931;
    382 	break;
    383     default:
    384 	panic("mad_read: Bad chip type=%d\n", sc->mad_chip_type);
    385     }
    386     s = splaudio();		/* don't want an interrupt between outb&inb */
    387     bus_space_write_1(sc->sc_iot, sc->mad_ioh, MC_PASSWD_REG, pwd);
    388     tmp = bus_space_read_1(sc->sc_iot, sc->mad_ioh, port);
    389     splx(s);
    390     return tmp;
    391 }
    392 
    393 void
    394 mad_write(sc, port, value)
    395     struct wss_softc *sc;
    396     int port;
    397     int value;
    398 {
    399     int pwd;
    400     int s;
    401 
    402     switch (sc->mad_chip_type) {	/* Output password */
    403     case MAD_82C928:
    404     case MAD_OTI601D:
    405 	pwd = M_PASSWD_928;
    406 	break;
    407     case MAD_82C929:
    408 	pwd = M_PASSWD_929;
    409 	break;
    410     case MAD_82C931:
    411 	pwd = M_PASSWD_931;
    412 	break;
    413     default:
    414 	panic("mad_write: Bad chip type=%d\n", sc->mad_chip_type);
    415     }
    416     s = splaudio();
    417     bus_space_write_1(sc->sc_iot, sc->mad_ioh, MC_PASSWD_REG, pwd);
    418     bus_space_write_1(sc->sc_iot, sc->mad_ioh, port, value & 0xff);
    419     splx(s);
    420 }
    421 
    422 void
    423 madattach(sc)
    424     struct wss_softc *sc;
    425 {
    426     unsigned char cs4231_mode;
    427     int joy;
    428 
    429     if (sc->mad_chip_type == MAD_NONE)
    430         return;
    431 
    432     /* Do we want the joystick disabled? */
    433     joy = sc->sc_dev.dv_cfdata->cf_flags & 2 ? MC1_JOYDISABLE : 0;
    434 
    435     /* enable WSS emulation at the I/O port */
    436     mad_write(sc, MC1_PORT, M_WSS_PORT_SELECT(sc->mad_ioindex) | joy);
    437     mad_write(sc, MC2_PORT, 0x03); /* ? */
    438     mad_write(sc, MC3_PORT, 0xf0); /* Disable SB */
    439 
    440     cs4231_mode =
    441 	strncmp(sc->sc_ad1848.chip_name, "CS4248", 6) == 0 ||
    442 	strncmp(sc->sc_ad1848.chip_name, "CS4231", 6) == 0 ? 0x02 : 0;
    443 
    444     if (sc->mad_chip_type == MAD_82C929) {
    445 	mad_write(sc, MC4_PORT, 0x92);
    446 	mad_write(sc, MC5_PORT, 0xA5 | cs4231_mode);
    447 	mad_write(sc, MC6_PORT, 0x03);	/* Disable MPU401 */
    448     } else {
    449 	mad_write(sc, MC4_PORT, 0x02);
    450 	mad_write(sc, MC5_PORT, 0x30 | cs4231_mode);
    451     }
    452 
    453 #ifdef AUDIO_DEBUG
    454     if (wssdebug) {
    455 	int i;
    456 	for (i = MC1_PORT; i <= MC7_PORT; i++)
    457 	    DPRINTF(("port %03x after init = %02x\n", i, mad_read(sc, i)));
    458     }
    459 #endif
    460 }
    461