xref: /netbsd-src/sys/dev/isapnp/ym_isapnp.c (revision e622eac459adf11c2e710d7a4de0f05510bbbe61)
1*e622eac4Sisaki /*	$NetBSD: ym_isapnp.c,v 1.26 2019/05/08 13:40:18 isaki Exp $ */
274545bafSaugustss 
374545bafSaugustss /*
474545bafSaugustss  * Copyright (c) 1991-1993 Regents of the University of California.
574545bafSaugustss  * All rights reserved.
674545bafSaugustss  *
774545bafSaugustss  * Redistribution and use in source and binary forms, with or without
874545bafSaugustss  * modification, are permitted provided that the following conditions
974545bafSaugustss  * are met:
1074545bafSaugustss  * 1. Redistributions of source code must retain the above copyright
1174545bafSaugustss  *    notice, this list of conditions and the following disclaimer.
1274545bafSaugustss  * 2. Redistributions in binary form must reproduce the above copyright
1374545bafSaugustss  *    notice, this list of conditions and the following disclaimer in the
1474545bafSaugustss  *    documentation and/or other materials provided with the distribution.
1574545bafSaugustss  * 3. All advertising materials mentioning features or use of this software
1674545bafSaugustss  *    must display the following acknowledgement:
1774545bafSaugustss  *	This product includes software developed by the Computer Systems
1874545bafSaugustss  *	Engineering Group at Lawrence Berkeley Laboratory.
1974545bafSaugustss  * 4. Neither the name of the University nor of the Laboratory may be used
2074545bafSaugustss  *    to endorse or promote products derived from this software without
2174545bafSaugustss  *    specific prior written permission.
2274545bafSaugustss  *
2374545bafSaugustss  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2474545bafSaugustss  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2574545bafSaugustss  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2674545bafSaugustss  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2774545bafSaugustss  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2874545bafSaugustss  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2974545bafSaugustss  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3074545bafSaugustss  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3174545bafSaugustss  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3274545bafSaugustss  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3374545bafSaugustss  * SUCH DAMAGE.
3474545bafSaugustss  *
3574545bafSaugustss  */
3674545bafSaugustss 
3774545bafSaugustss /*
3874545bafSaugustss  *  Driver for the Yamaha OPL3-SA3 chipset. This is found on many laptops
3974545bafSaugustss  *  and Pentium (II) motherboards.
4074545bafSaugustss  *
4174545bafSaugustss  *  Original code from OpenBSD.
4274545bafSaugustss  */
4374545bafSaugustss 
449d2580ffSlukem #include <sys/cdefs.h>
45*e622eac4Sisaki __KERNEL_RCSID(0, "$NetBSD: ym_isapnp.c,v 1.26 2019/05/08 13:40:18 isaki Exp $");
469d2580ffSlukem 
471fa31472Sitohy #include "mpu_ym.h"
481fa31472Sitohy 
4974545bafSaugustss #include <sys/param.h>
5074545bafSaugustss #include <sys/systm.h>
5174545bafSaugustss #include <sys/device.h>
52f7151935Spk #include <sys/errno.h>
5374545bafSaugustss 
5474545bafSaugustss #include <sys/audioio.h>
55*e622eac4Sisaki #include <dev/audio/audio_if.h>
5674545bafSaugustss 
5774545bafSaugustss #include <dev/isa/isavar.h>
5874545bafSaugustss #include <dev/isa/isadmavar.h>
5974545bafSaugustss 
6074545bafSaugustss #include <dev/isapnp/isapnpreg.h>
6174545bafSaugustss #include <dev/isapnp/isapnpvar.h>
62bdb2269aSchristos #include <dev/isapnp/isapnpdevs.h>
6374545bafSaugustss 
6474545bafSaugustss #include <dev/ic/ad1848reg.h>
6574545bafSaugustss #include <dev/isa/ad1848var.h>
6674545bafSaugustss 
6774545bafSaugustss #include <dev/ic/cs4231reg.h>
6874545bafSaugustss #include <dev/isa/cs4231var.h>
6974545bafSaugustss 
701fa31472Sitohy #include <dev/ic/opl3sa3reg.h>
7174545bafSaugustss #include <dev/isa/wssreg.h>
7274545bafSaugustss #include <dev/isa/ymvar.h>
7374545bafSaugustss 
74df73a4b1Scegger int	ym_isapnp_match(device_t, cfdata_t, void *);
75df73a4b1Scegger void	ym_isapnp_attach(device_t, device_t, void *);
7674545bafSaugustss 
77ff2f721fStsutsui CFATTACH_DECL_NEW(ym_isapnp, sizeof(struct ym_softc),
78c9b3657cSthorpej     ym_isapnp_match, ym_isapnp_attach, NULL, NULL);
7974545bafSaugustss 
8074545bafSaugustss /*
8174545bafSaugustss  * Probe / attach routines.
8274545bafSaugustss  */
8374545bafSaugustss 
8474545bafSaugustss /*
8574545bafSaugustss  * Probe for the Yamaha hardware.
8674545bafSaugustss  */
8774545bafSaugustss int
ym_isapnp_match(device_t parent,cfdata_t match,void * aux)88df73a4b1Scegger ym_isapnp_match(device_t parent, cfdata_t match, void *aux)
8974545bafSaugustss {
906ada3afdSmycroft 	int pri, variant;
912cccf3bdSmycroft 
926ada3afdSmycroft 	pri = isapnp_devmatch(aux, &isapnp_ym_devinfo, &variant);
936ada3afdSmycroft 	if (pri && variant > 0)
946ada3afdSmycroft 		pri = 0;
95069e72cbSkent 	return pri;
9674545bafSaugustss }
9774545bafSaugustss 
9874545bafSaugustss /*
9974545bafSaugustss  * Attach hardware to driver, attach hardware driver to audio
10074545bafSaugustss  * pseudo-device driver.
10174545bafSaugustss  */
10274545bafSaugustss void
ym_isapnp_attach(device_t parent,device_t self,void * aux)103df73a4b1Scegger ym_isapnp_attach(device_t parent, device_t self, void *aux)
10474545bafSaugustss {
105069e72cbSkent 	struct ym_softc *sc;
106069e72cbSkent 	struct ad1848_softc *ac;
107069e72cbSkent 	struct isapnp_attach_args *ipa;
10874545bafSaugustss 
109838ee1e0Sthorpej 	sc = device_private(self);
110069e72cbSkent 	ac = &sc->sc_ad1848.sc_ad1848;
111ff2f721fStsutsui 	ac->sc_dev = self;
112069e72cbSkent 	ipa = aux;
113503014ebSaugustss 	printf("\n");
114503014ebSaugustss 
115503014ebSaugustss 	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
116cf417aadScegger 		aprint_error_dev(self, "error in region allocation\n");
11774545bafSaugustss 		return;
11874545bafSaugustss 	}
11974545bafSaugustss 
12074545bafSaugustss 	sc->sc_iot = ipa->ipa_iot;
12174545bafSaugustss 	sc->sc_ic = ipa->ipa_ic;
122503014ebSaugustss 	sc->sc_ioh = ipa->ipa_io[1].h;
12374545bafSaugustss 
12474545bafSaugustss 	sc->ym_irq = ipa->ipa_irq[0].num;
125281bba93Snathanw 	sc->ym_playdrq = ipa->ipa_drq[0].num;
12674545bafSaugustss 	sc->ym_recdrq = ipa->ipa_drq[1].num;
12774545bafSaugustss 
1281fa31472Sitohy 	sc->sc_sb_ioh = ipa->ipa_io[0].h;
1291fa31472Sitohy 	sc->sc_opl_ioh = ipa->ipa_io[2].h;
1301fa31472Sitohy #if NMPU_YM > 0
1311fa31472Sitohy 	sc->sc_mpu_ioh = ipa->ipa_io[3].h;
1321fa31472Sitohy #endif
13374545bafSaugustss 	sc->sc_controlioh = ipa->ipa_io[4].h;
13474545bafSaugustss 
135f7151935Spk 	ac->sc_iot = sc->sc_iot;
13641d5307eSmycroft 	if (bus_space_subregion(sc->sc_iot, sc->sc_ioh, WSS_CODEC, AD1848_NPORT,
137f887d74cSmycroft 	    &ac->sc_ioh)) {
138cf417aadScegger 		aprint_error_dev(self, "bus_space_subregion failed\n");
139f887d74cSmycroft 		return;
140f887d74cSmycroft 	}
141f7151935Spk 	ac->mode = 2;
142f7151935Spk 	ac->MCE_bit = MODE_CHANGE_ENABLE;
143503014ebSaugustss 
144f7151935Spk 	sc->sc_ad1848.sc_ic  = sc->sc_ic;
145f7151935Spk 
146cf417aadScegger 	printf("%s: %s %s", device_xname(self), ipa->ipa_devident,
147503014ebSaugustss 	    ipa->ipa_devclass);
14874545bafSaugustss 
14974545bafSaugustss 	ym_attach(sc);
15074545bafSaugustss }
151