gus_isapnp.c revision 1.32.4.1 1 /* $NetBSD: gus_isapnp.c,v 1.32.4.1 2008/05/16 02:24:33 yamt Exp $ */
2
3 /*
4 * Copyright (c) 1997, 1999 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.32.4.1 2008/05/16 02:24:33 yamt Exp $");
33
34 #include "guspnp.h"
35 #if NGUSPNP > 0
36
37 #include <sys/param.h>
38 #include <sys/fcntl.h>
39 #include <sys/vnode.h>
40 #include <sys/poll.h>
41 #include <sys/malloc.h>
42 #include <sys/select.h>
43 #include <sys/systm.h>
44 #include <sys/errno.h>
45 #include <sys/ioctl.h>
46 #include <sys/syslog.h>
47 #include <sys/device.h>
48 #include <sys/proc.h>
49
50 #include <sys/bus.h>
51
52 #include <sys/audioio.h>
53 #include <dev/audio_if.h>
54 #include <dev/audiovar.h>
55 #include <dev/mulaw.h>
56
57 #include <dev/isa/isavar.h>
58 #include <dev/isa/isadmavar.h>
59
60 #include <dev/isapnp/isapnpreg.h>
61 #include <dev/isapnp/isapnpvar.h>
62 #include <dev/isapnp/isapnpdevs.h>
63
64
65 #include <dev/ic/interwavevar.h>
66 #include <dev/ic/interwavereg.h>
67
68
69 int gus_isapnp_match(struct device *, struct cfdata *, void *);
70 void gus_isapnp_attach(struct device *, struct device *, void *);
71 static int gus_isapnp_open(void *, int);
72
73 static const struct audio_hw_if guspnp_hw_if = {
74 gus_isapnp_open,
75 iwclose,
76 NULL, /* drain */
77 iw_query_encoding,
78 iw_set_params,
79 iw_round_blocksize,
80 iw_commit_settings,
81 iw_init_output,
82 iw_init_input,
83 iw_start_output,
84 iw_start_input,
85 iw_halt_output,
86 iw_halt_input,
87 iw_speaker_ctl,
88 iw_getdev,
89 iw_setfd,
90 iw_set_port,
91 iw_get_port,
92 iw_query_devinfo,
93 iw_malloc,
94 iw_free,
95 iw_round_buffersize,
96 iw_mappage,
97 iw_get_props,
98 NULL, /* trigger_output */
99 NULL, /* trigger_input */
100 NULL, /* dev_ioctl */
101 NULL, /* powerstate */
102 };
103
104 CFATTACH_DECL(guspnp, sizeof(struct iw_softc),
105 gus_isapnp_match, gus_isapnp_attach, NULL, NULL);
106
107 extern struct cfdriver guspnp_cd;
108
109 /*
110 * Probe / attach routines.
111 */
112
113 /*
114 * Probe for the guspnp hardware.
115 *
116 * The thing has 5 separate devices on the card
117 */
118
119 static int gus_0 = 1; /* XXX what's this */
120
121 int
122 gus_isapnp_match(struct device *parent, struct cfdata *match,
123 void *aux)
124 {
125 int pri, variant;
126
127 pri = isapnp_devmatch(aux, &isapnp_gus_devinfo, &variant);
128 if (pri && variant > 0)
129 pri = 0;
130 return pri;
131 }
132
133 /*
134 * Attach hardware to driver, attach hardware driver to audio
135 * pseudo-device driver.
136 */
137 void
138 gus_isapnp_attach(struct device *parent, struct device *self,
139 void *aux)
140 {
141 struct iw_softc *sc;
142 struct isapnp_attach_args *ipa;
143
144 sc = device_private(self);
145 ipa = aux;
146 printf("\n");
147
148 if (!gus_0)
149 return;
150 gus_0 = 0;
151
152 if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
153 aprint_error_dev(&sc->sc_dev, "error in region allocation\n");
154 return;
155 }
156
157 sc->sc_iot = ipa->ipa_iot;
158
159 /* handle is the region base */
160
161 sc->dir_h = 0; /* XXXXX */
162 sc->p2xr = 0;
163 sc->p2xr_h = ipa->ipa_io[0].h;
164 sc->sc_p2xr_ic = ipa->ipa_ic;
165 sc->p3xr = 0;
166 sc->p3xr_h = ipa->ipa_io[1].h;
167 sc->sc_p3xr_ic = ipa->ipa_ic;
168 sc->codec_index = 0;
169 sc->codec_index_h = ipa->ipa_io[2].h;
170 sc->sc_irq = ipa->ipa_irq[0].num;
171 sc->sc_recdrq = ipa->ipa_drq[0].num;
172 sc->sc_playdrq = ipa->ipa_drq[1].num;
173
174 sc->sc_ic = ipa->ipa_ic;
175
176 /*
177 * Create our DMA maps.
178 */
179 if (sc->sc_playdrq != -1) {
180 sc->sc_play_maxsize = isa_dmamaxsize(sc->sc_ic,
181 sc->sc_playdrq);
182 if (isa_drq_alloc(sc->sc_ic, sc->sc_playdrq) != 0) {
183 aprint_error_dev(&sc->sc_dev, "can't reserve drq %d\n",
184 sc->sc_playdrq);
185 return;
186 }
187 if (isa_dmamap_create(sc->sc_ic, sc->sc_playdrq,
188 sc->sc_play_maxsize, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
189 aprint_error_dev(&sc->sc_dev, "can't create map for drq %d\n",
190 sc->sc_playdrq);
191 return;
192 }
193 }
194 if (sc->sc_recdrq != -1) {
195 sc->sc_rec_maxsize = isa_dmamaxsize(sc->sc_ic,
196 sc->sc_recdrq);
197 if (isa_drq_alloc(sc->sc_ic, sc->sc_recdrq) != 0) {
198 aprint_error_dev(&sc->sc_dev, "can't reserve drq %d\n",
199 sc->sc_recdrq);
200 return;
201 }
202 if (isa_dmamap_create(sc->sc_ic, sc->sc_recdrq,
203 sc->sc_rec_maxsize, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
204 aprint_error_dev(&sc->sc_dev, "can't create map for drq %d\n",
205 sc->sc_recdrq);
206 return;
207 }
208 }
209
210 /*
211 * isapnp is a child if isa, and we need isa for the DMA
212 * routines.
213 */
214 sc->iw_cd = &guspnp_cd;
215 sc->iw_hw_if = &guspnp_hw_if;
216
217 printf("%s: %s %s", device_xname(&sc->sc_dev), ipa->ipa_devident,
218 ipa->ipa_devclass);
219
220 iwattach(sc);
221 }
222
223 static int
224 gus_isapnp_open(void *addr, int flags)
225 {
226 /* open hardware */
227 struct iw_softc *sc;
228
229 sc = (struct iw_softc *)addr;
230 if (!sc)
231 return ENXIO;
232
233 return iwopen(sc,flags);
234 }
235
236 #endif /* NGUSPNP */
237