xref: /netbsd/sys/dev/isapnp/ym_isapnp.c (revision c4a72b64)
1 /*	$NetBSD: ym_isapnp.c,v 1.16 2002/10/02 16:34:05 thorpej Exp $ */
2 
3 
4 /*
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 /*
39  *  Driver for the Yamaha OPL3-SA3 chipset. This is found on many laptops
40  *  and Pentium (II) motherboards.
41  *
42  *  Original code from OpenBSD.
43  */
44 
45 #include <sys/cdefs.h>
46 __KERNEL_RCSID(0, "$NetBSD: ym_isapnp.c,v 1.16 2002/10/02 16:34:05 thorpej Exp $");
47 
48 #include "mpu_ym.h"
49 
50 #include <sys/param.h>
51 #include <sys/systm.h>
52 #include <sys/device.h>
53 #include <sys/errno.h>
54 
55 #include <sys/audioio.h>
56 #include <dev/audio_if.h>
57 
58 #include <dev/isa/isavar.h>
59 #include <dev/isa/isadmavar.h>
60 
61 #include <dev/isapnp/isapnpreg.h>
62 #include <dev/isapnp/isapnpvar.h>
63 #include <dev/isapnp/isapnpdevs.h>
64 
65 #include <dev/ic/ad1848reg.h>
66 #include <dev/isa/ad1848var.h>
67 
68 #include <dev/ic/cs4231reg.h>
69 #include <dev/isa/cs4231var.h>
70 
71 #include <dev/ic/opl3sa3reg.h>
72 #include <dev/isa/wssreg.h>
73 #include <dev/isa/ymvar.h>
74 
75 int	ym_isapnp_match __P((struct device *, struct cfdata *, void *));
76 void	ym_isapnp_attach __P((struct device *, struct device *, void *));
77 
78 CFATTACH_DECL(ym_isapnp, sizeof(struct ym_softc),
79     ym_isapnp_match, ym_isapnp_attach, NULL, NULL);
80 
81 /*
82  * Probe / attach routines.
83  */
84 
85 /*
86  * Probe for the Yamaha hardware.
87  */
88 int
89 ym_isapnp_match(parent, match, aux)
90 	struct device *parent;
91 	struct cfdata *match;
92 	void *aux;
93 {
94 	int pri, variant;
95 
96 	pri = isapnp_devmatch(aux, &isapnp_ym_devinfo, &variant);
97 	if (pri && variant > 0)
98 		pri = 0;
99 	return (pri);
100 }
101 
102 /*
103  * Attach hardware to driver, attach hardware driver to audio
104  * pseudo-device driver.
105  */
106 void
107 ym_isapnp_attach(parent, self, aux)
108 	struct device *parent, *self;
109 	void *aux;
110 {
111 	struct ym_softc *sc = (struct ym_softc *)self;
112 	struct ad1848_softc *ac = &sc->sc_ad1848.sc_ad1848;
113 	struct isapnp_attach_args *ipa = aux;
114 
115 	printf("\n");
116 
117 	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
118 		printf("%s: error in region allocation\n", self->dv_xname);
119 		return;
120 	}
121 
122 	sc->sc_iot = ipa->ipa_iot;
123 	sc->sc_ic = ipa->ipa_ic;
124 	sc->sc_ioh = ipa->ipa_io[1].h;
125 
126 	sc->ym_irq = ipa->ipa_irq[0].num;
127 	sc->ym_playdrq = ipa->ipa_drq[0].num;
128 	sc->ym_recdrq = ipa->ipa_drq[1].num;
129 
130 	sc->sc_sb_ioh = ipa->ipa_io[0].h;
131 	sc->sc_opl_ioh = ipa->ipa_io[2].h;
132 #if NMPU_YM > 0
133 	sc->sc_mpu_ioh = ipa->ipa_io[3].h;
134 #endif
135 	sc->sc_controlioh = ipa->ipa_io[4].h;
136 
137 	ac->sc_iot = sc->sc_iot;
138 	if (bus_space_subregion(sc->sc_iot, sc->sc_ioh, WSS_CODEC, AD1848_NPORT,
139 	    &ac->sc_ioh)) {
140 		printf("%s: bus_space_subregion failed\n", self->dv_xname);
141 		return;
142 	}
143 	ac->mode = 2;
144 	ac->MCE_bit = MODE_CHANGE_ENABLE;
145 
146 	sc->sc_ad1848.sc_ic  = sc->sc_ic;
147 
148 	printf("%s: %s %s", self->dv_xname, ipa->ipa_devident,
149 	    ipa->ipa_devclass);
150 
151 	ym_attach(sc);
152 }
153