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