gus_isapnp.c revision 1.39.2.2 1 /* $NetBSD: gus_isapnp.c,v 1.39.2.2 2019/05/03 05:43:46 isaki 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.39.2.2 2019/05/03 05:43:46 isaki 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
50 #include <dev/isa/isavar.h>
51 #include <dev/isa/isadmavar.h>
52
53 #include <dev/isapnp/isapnpreg.h>
54 #include <dev/isapnp/isapnpvar.h>
55 #include <dev/isapnp/isapnpdevs.h>
56
57 #include <dev/ic/interwavevar.h>
58 #include <dev/ic/interwavereg.h>
59
60
61 int gus_isapnp_match(device_t, cfdata_t, void *);
62 void gus_isapnp_attach(device_t, device_t, void *);
63 static int gus_isapnp_open(void *, int);
64
65 static const struct audio_hw_if guspnp_hw_if = {
66 .open = gus_isapnp_open,
67 .close = iwclose,
68 .query_format = iw_query_format,
69 .set_format = iw_audio_set_format,
70 .round_blocksize = iw_round_blocksize,
71 .commit_settings = iw_commit_settings,
72 .init_output = iw_init_output,
73 .init_input = iw_init_input,
74 .start_output = iw_start_output,
75 .start_input = iw_start_input,
76 .halt_output = iw_halt_output,
77 .halt_input = iw_halt_input,
78 .speaker_ctl = iw_speaker_ctl,
79 .getdev = iw_getdev,
80 .setfd = iw_setfd,
81 .set_port = iw_set_port,
82 .get_port = iw_get_port,
83 .query_devinfo = iw_query_devinfo,
84 .allocm = iw_malloc,
85 .freem = iw_free,
86 .round_buffersize = iw_round_buffersize,
87 .mappage = iw_mappage,
88 .get_props = iw_get_props,
89 .get_locks = iw_get_locks,
90 };
91
92 CFATTACH_DECL_NEW(guspnp, sizeof(struct iw_softc),
93 gus_isapnp_match, gus_isapnp_attach, NULL, NULL);
94
95 extern struct cfdriver guspnp_cd;
96
97 /*
98 * Probe / attach routines.
99 */
100
101 /*
102 * Probe for the guspnp hardware.
103 *
104 * The thing has 5 separate devices on the card
105 */
106
107 static int gus_0 = 1; /* XXX what's this */
108
109 int
110 gus_isapnp_match(device_t parent, cfdata_t match, void *aux)
111 {
112 int pri, variant;
113
114 pri = isapnp_devmatch(aux, &isapnp_gus_devinfo, &variant);
115 if (pri && variant > 0)
116 pri = 0;
117 return pri;
118 }
119
120 /*
121 * Attach hardware to driver, attach hardware driver to audio
122 * pseudo-device driver.
123 */
124 void
125 gus_isapnp_attach(device_t parent, device_t self, void *aux)
126 {
127 struct iw_softc *sc;
128 struct isapnp_attach_args *ipa;
129
130 sc = device_private(self);
131 ipa = aux;
132 aprint_naive("\n");
133 aprint_normal("\n");
134
135 if (!gus_0)
136 return;
137 gus_0 = 0;
138
139 if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
140 aprint_error_dev(self, "error in region allocation\n");
141 return;
142 }
143
144 sc->sc_dev = self;
145 sc->sc_iot = ipa->ipa_iot;
146
147 /* handle is the region base */
148
149 sc->dir_h = 0; /* XXXXX */
150 sc->p2xr = 0;
151 sc->p2xr_h = ipa->ipa_io[0].h;
152 sc->sc_p2xr_ic = ipa->ipa_ic;
153 sc->p3xr = 0;
154 sc->p3xr_h = ipa->ipa_io[1].h;
155 sc->sc_p3xr_ic = ipa->ipa_ic;
156 sc->codec_index = 0;
157 sc->codec_index_h = ipa->ipa_io[2].h;
158 sc->sc_irq = ipa->ipa_irq[0].num;
159 sc->sc_recdrq = ipa->ipa_drq[0].num;
160 sc->sc_playdrq = ipa->ipa_drq[1].num;
161
162 sc->sc_ic = ipa->ipa_ic;
163
164 /*
165 * Create our DMA maps.
166 */
167 if (sc->sc_playdrq != -1) {
168 sc->sc_play_maxsize = isa_dmamaxsize(sc->sc_ic,
169 sc->sc_playdrq);
170 if (isa_drq_alloc(sc->sc_ic, sc->sc_playdrq) != 0) {
171 aprint_error_dev(self, "can't reserve drq %d\n",
172 sc->sc_playdrq);
173 return;
174 }
175 if (isa_dmamap_create(sc->sc_ic, sc->sc_playdrq,
176 sc->sc_play_maxsize, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
177 aprint_error_dev(self, "can't create map for drq %d\n",
178 sc->sc_playdrq);
179 return;
180 }
181 }
182 if (sc->sc_recdrq != -1) {
183 sc->sc_rec_maxsize = isa_dmamaxsize(sc->sc_ic,
184 sc->sc_recdrq);
185 if (isa_drq_alloc(sc->sc_ic, sc->sc_recdrq) != 0) {
186 aprint_error_dev(self, "can't reserve drq %d\n",
187 sc->sc_recdrq);
188 return;
189 }
190 if (isa_dmamap_create(sc->sc_ic, sc->sc_recdrq,
191 sc->sc_rec_maxsize, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
192 aprint_error_dev(self, "can't create map for drq %d\n",
193 sc->sc_recdrq);
194 return;
195 }
196 }
197
198 /*
199 * isapnp is a child if isa, and we need isa for the DMA
200 * routines.
201 */
202 sc->iw_cd = &guspnp_cd;
203 sc->iw_hw_if = &guspnp_hw_if;
204
205 aprint_normal_dev(self, "%s %s", ipa->ipa_devident, ipa->ipa_devclass);
206
207 iwattach(sc);
208 }
209
210 static int
211 gus_isapnp_open(void *addr, int flags)
212 {
213 /* open hardware */
214 struct iw_softc *sc;
215
216 sc = (struct iw_softc *)addr;
217 if (!sc)
218 return ENXIO;
219
220 return iwopen(sc,flags);
221 }
222
223 #endif /* NGUSPNP */
224