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