gus_isapnp.c revision 1.33.12.1 1 /* $NetBSD: gus_isapnp.c,v 1.33.12.1 2008/12/12 23:06:57 ad Exp $ */
2
3 /*
4 * Copyright (c) 1997, 1999, 2008 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * Author: Kari Mettinen
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include <sys/cdefs.h>
32 __KERNEL_RCSID(0, "$NetBSD: gus_isapnp.c,v 1.33.12.1 2008/12/12 23:06:57 ad Exp $");
33
34 #include "guspnp.h"
35 #if NGUSPNP > 0
36
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/errno.h>
40 #include <sys/ioctl.h>
41 #include <sys/syslog.h>
42 #include <sys/device.h>
43 #include <sys/proc.h>
44 #include <sys/bus.h>
45 #include <sys/audioio.h>
46
47 #include <dev/audio_if.h>
48 #include <dev/audiovar.h>
49 #include <dev/mulaw.h>
50
51 #include <dev/isa/isavar.h>
52 #include <dev/isa/isadmavar.h>
53
54 #include <dev/isapnp/isapnpreg.h>
55 #include <dev/isapnp/isapnpvar.h>
56 #include <dev/isapnp/isapnpdevs.h>
57
58 #include <dev/ic/interwavevar.h>
59 #include <dev/ic/interwavereg.h>
60
61
62 int gus_isapnp_match(struct device *, struct cfdata *, void *);
63 void gus_isapnp_attach(struct device *, struct device *, void *);
64 static int gus_isapnp_open(void *, int);
65
66 static const struct audio_hw_if guspnp_hw_if = {
67 gus_isapnp_open,
68 iwclose,
69 NULL, /* drain */
70 iw_query_encoding,
71 iw_set_params,
72 iw_round_blocksize,
73 iw_commit_settings,
74 iw_init_output,
75 iw_init_input,
76 iw_start_output,
77 iw_start_input,
78 iw_halt_output,
79 iw_halt_input,
80 iw_speaker_ctl,
81 iw_getdev,
82 iw_setfd,
83 iw_set_port,
84 iw_get_port,
85 iw_query_devinfo,
86 iw_malloc,
87 iw_free,
88 iw_round_buffersize,
89 iw_mappage,
90 iw_get_props,
91 NULL, /* trigger_output */
92 NULL, /* trigger_input */
93 NULL, /* dev_ioctl */
94 NULL, /* powerstate */
95 iw_get_locks,
96 };
97
98 CFATTACH_DECL(guspnp, sizeof(struct iw_softc),
99 gus_isapnp_match, gus_isapnp_attach, NULL, NULL);
100
101 extern struct cfdriver guspnp_cd;
102
103 /*
104 * Probe / attach routines.
105 */
106
107 /*
108 * Probe for the guspnp hardware.
109 *
110 * The thing has 5 separate devices on the card
111 */
112
113 static int gus_0 = 1; /* XXX what's this */
114
115 int
116 gus_isapnp_match(struct device *parent, struct cfdata *match,
117 void *aux)
118 {
119 int pri, variant;
120
121 pri = isapnp_devmatch(aux, &isapnp_gus_devinfo, &variant);
122 if (pri && variant > 0)
123 pri = 0;
124 return pri;
125 }
126
127 /*
128 * Attach hardware to driver, attach hardware driver to audio
129 * pseudo-device driver.
130 */
131 void
132 gus_isapnp_attach(struct device *parent, struct device *self,
133 void *aux)
134 {
135 struct iw_softc *sc;
136 struct isapnp_attach_args *ipa;
137
138 sc = device_private(self);
139 ipa = aux;
140 printf("\n");
141
142 if (!gus_0)
143 return;
144 gus_0 = 0;
145
146 if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
147 aprint_error_dev(&sc->sc_dev, "error in region allocation\n");
148 return;
149 }
150
151 sc->sc_iot = ipa->ipa_iot;
152
153 /* handle is the region base */
154
155 sc->dir_h = 0; /* XXXXX */
156 sc->p2xr = 0;
157 sc->p2xr_h = ipa->ipa_io[0].h;
158 sc->sc_p2xr_ic = ipa->ipa_ic;
159 sc->p3xr = 0;
160 sc->p3xr_h = ipa->ipa_io[1].h;
161 sc->sc_p3xr_ic = ipa->ipa_ic;
162 sc->codec_index = 0;
163 sc->codec_index_h = ipa->ipa_io[2].h;
164 sc->sc_irq = ipa->ipa_irq[0].num;
165 sc->sc_recdrq = ipa->ipa_drq[0].num;
166 sc->sc_playdrq = ipa->ipa_drq[1].num;
167
168 sc->sc_ic = ipa->ipa_ic;
169
170 /*
171 * Create our DMA maps.
172 */
173 if (sc->sc_playdrq != -1) {
174 sc->sc_play_maxsize = isa_dmamaxsize(sc->sc_ic,
175 sc->sc_playdrq);
176 if (isa_drq_alloc(sc->sc_ic, sc->sc_playdrq) != 0) {
177 aprint_error_dev(&sc->sc_dev, "can't reserve drq %d\n",
178 sc->sc_playdrq);
179 return;
180 }
181 if (isa_dmamap_create(sc->sc_ic, sc->sc_playdrq,
182 sc->sc_play_maxsize, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
183 aprint_error_dev(&sc->sc_dev, "can't create map for drq %d\n",
184 sc->sc_playdrq);
185 return;
186 }
187 }
188 if (sc->sc_recdrq != -1) {
189 sc->sc_rec_maxsize = isa_dmamaxsize(sc->sc_ic,
190 sc->sc_recdrq);
191 if (isa_drq_alloc(sc->sc_ic, sc->sc_recdrq) != 0) {
192 aprint_error_dev(&sc->sc_dev, "can't reserve drq %d\n",
193 sc->sc_recdrq);
194 return;
195 }
196 if (isa_dmamap_create(sc->sc_ic, sc->sc_recdrq,
197 sc->sc_rec_maxsize, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
198 aprint_error_dev(&sc->sc_dev, "can't create map for drq %d\n",
199 sc->sc_recdrq);
200 return;
201 }
202 }
203
204 /*
205 * isapnp is a child if isa, and we need isa for the DMA
206 * routines.
207 */
208 sc->iw_cd = &guspnp_cd;
209 sc->iw_hw_if = &guspnp_hw_if;
210
211 printf("%s: %s %s", device_xname(&sc->sc_dev), ipa->ipa_devident,
212 ipa->ipa_devclass);
213
214 iwattach(sc);
215 }
216
217 static int
218 gus_isapnp_open(void *addr, int flags)
219 {
220 /* open hardware */
221 struct iw_softc *sc;
222
223 sc = (struct iw_softc *)addr;
224 if (!sc)
225 return ENXIO;
226
227 return iwopen(sc,flags);
228 }
229
230 #endif /* NGUSPNP */
231