Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / isapnp / wss_isapnp.c
blobc1eda294509246f90e45a89532ce8a4ca0d9cdc4
1 /* $NetBSD: wss_isapnp.c,v 1.24 2009/05/12 10:07:55 cegger Exp $ */
3 /*
4 * Copyright (c) 1997, 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Lennart Augustsson (augustss@NetBSD.org).
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.
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.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: wss_isapnp.c,v 1.24 2009/05/12 10:07:55 cegger Exp $");
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/device.h>
38 #include <sys/errno.h>
40 #include <sys/bus.h>
42 #include <sys/audioio.h>
43 #include <dev/audio_if.h>
45 #include <dev/isa/isavar.h>
46 #include <dev/isa/isadmavar.h>
48 #include <dev/isapnp/isapnpreg.h>
49 #include <dev/isapnp/isapnpvar.h>
50 #include <dev/isapnp/isapnpdevs.h>
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>
58 int wss_isapnp_match(device_t, cfdata_t, void *);
59 void wss_isapnp_attach(device_t, device_t, void *);
61 CFATTACH_DECL(wss_isapnp, sizeof(struct wss_softc),
62 wss_isapnp_match, wss_isapnp_attach, NULL, NULL);
65 * Probe / attach routines.
69 * Probe for the WSS hardware.
71 int
72 wss_isapnp_match(device_t parent, cfdata_t match, void *aux)
74 int pri, variant;
76 pri = isapnp_devmatch(aux, &isapnp_wss_devinfo, &variant);
77 if (pri && variant > 1)
78 pri = 0;
79 return pri;
83 * Attach hardware to driver, attach hardware driver to audio
84 * pseudo-device driver.
86 void
87 wss_isapnp_attach(device_t parent, device_t self, void *aux)
89 struct wss_softc *sc;
90 struct ad1848_softc *ac;
91 struct isapnp_attach_args *ipa;
92 int variant;
94 sc = device_private(self);
95 ac = &sc->sc_ad1848.sc_ad1848;
96 ipa = aux;
97 printf("\n");
99 if (!isapnp_devmatch(aux, &isapnp_wss_devinfo, &variant)) {
100 aprint_error_dev(self, "match failed?\n");
101 return;
104 if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
105 aprint_error_dev(self, "error in region allocation\n");
106 return;
109 switch (variant) {
110 case 1:
111 /* We have to put the chip into `WSS mode'. */
113 bus_space_tag_t iot;
114 bus_space_handle_t ioh;
116 iot = ipa->ipa_iot;
117 ioh = ipa->ipa_io[0].h;
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);
128 delay(1000);
131 sc->sc_iot = ipa->ipa_iot;
132 sc->sc_ioh = ipa->ipa_io[2].h;
133 break;
135 default:
136 sc->sc_iot = ipa->ipa_iot;
137 sc->sc_ioh = ipa->ipa_io[0].h;
138 break;
141 sc->mad_chip_type = MAD_NONE;
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;
148 sc->sc_ad1848.sc_ic = ipa->ipa_ic;
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;
156 if (!ad1848_isa_probe(&sc->sc_ad1848)) {
157 aprint_error_dev(self, "ad1848_probe failed\n");
158 return;
161 aprint_error_dev(self, "%s %s", ipa->ipa_devident,
162 ipa->ipa_devclass);
164 wssattach(sc);
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;
170 sc->sc_opl_ioh = ipa->ipa_io[1].h;
172 arg.type = AUDIODEV_TYPE_OPL;
173 arg.hwif = 0;
174 arg.hdl = 0;
175 (void)config_found(&ac->sc_dev, &arg, audioprint);