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