vidcaudio.c revision 1.14.2.5 1 1.14.2.5 skrll /* $NetBSD: vidcaudio.c,v 1.14.2.5 2005/01/17 19:29:12 skrll Exp $ */
2 1.1 reinoud
3 1.1 reinoud /*
4 1.1 reinoud * Copyright (c) 1995 Melvin Tang-Richardson
5 1.1 reinoud *
6 1.1 reinoud * Redistribution and use in source and binary forms, with or without
7 1.1 reinoud * modification, are permitted provided that the following conditions
8 1.1 reinoud * are met:
9 1.1 reinoud * 1. Redistributions of source code must retain the above copyright
10 1.1 reinoud * notice, this list of conditions and the following disclaimer.
11 1.1 reinoud * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 reinoud * notice, this list of conditions and the following disclaimer in the
13 1.1 reinoud * documentation and/or other materials provided with the distribution.
14 1.1 reinoud * 3. All advertising materials mentioning features or use of this software
15 1.1 reinoud * must display the following acknowledgement:
16 1.1 reinoud * This product includes software developed by the RiscBSD team.
17 1.1 reinoud * 4. The name of the author may not be used to endorse or promote products
18 1.1 reinoud * derived from this software without specific prior written permission.
19 1.1 reinoud *
20 1.1 reinoud * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.1 reinoud * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.1 reinoud * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.1 reinoud * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.1 reinoud * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.1 reinoud * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.1 reinoud * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.1 reinoud * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.1 reinoud * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.1 reinoud * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.1 reinoud */
31 1.1 reinoud
32 1.14.2.1 skrll /*-
33 1.14.2.1 skrll * Copyright (c) 2003 Ben Harris
34 1.14.2.1 skrll * All rights reserved.
35 1.14.2.1 skrll *
36 1.14.2.1 skrll * Redistribution and use in source and binary forms, with or without
37 1.14.2.1 skrll * modification, are permitted provided that the following conditions
38 1.14.2.1 skrll * are met:
39 1.14.2.1 skrll * 1. Redistributions of source code must retain the above copyright
40 1.14.2.1 skrll * notice, this list of conditions and the following disclaimer.
41 1.14.2.1 skrll * 2. Redistributions in binary form must reproduce the above copyright
42 1.14.2.1 skrll * notice, this list of conditions and the following disclaimer in the
43 1.14.2.1 skrll * documentation and/or other materials provided with the distribution.
44 1.14.2.1 skrll * 3. The name of the author may not be used to endorse or promote products
45 1.14.2.1 skrll * derived from this software without specific prior written permission.
46 1.14.2.1 skrll *
47 1.14.2.1 skrll * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
48 1.14.2.1 skrll * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49 1.14.2.1 skrll * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
50 1.14.2.1 skrll * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
51 1.14.2.1 skrll * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
52 1.14.2.1 skrll * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
53 1.14.2.1 skrll * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
54 1.14.2.1 skrll * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
55 1.14.2.1 skrll * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
56 1.14.2.1 skrll * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57 1.14.2.1 skrll */
58 1.14.2.1 skrll
59 1.1 reinoud /*
60 1.14.2.1 skrll * audio driver for the RiscPC 8/16 bit sound
61 1.1 reinoud *
62 1.1 reinoud * Interfaces with the NetBSD generic audio driver to provide SUN
63 1.1 reinoud * /dev/audio (partial) compatibility.
64 1.1 reinoud */
65 1.1 reinoud
66 1.1 reinoud #include <sys/param.h> /* proc.h */
67 1.5 bjh21
68 1.14.2.5 skrll __KERNEL_RCSID(0, "$NetBSD: vidcaudio.c,v 1.14.2.5 2005/01/17 19:29:12 skrll Exp $");
69 1.5 bjh21
70 1.14.2.1 skrll #include <sys/audioio.h>
71 1.1 reinoud #include <sys/conf.h> /* autoconfig functions */
72 1.1 reinoud #include <sys/device.h> /* device calls */
73 1.1 reinoud #include <sys/errno.h>
74 1.14.2.1 skrll #include <sys/malloc.h>
75 1.14.2.1 skrll #include <sys/proc.h> /* device calls */
76 1.1 reinoud #include <sys/systm.h>
77 1.1 reinoud
78 1.1 reinoud #include <uvm/uvm_extern.h>
79 1.1 reinoud
80 1.1 reinoud #include <dev/audio_if.h>
81 1.14.2.1 skrll #include <dev/audiobellvar.h>
82 1.14.2.5 skrll #include <dev/auconv.h>
83 1.14.2.1 skrll #include <dev/mulaw.h>
84 1.1 reinoud
85 1.4 thorpej #include <machine/intr.h>
86 1.14.2.1 skrll #include <machine/machdep.h>
87 1.3 thorpej #include <arm/arm32/katelib.h>
88 1.1 reinoud
89 1.5 bjh21 #include <arm/iomd/vidcaudiovar.h>
90 1.1 reinoud #include <arm/iomd/iomdreg.h>
91 1.1 reinoud #include <arm/iomd/iomdvar.h>
92 1.1 reinoud #include <arm/iomd/vidc.h>
93 1.1 reinoud #include <arm/mainbus/mainbus.h>
94 1.1 reinoud
95 1.14.2.1 skrll #include "pckbd.h"
96 1.14.2.1 skrll #if NPCKBD > 0
97 1.14.2.1 skrll #include <dev/pckbport/pckbdvar.h>
98 1.14.2.1 skrll #endif
99 1.1 reinoud
100 1.14.2.1 skrll #include "rpckbd.h"
101 1.14.2.1 skrll #if NRPCKBD > 0
102 1.14.2.1 skrll #include <arm/iomd/rpckbdvar.h>
103 1.14.2.1 skrll #endif
104 1.1 reinoud
105 1.14.2.1 skrll #include "vt.h"
106 1.14.2.1 skrll #if NVT > 0
107 1.14.2.1 skrll extern void vt_hookup_bell(void (*)(void *, u_int, u_int, u_int, int), void *);
108 1.14.2.1 skrll #endif
109 1.1 reinoud
110 1.14.2.1 skrll extern int *vidc_base;
111 1.1 reinoud
112 1.14.2.1 skrll #ifdef VIDCAUDIO_DEBUG
113 1.14.2.1 skrll #define DPRINTF(x) printf x
114 1.14.2.1 skrll #else
115 1.14.2.1 skrll #define DPRINTF(x)
116 1.14.2.1 skrll #endif
117 1.1 reinoud
118 1.14.2.1 skrll struct vidcaudio_softc {
119 1.14.2.1 skrll struct device sc_dev;
120 1.1 reinoud
121 1.14.2.1 skrll irqhandler_t sc_ih;
122 1.14.2.1 skrll int sc_dma_intr;
123 1.1 reinoud
124 1.14.2.1 skrll int sc_is16bit;
125 1.1 reinoud
126 1.14.2.1 skrll size_t sc_pblksize;
127 1.14.2.1 skrll vm_offset_t sc_poffset;
128 1.14.2.1 skrll vm_offset_t sc_pbufsize;
129 1.14.2.1 skrll paddr_t *sc_ppages;
130 1.14.2.1 skrll void (*sc_pintr)(void *);
131 1.14.2.1 skrll void *sc_parg;
132 1.14.2.1 skrll int sc_pcountdown;
133 1.1 reinoud };
134 1.1 reinoud
135 1.14.2.1 skrll static int vidcaudio_probe(struct device *, struct cfdata *, void *);
136 1.14.2.1 skrll static void vidcaudio_attach(struct device *, struct device *, void *);
137 1.14.2.1 skrll static void vidcaudio_close(void *);
138 1.14.2.1 skrll
139 1.14.2.1 skrll static int vidcaudio_intr(void *);
140 1.14.2.1 skrll static void vidcaudio_rate(int);
141 1.14.2.1 skrll static void vidcaudio_ctrl(int);
142 1.14.2.1 skrll static void vidcaudio_stereo(int, int);
143 1.14.2.5 skrll static stream_filter_factory_t mulaw_to_vidc;
144 1.14.2.5 skrll static stream_filter_factory_t mulaw_to_vidc_stereo;
145 1.14.2.5 skrll static int mulaw_to_vidc_fetch_to(stream_fetcher_t *, audio_stream_t *, int);
146 1.14.2.5 skrll static int mulaw_to_vidc_stereo_fetch_to(stream_fetcher_t *,
147 1.14.2.5 skrll audio_stream_t *, int);
148 1.1 reinoud
149 1.12 thorpej CFATTACH_DECL(vidcaudio, sizeof(struct vidcaudio_softc),
150 1.13 thorpej vidcaudio_probe, vidcaudio_attach, NULL, NULL);
151 1.1 reinoud
152 1.14.2.1 skrll static int vidcaudio_query_encoding(void *, struct audio_encoding *);
153 1.14.2.5 skrll static int vidcaudio_set_params(void *, int, int, audio_params_t *,
154 1.14.2.5 skrll audio_params_t *, stream_filter_list_t *, stream_filter_list_t *);
155 1.14.2.5 skrll static int vidcaudio_round_blocksize(void *, int, int, const audio_params_t *);
156 1.14.2.1 skrll static int vidcaudio_trigger_output(void *, void *, void *, int,
157 1.14.2.5 skrll void (*)(void *), void *, const audio_params_t *);
158 1.14.2.1 skrll static int vidcaudio_trigger_input(void *, void *, void *, int,
159 1.14.2.5 skrll void (*)(void *), void *, const audio_params_t *);
160 1.14.2.1 skrll static int vidcaudio_halt_output(void *);
161 1.14.2.1 skrll static int vidcaudio_halt_input(void *);
162 1.14.2.1 skrll static int vidcaudio_getdev(void *, struct audio_device *);
163 1.14.2.1 skrll static int vidcaudio_set_port(void *, mixer_ctrl_t *);
164 1.14.2.1 skrll static int vidcaudio_get_port(void *, mixer_ctrl_t *);
165 1.14.2.1 skrll static int vidcaudio_query_devinfo(void *, mixer_devinfo_t *);
166 1.14.2.1 skrll static int vidcaudio_get_props(void *);
167 1.14.2.1 skrll
168 1.14.2.1 skrll static struct audio_device vidcaudio_device = {
169 1.14.2.1 skrll "ARM VIDC",
170 1.14.2.1 skrll "",
171 1.1 reinoud "vidcaudio"
172 1.1 reinoud };
173 1.1 reinoud
174 1.14.2.4 skrll static const struct audio_hw_if vidcaudio_hw_if = {
175 1.14.2.5 skrll NULL, /* open */
176 1.1 reinoud vidcaudio_close,
177 1.14.2.1 skrll NULL,
178 1.1 reinoud vidcaudio_query_encoding,
179 1.1 reinoud vidcaudio_set_params,
180 1.1 reinoud vidcaudio_round_blocksize,
181 1.14.2.1 skrll NULL,
182 1.14.2.1 skrll NULL,
183 1.14.2.1 skrll NULL,
184 1.14.2.1 skrll NULL,
185 1.14.2.1 skrll NULL,
186 1.1 reinoud vidcaudio_halt_output,
187 1.1 reinoud vidcaudio_halt_input,
188 1.14.2.1 skrll NULL,
189 1.1 reinoud vidcaudio_getdev,
190 1.14.2.1 skrll NULL,
191 1.1 reinoud vidcaudio_set_port,
192 1.1 reinoud vidcaudio_get_port,
193 1.1 reinoud vidcaudio_query_devinfo,
194 1.14.2.1 skrll NULL,
195 1.14.2.1 skrll NULL,
196 1.14.2.1 skrll NULL,
197 1.14.2.1 skrll NULL,
198 1.1 reinoud vidcaudio_get_props,
199 1.14.2.1 skrll vidcaudio_trigger_output,
200 1.14.2.1 skrll vidcaudio_trigger_input,
201 1.14.2.1 skrll NULL,
202 1.1 reinoud };
203 1.1 reinoud
204 1.14.2.1 skrll static int
205 1.14.2.1 skrll vidcaudio_probe(struct device *parent, struct cfdata *cf, void *aux)
206 1.1 reinoud {
207 1.1 reinoud int id;
208 1.1 reinoud
209 1.1 reinoud id = IOMD_ID;
210 1.1 reinoud
211 1.1 reinoud /* So far I only know about this IOMD */
212 1.1 reinoud switch (id) {
213 1.1 reinoud case RPC600_IOMD_ID:
214 1.1 reinoud case ARM7500_IOC_ID:
215 1.1 reinoud case ARM7500FE_IOC_ID:
216 1.14.2.1 skrll return 1;
217 1.1 reinoud default:
218 1.14.2.1 skrll aprint_error("vidcaudio: Unknown IOMD id=%04x", id);
219 1.14.2.1 skrll return 0;
220 1.1 reinoud }
221 1.1 reinoud }
222 1.1 reinoud
223 1.1 reinoud
224 1.14.2.1 skrll static void
225 1.14.2.1 skrll vidcaudio_attach(struct device *parent, struct device *self, void *aux)
226 1.1 reinoud {
227 1.14.2.5 skrll struct vidcaudio_softc *sc;
228 1.14.2.1 skrll struct device *beepdev;
229 1.1 reinoud
230 1.14.2.5 skrll sc = (void *)self;
231 1.14.2.1 skrll switch (IOMD_ID) {
232 1.14.2.1 skrll #ifndef EB7500ATX
233 1.1 reinoud case RPC600_IOMD_ID:
234 1.14.2.1 skrll sc->sc_is16bit = (cmos_read(0xc4) >> 5) & 1;
235 1.14.2.1 skrll sc->sc_dma_intr = IRQ_DMASCH0;
236 1.1 reinoud break;
237 1.14.2.1 skrll #endif
238 1.1 reinoud case ARM7500_IOC_ID:
239 1.1 reinoud case ARM7500FE_IOC_ID:
240 1.14.2.1 skrll sc->sc_is16bit = TRUE;
241 1.14.2.1 skrll sc->sc_dma_intr = IRQ_SDMA;
242 1.1 reinoud break;
243 1.14.2.1 skrll default:
244 1.14.2.1 skrll aprint_error(": strange IOMD\n");
245 1.14.2.1 skrll return;
246 1.1 reinoud }
247 1.1 reinoud
248 1.14.2.1 skrll if (sc->sc_is16bit)
249 1.14.2.1 skrll aprint_normal(": 16-bit external DAC\n");
250 1.14.2.1 skrll else
251 1.14.2.1 skrll aprint_normal(": 8-bit internal DAC\n");
252 1.1 reinoud
253 1.14.2.1 skrll /* Install the irq handler for the DMA interrupt */
254 1.14.2.1 skrll sc->sc_ih.ih_func = vidcaudio_intr;
255 1.14.2.1 skrll sc->sc_ih.ih_arg = sc;
256 1.14.2.1 skrll sc->sc_ih.ih_level = IPL_AUDIO;
257 1.14.2.1 skrll sc->sc_ih.ih_name = self->dv_xname;
258 1.14.2.1 skrll
259 1.14.2.1 skrll if (irq_claim(sc->sc_dma_intr, &sc->sc_ih) != 0) {
260 1.14.2.1 skrll aprint_error("%s: couldn't claim IRQ %d\n",
261 1.14.2.1 skrll self->dv_xname, sc->sc_dma_intr);
262 1.14.2.1 skrll return;
263 1.14.2.1 skrll }
264 1.1 reinoud
265 1.14.2.1 skrll disable_irq(sc->sc_dma_intr);
266 1.1 reinoud
267 1.14.2.1 skrll beepdev = audio_attach_mi(&vidcaudio_hw_if, sc, self);
268 1.14.2.1 skrll #if NPCKBD > 0
269 1.14.2.1 skrll pckbd_hookup_bell(audiobell, beepdev);
270 1.14.2.1 skrll #endif
271 1.14.2.1 skrll #if NRPCKBD > 0
272 1.14.2.1 skrll rpckbd_hookup_bell(audiobell, beepdev);
273 1.14.2.1 skrll #endif
274 1.14.2.1 skrll #if NVT > 0
275 1.14.2.1 skrll vt_hookup_bell(audiobell, beepdev);
276 1.1 reinoud #endif
277 1.1 reinoud }
278 1.1 reinoud
279 1.14.2.1 skrll static void
280 1.14.2.1 skrll vidcaudio_close(void *addr)
281 1.1 reinoud {
282 1.14.2.5 skrll struct vidcaudio_softc *sc;
283 1.1 reinoud
284 1.14.2.1 skrll DPRINTF(("DEBUG: vidcaudio_close called\n"));
285 1.14.2.5 skrll sc = addr;
286 1.14.2.1 skrll /*
287 1.14.2.1 skrll * We do this here rather than in vidcaudio_halt_output()
288 1.14.2.1 skrll * because the latter can be called from interrupt context
289 1.14.2.1 skrll * (audio_pint()->audio_clear()->vidcaudio_halt_output()).
290 1.14.2.1 skrll */
291 1.14.2.1 skrll if (sc->sc_ppages != NULL) {
292 1.14.2.1 skrll free(sc->sc_ppages, M_DEVBUF);
293 1.14.2.1 skrll sc->sc_ppages = NULL;
294 1.14.2.1 skrll }
295 1.1 reinoud }
296 1.1 reinoud
297 1.14.2.1 skrll /*
298 1.14.2.1 skrll * Interface to the generic audio driver
299 1.14.2.1 skrll */
300 1.14.2.1 skrll
301 1.14.2.1 skrll static int
302 1.14.2.1 skrll vidcaudio_query_encoding(void *addr, struct audio_encoding *fp)
303 1.1 reinoud {
304 1.14.2.5 skrll struct vidcaudio_softc *sc;
305 1.14.2.1 skrll
306 1.14.2.5 skrll sc = addr;
307 1.1 reinoud switch (fp->index) {
308 1.1 reinoud case 0:
309 1.14.2.1 skrll strcpy(fp->name, AudioEmulaw);
310 1.1 reinoud fp->encoding = AUDIO_ENCODING_ULAW;
311 1.1 reinoud fp->precision = 8;
312 1.14.2.1 skrll fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
313 1.1 reinoud break;
314 1.1 reinoud
315 1.14.2.1 skrll case 1:
316 1.14.2.1 skrll if (sc->sc_is16bit) {
317 1.14.2.1 skrll strcpy(fp->name, AudioEslinear_le);
318 1.14.2.1 skrll fp->encoding = AUDIO_ENCODING_SLINEAR_LE;
319 1.14.2.1 skrll fp->precision = 16;
320 1.14.2.1 skrll fp->flags = 0;
321 1.14.2.1 skrll break;
322 1.14.2.1 skrll }
323 1.14.2.1 skrll /* FALLTHROUGH */
324 1.1 reinoud default:
325 1.14.2.1 skrll return EINVAL;
326 1.1 reinoud }
327 1.1 reinoud return 0;
328 1.1 reinoud }
329 1.1 reinoud
330 1.14.2.1 skrll #define MULAW_TO_VIDC(m) (~((m) << 1 | (m) >> 7))
331 1.14.2.1 skrll
332 1.14.2.5 skrll static stream_filter_t *
333 1.14.2.5 skrll mulaw_to_vidc(struct audio_softc *sc, const audio_params_t *from,
334 1.14.2.5 skrll const audio_params_t *to)
335 1.1 reinoud {
336 1.1 reinoud
337 1.14.2.5 skrll return auconv_nocontext_filter_factory(mulaw_to_vidc_fetch_to);
338 1.1 reinoud }
339 1.1 reinoud
340 1.14.2.5 skrll static int
341 1.14.2.5 skrll mulaw_to_vidc_fetch_to(stream_fetcher_t *self, audio_stream_t *dst, int max_used)
342 1.1 reinoud {
343 1.14.2.5 skrll stream_filter_t *this;
344 1.14.2.5 skrll int m, err;
345 1.1 reinoud
346 1.14.2.5 skrll this = (stream_filter_t *)self;
347 1.14.2.5 skrll if ((err = this->prev->fetch_to(this->prev, this->src, max_used)))
348 1.14.2.5 skrll return err;
349 1.14.2.5 skrll m = dst->end - dst->start;
350 1.14.2.5 skrll m = min(m, max_used);
351 1.14.2.5 skrll FILTER_LOOP_PROLOGUE(this->src, 1, dst, 1, m) {
352 1.14.2.5 skrll *d = MULAW_TO_VIDC(*s);
353 1.14.2.5 skrll } FILTER_LOOP_EPILOGUE(this->src, dst);
354 1.14.2.5 skrll return 0;
355 1.14.2.5 skrll }
356 1.14.2.5 skrll
357 1.14.2.5 skrll static stream_filter_t *
358 1.14.2.5 skrll mulaw_to_vidc_stereo(struct audio_softc *sc, const audio_params_t *from,
359 1.14.2.5 skrll const audio_params_t *to)
360 1.14.2.5 skrll {
361 1.14.2.5 skrll
362 1.14.2.5 skrll return auconv_nocontext_filter_factory(mulaw_to_vidc_stereo_fetch_to);
363 1.14.2.5 skrll }
364 1.14.2.5 skrll
365 1.14.2.5 skrll static int
366 1.14.2.5 skrll mulaw_to_vidc_stereo_fetch_to(stream_fetcher_t *self, audio_stream_t *dst,
367 1.14.2.5 skrll int max_used)
368 1.14.2.5 skrll {
369 1.14.2.5 skrll stream_filter_t *this;
370 1.14.2.5 skrll int m, err;
371 1.14.2.5 skrll
372 1.14.2.5 skrll this = (stream_filter_t *)self;
373 1.14.2.5 skrll max_used = (max_used + 1) & ~1;
374 1.14.2.5 skrll if ((err = this->prev->fetch_to(this->prev, this->src, max_used / 2)))
375 1.14.2.5 skrll return err;
376 1.14.2.5 skrll m = (dst->end - dst->start) & ~1;
377 1.14.2.5 skrll m = min(m, max_used);
378 1.14.2.5 skrll FILTER_LOOP_PROLOGUE(this->src, 1, dst, 2, m) {
379 1.14.2.5 skrll d[0] = d[1] = MULAW_TO_VIDC(*s);
380 1.14.2.5 skrll } FILTER_LOOP_EPILOGUE(this->src, dst);
381 1.14.2.5 skrll return 0;
382 1.14.2.1 skrll }
383 1.1 reinoud
384 1.14.2.1 skrll static int
385 1.14.2.1 skrll vidcaudio_set_params(void *addr, int setmode, int usemode,
386 1.14.2.5 skrll audio_params_t *p, audio_params_t *r,
387 1.14.2.5 skrll stream_filter_list_t *pfil, stream_filter_list_t *rfil)
388 1.1 reinoud {
389 1.14.2.5 skrll audio_params_t hw;
390 1.14.2.5 skrll struct vidcaudio_softc *sc;
391 1.14.2.1 skrll int sample_period, ch;
392 1.1 reinoud
393 1.14.2.1 skrll if ((setmode & AUMODE_PLAY) == 0)
394 1.14.2.1 skrll return 0;
395 1.1 reinoud
396 1.14.2.5 skrll sc = addr;
397 1.14.2.1 skrll if (sc->sc_is16bit) {
398 1.14.2.1 skrll /* ARM7500ish, 16-bit, two-channel */
399 1.14.2.5 skrll hw = *p;
400 1.14.2.1 skrll if (p->encoding == AUDIO_ENCODING_ULAW && p->precision == 8) {
401 1.14.2.5 skrll hw.encoding = AUDIO_ENCODING_SLINEAR_LE;
402 1.14.2.5 skrll hw.precision = hw.validbits = 16;
403 1.14.2.5 skrll pfil->append(pfil, mulaw_to_linear16, &hw);
404 1.14.2.1 skrll } else if (p->encoding != AUDIO_ENCODING_SLINEAR_LE ||
405 1.14.2.1 skrll p->precision != 16)
406 1.14.2.1 skrll return EINVAL;
407 1.14.2.1 skrll sample_period = 705600 / 4 / p->sample_rate;
408 1.14.2.1 skrll if (sample_period < 3) sample_period = 3;
409 1.14.2.1 skrll vidcaudio_rate(sample_period - 2);
410 1.14.2.1 skrll vidcaudio_ctrl(SCR_SERIAL);
411 1.14.2.5 skrll hw.sample_rate = 705600 / 4 / sample_period;
412 1.14.2.5 skrll hw.channels = 2;
413 1.14.2.5 skrll pfil->append(pfil, aurateconv, &hw);
414 1.14.2.1 skrll } else {
415 1.14.2.1 skrll /* VIDC20ish, u-law, 8-channel */
416 1.14.2.1 skrll if (p->encoding != AUDIO_ENCODING_ULAW || p->precision != 8)
417 1.14.2.1 skrll return EINVAL;
418 1.1 reinoud /*
419 1.14.2.1 skrll * We always use two hardware channels, because using
420 1.14.2.1 skrll * one at 8kHz gives a nasty whining sound from the
421 1.14.2.1 skrll * speaker. The aurateconv mechanism doesn't support
422 1.14.2.1 skrll * ulaw, so we do the channel duplication ourselves,
423 1.14.2.1 skrll * and don't try to do rate conversion.
424 1.1 reinoud */
425 1.14.2.1 skrll sample_period = 1000000 / 2 / p->sample_rate;
426 1.14.2.1 skrll if (sample_period < 3) sample_period = 3;
427 1.14.2.5 skrll p->sample_rate = 1000000 / 2 / sample_period;
428 1.14.2.5 skrll hw = *p;
429 1.14.2.5 skrll hw.encoding = AUDIO_ENCODING_NONE;
430 1.14.2.5 skrll hw.precision = 8;
431 1.14.2.1 skrll vidcaudio_rate(sample_period - 2);
432 1.14.2.1 skrll vidcaudio_ctrl(SCR_SDAC | SCR_CLKSEL);
433 1.14.2.5 skrll if (p->channels == 1) {
434 1.14.2.5 skrll pfil->append(pfil, mulaw_to_vidc_stereo, &hw);
435 1.14.2.1 skrll for (ch = 0; ch < 8; ch++)
436 1.14.2.1 skrll vidcaudio_stereo(ch, SIR_CENTRE);
437 1.14.2.5 skrll } else {
438 1.14.2.5 skrll pfil->append(pfil, mulaw_to_vidc, &hw);
439 1.14.2.1 skrll for (ch = 0; ch < 8; ch += 2)
440 1.14.2.1 skrll vidcaudio_stereo(ch, SIR_LEFT_100);
441 1.14.2.1 skrll for (ch = 1; ch < 8; ch += 2)
442 1.14.2.1 skrll vidcaudio_stereo(ch, SIR_RIGHT_100);
443 1.1 reinoud }
444 1.1 reinoud }
445 1.1 reinoud return 0;
446 1.1 reinoud }
447 1.1 reinoud
448 1.14.2.1 skrll static int
449 1.14.2.5 skrll vidcaudio_round_blocksize(void *addr, int wantblk,
450 1.14.2.5 skrll int mode, const audio_params_t *param)
451 1.1 reinoud {
452 1.14.2.1 skrll int blk;
453 1.14.2.1 skrll
454 1.14.2.5 skrll /*
455 1.14.2.1 skrll * Find the smallest power of two that's larger than the
456 1.14.2.1 skrll * requested block size, but don't allow < 32 (DMA burst is 16
457 1.14.2.1 skrll * bytes, and single bursts are tricky) or > PAGE_SIZE (DMA is
458 1.14.2.1 skrll * confined to a page).
459 1.14.2.1 skrll */
460 1.14.2.1 skrll
461 1.14.2.1 skrll for (blk = 32; blk < PAGE_SIZE; blk <<= 1)
462 1.14.2.5 skrll if (blk >= wantblk)
463 1.14.2.5 skrll return blk;
464 1.14.2.1 skrll return blk;
465 1.1 reinoud }
466 1.1 reinoud
467 1.14.2.1 skrll static int
468 1.14.2.1 skrll vidcaudio_trigger_output(void *addr, void *start, void *end, int blksize,
469 1.14.2.5 skrll void (*intr)(void *), void *arg, const audio_params_t *params)
470 1.1 reinoud {
471 1.14.2.5 skrll struct vidcaudio_softc *sc;
472 1.14.2.1 skrll size_t npages, i;
473 1.14.2.1 skrll
474 1.14.2.1 skrll DPRINTF(("vidcaudio_trigger_output %p-%p/0x%x\n",
475 1.14.2.1 skrll start, end, blksize));
476 1.14.2.1 skrll
477 1.14.2.5 skrll sc = addr;
478 1.14.2.5 skrll KASSERT(blksize == vidcaudio_round_blocksize(addr, blksize, 0, NULL));
479 1.14.2.1 skrll KASSERT((vaddr_t)start % blksize == 0);
480 1.14.2.1 skrll
481 1.14.2.1 skrll sc->sc_pblksize = blksize;
482 1.14.2.1 skrll sc->sc_pbufsize = (char *)end - (char *)start;
483 1.14.2.1 skrll npages = sc->sc_pbufsize >> PGSHIFT;
484 1.14.2.1 skrll if (sc->sc_ppages != NULL)
485 1.14.2.1 skrll free(sc->sc_ppages, M_DEVBUF);
486 1.14.2.1 skrll sc->sc_ppages = malloc(npages * sizeof(paddr_t), M_DEVBUF, M_WAITOK);
487 1.14.2.1 skrll if (sc->sc_ppages == NULL) return ENOMEM;
488 1.14.2.1 skrll for (i = 0; i < npages; i++)
489 1.14.2.1 skrll if (!pmap_extract(pmap_kernel(),
490 1.14.2.1 skrll (vaddr_t)start + i * PAGE_SIZE, &sc->sc_ppages[i]))
491 1.14.2.1 skrll return EIO;
492 1.14.2.1 skrll sc->sc_poffset = 0;
493 1.14.2.1 skrll sc->sc_pintr = intr;
494 1.14.2.1 skrll sc->sc_parg = arg;
495 1.14.2.1 skrll
496 1.14.2.1 skrll IOMD_WRITE_WORD(IOMD_SD0CR, IOMD_DMACR_CLEAR | IOMD_DMACR_QUADWORD);
497 1.14.2.1 skrll IOMD_WRITE_WORD(IOMD_SD0CR, IOMD_DMACR_ENABLE | IOMD_DMACR_QUADWORD);
498 1.14.2.1 skrll
499 1.14.2.1 skrll /*
500 1.14.2.1 skrll * Queue up the first two blocks, but don't tell audio code
501 1.14.2.1 skrll * we're finished with them yet.
502 1.14.2.1 skrll */
503 1.14.2.1 skrll sc->sc_pcountdown = 2;
504 1.14.2.1 skrll
505 1.14.2.1 skrll enable_irq(sc->sc_dma_intr);
506 1.14.2.1 skrll
507 1.14.2.1 skrll return 0;
508 1.1 reinoud }
509 1.1 reinoud
510 1.14.2.1 skrll static int
511 1.14.2.1 skrll vidcaudio_trigger_input(void *addr, void *start, void *end, int blksize,
512 1.14.2.5 skrll void (*intr)(void *), void *arg, const audio_params_t *params)
513 1.1 reinoud {
514 1.14.2.1 skrll
515 1.14.2.1 skrll return ENODEV;
516 1.14.2.1 skrll }
517 1.14.2.1 skrll
518 1.14.2.1 skrll static int
519 1.14.2.1 skrll vidcaudio_halt_output(void *addr)
520 1.14.2.1 skrll {
521 1.14.2.5 skrll struct vidcaudio_softc *sc;
522 1.14.2.1 skrll
523 1.14.2.1 skrll DPRINTF(("vidcaudio_halt_output\n"));
524 1.14.2.5 skrll sc = addr;
525 1.14.2.1 skrll disable_irq(sc->sc_dma_intr);
526 1.14.2.1 skrll IOMD_WRITE_WORD(IOMD_SD0CR, IOMD_DMACR_CLEAR | IOMD_DMACR_QUADWORD);
527 1.1 reinoud return 0;
528 1.1 reinoud }
529 1.1 reinoud
530 1.14.2.1 skrll static int
531 1.14.2.1 skrll vidcaudio_halt_input(void *addr)
532 1.14.2.1 skrll {
533 1.14.2.1 skrll
534 1.14.2.1 skrll return ENODEV;
535 1.14.2.1 skrll }
536 1.14.2.1 skrll
537 1.14.2.1 skrll static int
538 1.14.2.1 skrll vidcaudio_getdev(void *addr, struct audio_device *retp)
539 1.1 reinoud {
540 1.14.2.1 skrll
541 1.1 reinoud *retp = vidcaudio_device;
542 1.1 reinoud return 0;
543 1.1 reinoud }
544 1.1 reinoud
545 1.1 reinoud
546 1.14.2.1 skrll static int
547 1.14.2.1 skrll vidcaudio_set_port(void *addr, mixer_ctrl_t *cp)
548 1.1 reinoud {
549 1.14.2.1 skrll
550 1.1 reinoud return EINVAL;
551 1.1 reinoud }
552 1.1 reinoud
553 1.14.2.1 skrll static int
554 1.14.2.1 skrll vidcaudio_get_port(void *addr, mixer_ctrl_t *cp)
555 1.1 reinoud {
556 1.14.2.1 skrll
557 1.1 reinoud return EINVAL;
558 1.1 reinoud }
559 1.1 reinoud
560 1.14.2.1 skrll static int
561 1.14.2.1 skrll vidcaudio_query_devinfo(void *addr, mixer_devinfo_t *dip)
562 1.1 reinoud {
563 1.14.2.1 skrll
564 1.1 reinoud return ENXIO;
565 1.1 reinoud }
566 1.1 reinoud
567 1.14.2.1 skrll static int
568 1.14.2.1 skrll vidcaudio_get_props(void *addr)
569 1.1 reinoud {
570 1.14.2.1 skrll
571 1.1 reinoud return 0;
572 1.1 reinoud }
573 1.1 reinoud
574 1.14.2.1 skrll static void
575 1.14.2.1 skrll vidcaudio_rate(int rate)
576 1.1 reinoud {
577 1.1 reinoud
578 1.14.2.1 skrll WriteWord(vidc_base, VIDC_SFR | rate);
579 1.1 reinoud }
580 1.1 reinoud
581 1.14.2.1 skrll static void
582 1.14.2.1 skrll vidcaudio_ctrl(int ctrl)
583 1.14.2.1 skrll {
584 1.1 reinoud
585 1.14.2.1 skrll WriteWord(vidc_base, VIDC_SCR | ctrl);
586 1.1 reinoud }
587 1.1 reinoud
588 1.14.2.1 skrll static void
589 1.14.2.1 skrll vidcaudio_stereo(int channel, int position)
590 1.1 reinoud {
591 1.1 reinoud
592 1.14.2.1 skrll channel = channel << 24 | VIDC_SIR0;
593 1.14.2.1 skrll WriteWord(vidc_base, channel | position);
594 1.14.2.1 skrll }
595 1.1 reinoud
596 1.14.2.1 skrll static int
597 1.14.2.1 skrll vidcaudio_intr(void *arg)
598 1.14.2.1 skrll {
599 1.14.2.5 skrll struct vidcaudio_softc *sc;
600 1.14.2.1 skrll int status;
601 1.14.2.1 skrll paddr_t pnext, pend;
602 1.14.2.1 skrll
603 1.14.2.5 skrll sc = arg;
604 1.14.2.1 skrll status = IOMD_READ_BYTE(IOMD_SD0ST);
605 1.14.2.1 skrll DPRINTF(("I[%x]", status));
606 1.14.2.1 skrll if ((status & IOMD_DMAST_INT) == 0)
607 1.1 reinoud return 0;
608 1.1 reinoud
609 1.14.2.1 skrll pnext = sc->sc_ppages[sc->sc_poffset >> PGSHIFT] |
610 1.14.2.1 skrll (sc->sc_poffset & PGOFSET);
611 1.14.2.1 skrll pend = (pnext + sc->sc_pblksize - 16) & IOMD_DMAEND_OFFSET;
612 1.14.2.1 skrll
613 1.14.2.1 skrll switch (status &
614 1.14.2.1 skrll (IOMD_DMAST_OVERRUN | IOMD_DMAST_INT | IOMD_DMAST_BANKB)) {
615 1.14.2.1 skrll
616 1.14.2.1 skrll case (IOMD_DMAST_INT | IOMD_DMAST_BANKA):
617 1.14.2.1 skrll case (IOMD_DMAST_OVERRUN | IOMD_DMAST_INT | IOMD_DMAST_BANKB):
618 1.14.2.1 skrll DPRINTF(("B<0x%08lx,0x%03lx>", pnext, pend));
619 1.14.2.1 skrll IOMD_WRITE_WORD(IOMD_SD0CURB, pnext);
620 1.14.2.1 skrll IOMD_WRITE_WORD(IOMD_SD0ENDB, pend);
621 1.14.2.1 skrll break;
622 1.1 reinoud
623 1.14.2.1 skrll case (IOMD_DMAST_INT | IOMD_DMAST_BANKB):
624 1.14.2.1 skrll case (IOMD_DMAST_OVERRUN | IOMD_DMAST_INT | IOMD_DMAST_BANKA):
625 1.14.2.1 skrll DPRINTF(("A<0x%08lx,0x%03lx>", pnext, pend));
626 1.14.2.1 skrll IOMD_WRITE_WORD(IOMD_SD0CURA, pnext);
627 1.14.2.1 skrll IOMD_WRITE_WORD(IOMD_SD0ENDA, pend);
628 1.14.2.1 skrll break;
629 1.1 reinoud }
630 1.1 reinoud
631 1.14.2.1 skrll sc->sc_poffset += sc->sc_pblksize;
632 1.14.2.1 skrll if (sc->sc_poffset >= sc->sc_pbufsize)
633 1.14.2.1 skrll sc->sc_poffset = 0;
634 1.14.2.5 skrll
635 1.14.2.1 skrll if (sc->sc_pcountdown > 0)
636 1.14.2.1 skrll sc->sc_pcountdown--;
637 1.14.2.1 skrll else
638 1.14.2.1 skrll (*sc->sc_pintr)(sc->sc_parg);
639 1.1 reinoud
640 1.14.2.1 skrll return 1;
641 1.1 reinoud }
642