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