xref: /netbsd-src/sys/dev/isapnp/wss_isapnp.c (revision b1c86f5f087524e68db12794ee9c3e3da1ab17a0)
1 /*	$NetBSD: wss_isapnp.c,v 1.25 2009/05/12 10:16:35 cegger Exp $	*/
2 
3 /*
4  * Copyright (c) 1997, 1999 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Lennart Augustsson (augustss@NetBSD.org).
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: wss_isapnp.c,v 1.25 2009/05/12 10:16:35 cegger Exp $");
34 
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/device.h>
38 #include <sys/errno.h>
39 
40 #include <sys/bus.h>
41 
42 #include <sys/audioio.h>
43 #include <dev/audio_if.h>
44 
45 #include <dev/isa/isavar.h>
46 #include <dev/isa/isadmavar.h>
47 
48 #include <dev/isapnp/isapnpreg.h>
49 #include <dev/isapnp/isapnpvar.h>
50 #include <dev/isapnp/isapnpdevs.h>
51 
52 #include <dev/isa/ad1848var.h>
53 #include <dev/isa/madreg.h>
54 #include <dev/isa/wssreg.h>
55 #include <dev/isa/wssvar.h>
56 #include <dev/isa/sbreg.h>
57 
58 int	wss_isapnp_match(device_t, cfdata_t, void *);
59 void	wss_isapnp_attach(device_t, device_t, void *);
60 
61 CFATTACH_DECL(wss_isapnp, sizeof(struct wss_softc),
62     wss_isapnp_match, wss_isapnp_attach, NULL, NULL);
63 
64 /*
65  * Probe / attach routines.
66  */
67 
68 /*
69  * Probe for the WSS hardware.
70  */
71 int
72 wss_isapnp_match(device_t parent, cfdata_t match, void *aux)
73 {
74 	int pri, variant;
75 
76 	pri = isapnp_devmatch(aux, &isapnp_wss_devinfo, &variant);
77 	if (pri && variant > 1)
78 		pri = 0;
79 	return pri;
80 }
81 
82 /*
83  * Attach hardware to driver, attach hardware driver to audio
84  * pseudo-device driver.
85  */
86 void
87 wss_isapnp_attach(device_t parent, device_t self, void *aux)
88 {
89 	struct wss_softc *sc;
90 	struct ad1848_softc *ac;
91 	struct isapnp_attach_args *ipa;
92 	int variant;
93 
94 	sc = device_private(self);
95 	ac = &sc->sc_ad1848.sc_ad1848;
96 	ipa = aux;
97 	printf("\n");
98 
99 	if (!isapnp_devmatch(aux, &isapnp_wss_devinfo, &variant)) {
100 		aprint_error_dev(self, "match failed?\n");
101 		return;
102 	}
103 
104 	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
105 		aprint_error_dev(self, "error in region allocation\n");
106 		return;
107 	}
108 
109 	switch (variant) {
110 	case 1:
111 		/* We have to put the chip into `WSS mode'. */
112 		{
113 			bus_space_tag_t iot;
114 			bus_space_handle_t ioh;
115 
116 			iot = ipa->ipa_iot;
117 			ioh = ipa->ipa_io[0].h;
118 
119 			while (bus_space_read_1(iot, ioh,
120 			    SBP_DSP_WSTAT) & SB_DSP_BUSY);
121 			bus_space_write_1(iot, ioh, SBP_DSP_WRITE, 0x09);
122 			while (bus_space_read_1(iot, ioh,
123 			    SBP_DSP_WSTAT) & SB_DSP_BUSY);
124 			bus_space_write_1(iot, ioh, SBP_DSP_WRITE, 0x00);
125 			while (bus_space_read_1(iot, ioh,
126 			    SBP_DSP_WSTAT) & SB_DSP_BUSY);
127 
128 			delay(1000);
129 		}
130 
131 		sc->sc_iot = ipa->ipa_iot;
132 		sc->sc_ioh = ipa->ipa_io[2].h;
133 		break;
134 
135 	default:
136 		sc->sc_iot = ipa->ipa_iot;
137 		sc->sc_ioh = ipa->ipa_io[0].h;
138 		break;
139 	}
140 
141 	sc->mad_chip_type = MAD_NONE;
142 
143 	/* Set up AD1848 I/O handle. */
144 	ac->sc_iot = sc->sc_iot;
145 	ac->sc_ioh = sc->sc_ioh;
146 	ac->mode = 2;
147 
148 	sc->sc_ad1848.sc_ic = ipa->ipa_ic;
149 
150 	sc->wss_ic = ipa->ipa_ic;
151 	sc->wss_irq = ipa->ipa_irq[0].num;
152 	sc->wss_playdrq = ipa->ipa_drq[0].num;
153 	sc->wss_recdrq =
154 	    ipa->ipa_ndrq > 1 ? ipa->ipa_drq[1].num : ipa->ipa_drq[0].num;
155 
156 	if (!ad1848_isa_probe(&sc->sc_ad1848)) {
157 		aprint_error_dev(self, "ad1848_probe failed\n");
158 		return;
159 	}
160 
161 	aprint_error_dev(self, "%s %s", ipa->ipa_devident,
162 	    ipa->ipa_devclass);
163 
164 	wssattach(sc);
165 
166 	/* set up OPL I/O handle for ISAPNP boards w/o MAD */
167 	if (ipa->ipa_nio > 1 && sc->mad_chip_type == MAD_NONE) {
168 		struct audio_attach_args arg;
169 
170 		sc->sc_opl_ioh = ipa->ipa_io[1].h;
171 
172 		arg.type = AUDIODEV_TYPE_OPL;
173 		arg.hwif = 0;
174 		arg.hdl = 0;
175 		(void)config_found(&ac->sc_dev, &arg, audioprint);
176 	}
177 }
178