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