vidcaudio.c revision 1.12 1 1.12 thorpej /* $NetBSD: vidcaudio.c,v 1.12 2002/10/01 03:10:17 thorpej 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.1 reinoud /*
33 1.1 reinoud * audio driver for the RiscPC 16 bit sound
34 1.1 reinoud *
35 1.1 reinoud * Interfaces with the NetBSD generic audio driver to provide SUN
36 1.1 reinoud * /dev/audio (partial) compatibility.
37 1.1 reinoud */
38 1.1 reinoud
39 1.1 reinoud #include <sys/param.h> /* proc.h */
40 1.5 bjh21
41 1.12 thorpej __KERNEL_RCSID(0, "$NetBSD: vidcaudio.c,v 1.12 2002/10/01 03:10:17 thorpej Exp $");
42 1.5 bjh21
43 1.1 reinoud #include <sys/conf.h> /* autoconfig functions */
44 1.1 reinoud #include <sys/device.h> /* device calls */
45 1.1 reinoud #include <sys/proc.h> /* device calls */
46 1.1 reinoud #include <sys/audioio.h>
47 1.1 reinoud #include <sys/errno.h>
48 1.1 reinoud #include <sys/systm.h>
49 1.1 reinoud
50 1.1 reinoud #include <uvm/uvm_extern.h>
51 1.1 reinoud
52 1.1 reinoud #include <dev/audio_if.h>
53 1.1 reinoud
54 1.4 thorpej #include <machine/intr.h>
55 1.3 thorpej #include <arm/arm32/katelib.h>
56 1.1 reinoud
57 1.5 bjh21 #include <arm/iomd/vidcaudiovar.h>
58 1.1 reinoud #include <arm/iomd/iomdreg.h>
59 1.1 reinoud #include <arm/iomd/iomdvar.h>
60 1.1 reinoud #include <arm/iomd/vidc.h>
61 1.1 reinoud #include <arm/mainbus/mainbus.h>
62 1.1 reinoud #include <arm/iomd/waveform.h>
63 1.1 reinoud #include "vidcaudio.h"
64 1.1 reinoud
65 1.1 reinoud extern int *vidc_base;
66 1.1 reinoud
67 1.1 reinoud #undef DEBUG
68 1.1 reinoud
69 1.1 reinoud struct audio_general {
70 1.8 thorpej vaddr_t silence;
71 1.1 reinoud irqhandler_t ih;
72 1.1 reinoud
73 1.5 bjh21 void (*intr) (void *);
74 1.1 reinoud void *arg;
75 1.1 reinoud
76 1.8 thorpej paddr_t next_cur;
77 1.8 thorpej paddr_t next_end;
78 1.5 bjh21 void (*next_intr) (void *);
79 1.1 reinoud void *next_arg;
80 1.1 reinoud
81 1.1 reinoud int buffer;
82 1.1 reinoud int in_progress;
83 1.1 reinoud
84 1.1 reinoud int open;
85 1.1 reinoud } ag;
86 1.1 reinoud
87 1.1 reinoud struct vidcaudio_softc {
88 1.1 reinoud struct device device;
89 1.1 reinoud
90 1.1 reinoud int open;
91 1.1 reinoud };
92 1.1 reinoud
93 1.1 reinoud int vidcaudio_probe __P((struct device *parent, struct cfdata *cf, void *aux));
94 1.1 reinoud void vidcaudio_attach __P((struct device *parent, struct device *self, void *aux));
95 1.1 reinoud int vidcaudio_open __P((void *addr, int flags));
96 1.1 reinoud void vidcaudio_close __P((void *addr));
97 1.1 reinoud
98 1.1 reinoud int vidcaudio_intr __P((void *arg));
99 1.8 thorpej int vidcaudio_dma_program __P((vaddr_t cur, vaddr_t end, void (*intr)(void *), void *arg));
100 1.1 reinoud void vidcaudio_dummy_routine __P((void *arg));
101 1.1 reinoud int vidcaudio_stereo __P((int channel, int position));
102 1.1 reinoud int vidcaudio_rate __P((int rate));
103 1.1 reinoud void vidcaudio_shutdown __P((void));
104 1.1 reinoud
105 1.1 reinoud static int sound_dma_intr;
106 1.1 reinoud
107 1.12 thorpej CFATTACH_DECL(vidcaudio, sizeof(struct vidcaudio_softc),
108 1.12 thorpej vidcaudio_probe, vidcaudio_attach, NULL, NULL)
109 1.1 reinoud
110 1.1 reinoud int vidcaudio_query_encoding __P((void *, struct audio_encoding *));
111 1.1 reinoud int vidcaudio_set_params __P((void *, int, int, struct audio_params *, struct audio_params *));
112 1.1 reinoud int vidcaudio_round_blocksize __P((void *, int));
113 1.5 bjh21 int vidcaudio_start_output __P((void *, void *, int, void (*)(void *),
114 1.5 bjh21 void *));
115 1.5 bjh21 int vidcaudio_start_input __P((void *, void *, int, void (*)(void *),
116 1.5 bjh21 void *));
117 1.1 reinoud int vidcaudio_halt_output __P((void *));
118 1.1 reinoud int vidcaudio_halt_input __P((void *));
119 1.1 reinoud int vidcaudio_speaker_ctl __P((void *, int));
120 1.1 reinoud int vidcaudio_getdev __P((void *, struct audio_device *));
121 1.1 reinoud int vidcaudio_set_port __P((void *, mixer_ctrl_t *));
122 1.1 reinoud int vidcaudio_get_port __P((void *, mixer_ctrl_t *));
123 1.1 reinoud int vidcaudio_query_devinfo __P((void *, mixer_devinfo_t *));
124 1.1 reinoud int vidcaudio_get_props __P((void *));
125 1.1 reinoud
126 1.1 reinoud struct audio_device vidcaudio_device = {
127 1.1 reinoud "VidcAudio 8-bit",
128 1.1 reinoud "x",
129 1.1 reinoud "vidcaudio"
130 1.1 reinoud };
131 1.1 reinoud
132 1.1 reinoud struct audio_hw_if vidcaudio_hw_if = {
133 1.1 reinoud vidcaudio_open,
134 1.1 reinoud vidcaudio_close,
135 1.1 reinoud 0,
136 1.1 reinoud vidcaudio_query_encoding,
137 1.1 reinoud vidcaudio_set_params,
138 1.1 reinoud vidcaudio_round_blocksize,
139 1.1 reinoud 0,
140 1.1 reinoud 0,
141 1.1 reinoud 0,
142 1.1 reinoud vidcaudio_start_output,
143 1.1 reinoud vidcaudio_start_input,
144 1.1 reinoud vidcaudio_halt_output,
145 1.1 reinoud vidcaudio_halt_input,
146 1.1 reinoud vidcaudio_speaker_ctl,
147 1.1 reinoud vidcaudio_getdev,
148 1.1 reinoud 0,
149 1.1 reinoud vidcaudio_set_port,
150 1.1 reinoud vidcaudio_get_port,
151 1.1 reinoud vidcaudio_query_devinfo,
152 1.1 reinoud 0,
153 1.1 reinoud 0,
154 1.1 reinoud 0,
155 1.1 reinoud 0,
156 1.1 reinoud vidcaudio_get_props,
157 1.1 reinoud 0,
158 1.1 reinoud 0,
159 1.1 reinoud 0,
160 1.1 reinoud };
161 1.1 reinoud
162 1.1 reinoud
163 1.1 reinoud void
164 1.1 reinoud vidcaudio_beep_generate()
165 1.1 reinoud {
166 1.1 reinoud vidcaudio_dma_program(ag.silence, ag.silence+sizeof(beep_waveform)-16,
167 1.1 reinoud vidcaudio_dummy_routine, NULL);
168 1.1 reinoud }
169 1.1 reinoud
170 1.1 reinoud
171 1.1 reinoud int
172 1.1 reinoud vidcaudio_probe(parent, cf, aux)
173 1.1 reinoud struct device *parent;
174 1.1 reinoud struct cfdata* cf;
175 1.1 reinoud void *aux;
176 1.1 reinoud {
177 1.1 reinoud int id;
178 1.1 reinoud
179 1.1 reinoud id = IOMD_ID;
180 1.1 reinoud
181 1.1 reinoud /* So far I only know about this IOMD */
182 1.1 reinoud switch (id) {
183 1.1 reinoud case RPC600_IOMD_ID:
184 1.1 reinoud return(1);
185 1.1 reinoud break;
186 1.1 reinoud case ARM7500_IOC_ID:
187 1.1 reinoud case ARM7500FE_IOC_ID:
188 1.1 reinoud return(1);
189 1.1 reinoud break;
190 1.1 reinoud default:
191 1.1 reinoud printf("vidcaudio: Unknown IOMD id=%04x", id);
192 1.1 reinoud break;
193 1.1 reinoud }
194 1.1 reinoud
195 1.1 reinoud return (0);
196 1.1 reinoud }
197 1.1 reinoud
198 1.1 reinoud
199 1.1 reinoud void
200 1.1 reinoud vidcaudio_attach(parent, self, aux)
201 1.1 reinoud struct device *parent;
202 1.1 reinoud struct device *self;
203 1.1 reinoud void *aux;
204 1.1 reinoud {
205 1.1 reinoud struct vidcaudio_softc *sc = (void *)self;
206 1.1 reinoud int id;
207 1.1 reinoud
208 1.1 reinoud sc->open = 0;
209 1.1 reinoud ag.in_progress = 0;
210 1.1 reinoud
211 1.1 reinoud ag.next_cur = 0;
212 1.1 reinoud ag.next_end = 0;
213 1.1 reinoud ag.next_intr = NULL;
214 1.1 reinoud ag.next_arg = NULL;
215 1.1 reinoud
216 1.1 reinoud vidcaudio_rate(32); /* 24*1024*/
217 1.1 reinoud
218 1.1 reinoud /* Program the silence buffer and reset the DMA channel */
219 1.1 reinoud ag.silence = uvm_km_alloc(kernel_map, NBPG);
220 1.1 reinoud if (ag.silence == NULL)
221 1.10 provos panic("vidcaudio: Cannot allocate memory");
222 1.1 reinoud
223 1.1 reinoud memset((char *)ag.silence, 0, NBPG);
224 1.1 reinoud memcpy((char *)ag.silence, (char *)beep_waveform, sizeof(beep_waveform));
225 1.1 reinoud
226 1.1 reinoud ag.buffer = 0;
227 1.1 reinoud
228 1.1 reinoud /* Install the irq handler for the DMA interrupt */
229 1.1 reinoud ag.ih.ih_func = vidcaudio_intr;
230 1.1 reinoud ag.ih.ih_arg = NULL;
231 1.1 reinoud ag.ih.ih_level = IPL_AUDIO;
232 1.1 reinoud ag.ih.ih_name = "vidcaudio";
233 1.1 reinoud
234 1.1 reinoud ag.intr = NULL;
235 1.1 reinoud /* ag.nextintr = NULL;*/
236 1.1 reinoud
237 1.1 reinoud id = IOMD_ID;
238 1.1 reinoud
239 1.1 reinoud switch (id) {
240 1.1 reinoud case RPC600_IOMD_ID:
241 1.1 reinoud sound_dma_intr = IRQ_DMASCH0;
242 1.1 reinoud break;
243 1.1 reinoud case ARM7500_IOC_ID:
244 1.1 reinoud case ARM7500FE_IOC_ID:
245 1.1 reinoud sound_dma_intr = IRQ_SDMA;
246 1.1 reinoud break;
247 1.1 reinoud }
248 1.1 reinoud
249 1.1 reinoud disable_irq(sound_dma_intr);
250 1.1 reinoud
251 1.1 reinoud if (irq_claim(sound_dma_intr, &(ag.ih)))
252 1.10 provos panic("vidcaudio: couldn't claim IRQ %d", sound_dma_intr);
253 1.1 reinoud
254 1.1 reinoud disable_irq(sound_dma_intr);
255 1.1 reinoud
256 1.1 reinoud printf("\n");
257 1.1 reinoud
258 1.1 reinoud vidcaudio_dma_program(ag.silence, ag.silence+NBPG-16,
259 1.1 reinoud vidcaudio_dummy_routine, NULL);
260 1.1 reinoud
261 1.1 reinoud audio_attach_mi(&vidcaudio_hw_if, sc, &sc->device);
262 1.1 reinoud
263 1.1 reinoud #ifdef DEBUG
264 1.1 reinoud printf(" UNDER DEVELOPMENT (nuts)\n");
265 1.1 reinoud #endif
266 1.1 reinoud }
267 1.1 reinoud
268 1.1 reinoud int
269 1.1 reinoud vidcaudio_open(addr, flags)
270 1.1 reinoud void *addr;
271 1.1 reinoud int flags;
272 1.1 reinoud {
273 1.1 reinoud struct vidcaudio_softc *sc = addr;
274 1.1 reinoud
275 1.1 reinoud #ifdef DEBUG
276 1.1 reinoud printf("DEBUG: vidcaudio_open called\n");
277 1.1 reinoud #endif
278 1.1 reinoud
279 1.1 reinoud if (sc->open)
280 1.1 reinoud return EBUSY;
281 1.1 reinoud
282 1.1 reinoud sc->open = 1;
283 1.1 reinoud ag.open = 1;
284 1.1 reinoud
285 1.1 reinoud return 0;
286 1.1 reinoud }
287 1.1 reinoud
288 1.1 reinoud void
289 1.1 reinoud vidcaudio_close(addr)
290 1.1 reinoud void *addr;
291 1.1 reinoud {
292 1.1 reinoud struct vidcaudio_softc *sc = addr;
293 1.1 reinoud
294 1.1 reinoud vidcaudio_shutdown();
295 1.1 reinoud
296 1.1 reinoud #ifdef DEBUG
297 1.1 reinoud printf("DEBUG: vidcaudio_close called\n");
298 1.1 reinoud #endif
299 1.1 reinoud
300 1.1 reinoud sc->open = 0;
301 1.1 reinoud ag.open = 0;
302 1.1 reinoud }
303 1.1 reinoud
304 1.1 reinoud /* ************************************************************************* *
305 1.1 reinoud | Interface to the generic audio driver |
306 1.1 reinoud * ************************************************************************* */
307 1.1 reinoud
308 1.1 reinoud int
309 1.1 reinoud vidcaudio_query_encoding(addr, fp)
310 1.1 reinoud void *addr;
311 1.1 reinoud struct audio_encoding *fp;
312 1.1 reinoud {
313 1.1 reinoud switch (fp->index) {
314 1.1 reinoud case 0:
315 1.1 reinoud strcpy(fp->name, "vidc");
316 1.1 reinoud fp->encoding = AUDIO_ENCODING_ULAW;
317 1.1 reinoud fp->precision = 8;
318 1.1 reinoud fp->flags = 0;
319 1.1 reinoud break;
320 1.1 reinoud
321 1.1 reinoud default:
322 1.1 reinoud return(EINVAL);
323 1.1 reinoud }
324 1.1 reinoud return 0;
325 1.1 reinoud }
326 1.1 reinoud
327 1.1 reinoud int
328 1.1 reinoud vidcaudio_set_params(addr, setmode, usemode, p, r)
329 1.1 reinoud void *addr;
330 1.1 reinoud int setmode, usemode;
331 1.1 reinoud struct audio_params *p, *r;
332 1.1 reinoud {
333 1.1 reinoud if (p->encoding != AUDIO_ENCODING_ULAW ||
334 1.1 reinoud p->channels != 8)
335 1.1 reinoud return EINVAL;
336 1.1 reinoud vidcaudio_rate(4 * p->sample_rate / (3 * 1024)); /* XXX probably wrong */
337 1.1 reinoud
338 1.1 reinoud return 0;
339 1.1 reinoud }
340 1.1 reinoud
341 1.1 reinoud int
342 1.1 reinoud vidcaudio_round_blocksize(addr, blk)
343 1.1 reinoud void *addr;
344 1.1 reinoud int blk;
345 1.1 reinoud {
346 1.1 reinoud if (blk > NBPG)
347 1.1 reinoud blk = NBPG;
348 1.1 reinoud return (blk);
349 1.1 reinoud }
350 1.1 reinoud
351 1.1 reinoud #define ROUND(s) ( ((int)s) & (~(NBPG-1)) )
352 1.1 reinoud
353 1.1 reinoud int
354 1.1 reinoud vidcaudio_start_output(addr, p, cc, intr, arg)
355 1.1 reinoud void *addr;
356 1.1 reinoud void *p;
357 1.1 reinoud int cc;
358 1.5 bjh21 void (*intr)(void *);
359 1.1 reinoud void *arg;
360 1.1 reinoud {
361 1.1 reinoud /* I can only DMA inside 1 page */
362 1.1 reinoud
363 1.1 reinoud #ifdef DEBUG
364 1.1 reinoud printf("vidcaudio_start_output (%d) %08x %08x\n", cc, intr, arg);
365 1.1 reinoud #endif
366 1.1 reinoud
367 1.1 reinoud if (ROUND(p) != ROUND(p+cc)) {
368 1.1 reinoud /*
369 1.1 reinoud * If it's over a page I can fix it up by copying it into
370 1.1 reinoud * my buffer
371 1.1 reinoud */
372 1.1 reinoud
373 1.1 reinoud #ifdef DEBUG
374 1.1 reinoud printf("vidcaudio: DMA over page boundary requested."
375 1.1 reinoud " Fixing up\n");
376 1.1 reinoud #endif
377 1.1 reinoud memcpy(p, (char *)ag.silence, cc > NBPG ? NBPG : cc);
378 1.1 reinoud p = (void *)ag.silence;
379 1.1 reinoud
380 1.1 reinoud /*
381 1.1 reinoud * I can't DMA any more than that, but it is possible to
382 1.1 reinoud * fix it up by handling multiple buffers and only
383 1.1 reinoud * interrupting the audio driver after sending out all the
384 1.1 reinoud * stuff it gave me. That it more than I can be bothered
385 1.1 reinoud * to do right now and it probablly wont happen so I'll just
386 1.1 reinoud * truncate the buffer and tell the user.
387 1.1 reinoud */
388 1.1 reinoud
389 1.1 reinoud if (cc > NBPG) {
390 1.1 reinoud printf("vidcaudio: DMA buffer truncated. I could fix this up\n");
391 1.1 reinoud cc = NBPG;
392 1.1 reinoud }
393 1.1 reinoud }
394 1.8 thorpej vidcaudio_dma_program((vaddr_t)p, (vaddr_t)((char *)p+cc),
395 1.1 reinoud intr, arg);
396 1.1 reinoud return 0;
397 1.1 reinoud }
398 1.1 reinoud
399 1.1 reinoud int
400 1.1 reinoud vidcaudio_start_input(addr, p, cc, intr, arg)
401 1.1 reinoud void *addr;
402 1.1 reinoud void *p;
403 1.1 reinoud int cc;
404 1.5 bjh21 void (*intr)(void *);
405 1.1 reinoud void *arg;
406 1.1 reinoud {
407 1.1 reinoud return EIO;
408 1.1 reinoud }
409 1.1 reinoud
410 1.1 reinoud int
411 1.1 reinoud vidcaudio_halt_output(addr)
412 1.1 reinoud void *addr;
413 1.1 reinoud {
414 1.1 reinoud #ifdef DEBUG
415 1.1 reinoud printf("DEBUG: vidcaudio_halt_output\n");
416 1.1 reinoud #endif
417 1.1 reinoud return EIO;
418 1.1 reinoud }
419 1.1 reinoud
420 1.1 reinoud int
421 1.1 reinoud vidcaudio_halt_input(addr)
422 1.1 reinoud void *addr;
423 1.1 reinoud {
424 1.1 reinoud #ifdef DEBUG
425 1.1 reinoud printf("DEBUG: vidcaudio_halt_input\n");
426 1.1 reinoud #endif
427 1.1 reinoud return EIO;
428 1.1 reinoud }
429 1.1 reinoud
430 1.1 reinoud int
431 1.1 reinoud vidcaudio_speaker_ctl(addr, newstate)
432 1.1 reinoud void *addr;
433 1.1 reinoud int newstate;
434 1.1 reinoud {
435 1.1 reinoud #ifdef DEBUG
436 1.1 reinoud printf("DEBUG: vidcaudio_speaker_ctl\n");
437 1.1 reinoud #endif
438 1.1 reinoud return 0;
439 1.1 reinoud }
440 1.1 reinoud
441 1.1 reinoud int
442 1.1 reinoud vidcaudio_getdev(addr, retp)
443 1.1 reinoud void *addr;
444 1.1 reinoud struct audio_device *retp;
445 1.1 reinoud {
446 1.1 reinoud *retp = vidcaudio_device;
447 1.1 reinoud return 0;
448 1.1 reinoud }
449 1.1 reinoud
450 1.1 reinoud
451 1.1 reinoud int
452 1.1 reinoud vidcaudio_set_port(addr, cp)
453 1.1 reinoud void *addr;
454 1.1 reinoud mixer_ctrl_t *cp;
455 1.1 reinoud {
456 1.1 reinoud return EINVAL;
457 1.1 reinoud }
458 1.1 reinoud
459 1.1 reinoud int
460 1.1 reinoud vidcaudio_get_port(addr, cp)
461 1.1 reinoud void *addr;
462 1.1 reinoud mixer_ctrl_t *cp;
463 1.1 reinoud {
464 1.1 reinoud return EINVAL;
465 1.1 reinoud }
466 1.1 reinoud
467 1.1 reinoud int
468 1.1 reinoud vidcaudio_query_devinfo(addr, dip)
469 1.1 reinoud void *addr;
470 1.1 reinoud mixer_devinfo_t *dip;
471 1.1 reinoud {
472 1.1 reinoud return ENXIO;
473 1.1 reinoud }
474 1.1 reinoud
475 1.1 reinoud int
476 1.1 reinoud vidcaudio_get_props(addr)
477 1.1 reinoud void *addr;
478 1.1 reinoud {
479 1.1 reinoud return 0;
480 1.1 reinoud }
481 1.1 reinoud void
482 1.1 reinoud vidcaudio_dummy_routine(arg)
483 1.1 reinoud void *arg;
484 1.1 reinoud {
485 1.1 reinoud #ifdef DEBUG
486 1.1 reinoud printf("vidcaudio_dummy_routine\n");
487 1.1 reinoud #endif
488 1.1 reinoud }
489 1.1 reinoud
490 1.1 reinoud int
491 1.1 reinoud vidcaudio_rate(rate)
492 1.1 reinoud int rate;
493 1.1 reinoud {
494 1.1 reinoud WriteWord(vidc_base, VIDC_SFR | rate);
495 1.1 reinoud return 0;
496 1.1 reinoud }
497 1.1 reinoud
498 1.1 reinoud int
499 1.1 reinoud vidcaudio_stereo(channel, position)
500 1.1 reinoud int channel;
501 1.1 reinoud int position;
502 1.1 reinoud {
503 1.1 reinoud if (channel < 0) return EINVAL;
504 1.1 reinoud if (channel > 7) return EINVAL;
505 1.1 reinoud channel = channel<<24 | VIDC_SIR0;
506 1.1 reinoud WriteWord(vidc_base, channel | position);
507 1.1 reinoud return 0;
508 1.1 reinoud }
509 1.1 reinoud
510 1.7 thorpej #define PHYS(x, y) pmap_extract(pmap_kernel(), ((x)&L2_S_FRAME), (paddr_t *)(y))
511 1.1 reinoud
512 1.1 reinoud /*
513 1.1 reinoud * Program the next buffer to be used
514 1.1 reinoud * This function must be re-entrant, maximum re-entrancy of 2
515 1.1 reinoud */
516 1.1 reinoud
517 1.1 reinoud #define FLAGS (0)
518 1.1 reinoud
519 1.1 reinoud int
520 1.1 reinoud vidcaudio_dma_program(cur, end, intr, arg)
521 1.8 thorpej vaddr_t cur;
522 1.8 thorpej vaddr_t end;
523 1.5 bjh21 void (*intr)(void *);
524 1.1 reinoud void *arg;
525 1.1 reinoud {
526 1.1 reinoud paddr_t pa1, pa2;
527 1.1 reinoud
528 1.1 reinoud /* If there isn't a transfer in progress then start a new one */
529 1.1 reinoud if (ag.in_progress == 0) {
530 1.1 reinoud ag.buffer = 0;
531 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0CR, 0x90); /* Reset State Machine */
532 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0CR, 0x30); /* Reset State Machine */
533 1.1 reinoud
534 1.1 reinoud PHYS(cur, &pa1);
535 1.1 reinoud PHYS(end - 16, &pa2);
536 1.1 reinoud
537 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0CURB, pa1);
538 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0ENDB, pa2|FLAGS);
539 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0CURA, pa1);
540 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0ENDA, pa2|FLAGS);
541 1.1 reinoud
542 1.1 reinoud ag.in_progress = 1;
543 1.1 reinoud
544 1.1 reinoud ag.next_cur = ag.next_end = 0;
545 1.1 reinoud ag.next_intr = ag.next_arg = 0;
546 1.1 reinoud
547 1.1 reinoud ag.intr = intr;
548 1.1 reinoud ag.arg = arg;
549 1.1 reinoud
550 1.1 reinoud /*
551 1.1 reinoud * The driver 'clicks' between buffer swaps, leading me
552 1.1 reinoud * to think that the fifo is much small than on other
553 1.1 reinoud * sound cards so I'm going to have to do some tricks here
554 1.1 reinoud */
555 1.1 reinoud
556 1.1 reinoud (*ag.intr)(ag.arg); /* Schedule the next buffer */
557 1.1 reinoud ag.intr = vidcaudio_dummy_routine; /* Already done this */
558 1.1 reinoud ag.arg = NULL;
559 1.1 reinoud
560 1.1 reinoud #ifdef PRINT
561 1.1 reinoud printf("vidcaudio: start output\n");
562 1.1 reinoud #endif
563 1.1 reinoud #ifdef DEBUG
564 1.1 reinoud printf("SE");
565 1.1 reinoud #endif
566 1.1 reinoud enable_irq(sound_dma_intr);
567 1.1 reinoud } else {
568 1.1 reinoud /* Otherwise schedule the next one */
569 1.1 reinoud if (ag.next_cur != 0) {
570 1.1 reinoud /* If there's one scheduled then complain */
571 1.1 reinoud printf("vidcaudio: Buffer already Q'ed\n");
572 1.1 reinoud return EIO;
573 1.1 reinoud } else {
574 1.1 reinoud /* We're OK to schedule it now */
575 1.1 reinoud ag.buffer = (++ag.buffer) & 1;
576 1.1 reinoud PHYS(cur, &ag.next_cur);
577 1.1 reinoud PHYS(end - 16, &ag.next_end);
578 1.1 reinoud ag.next_intr = intr;
579 1.1 reinoud ag.next_arg = arg;
580 1.1 reinoud #ifdef DEBUG
581 1.1 reinoud printf("s");
582 1.1 reinoud #endif
583 1.1 reinoud }
584 1.1 reinoud }
585 1.1 reinoud return 0;
586 1.1 reinoud }
587 1.1 reinoud
588 1.1 reinoud void
589 1.1 reinoud vidcaudio_shutdown(void)
590 1.1 reinoud {
591 1.1 reinoud /* Shut down the channel */
592 1.1 reinoud ag.intr = NULL;
593 1.1 reinoud ag.in_progress = 0;
594 1.1 reinoud #ifdef PRINT
595 1.1 reinoud printf("vidcaudio: stop output\n");
596 1.1 reinoud #endif
597 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0CURB, ag.silence);
598 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0ENDB, (ag.silence + NBPG - 16) | (1<<30));
599 1.1 reinoud disable_irq(sound_dma_intr);
600 1.1 reinoud }
601 1.1 reinoud
602 1.1 reinoud int
603 1.1 reinoud vidcaudio_intr(arg)
604 1.1 reinoud void *arg;
605 1.1 reinoud {
606 1.1 reinoud int status = IOMD_READ_BYTE(IOMD_SD0ST);
607 1.5 bjh21 void (*nintr)(void *);
608 1.1 reinoud void *narg;
609 1.5 bjh21 void (*xintr)(void *);
610 1.1 reinoud void *xarg;
611 1.1 reinoud int xcur, xend;
612 1.1 reinoud IOMD_WRITE_WORD(IOMD_DMARQ, 0x10);
613 1.1 reinoud
614 1.1 reinoud #ifdef PRINT
615 1.1 reinoud printf ( "I" );
616 1.1 reinoud #endif
617 1.1 reinoud
618 1.1 reinoud if (ag.open == 0) {
619 1.1 reinoud vidcaudio_shutdown();
620 1.1 reinoud return 0;
621 1.1 reinoud }
622 1.1 reinoud
623 1.1 reinoud /* Have I got the generic audio device attached */
624 1.1 reinoud
625 1.1 reinoud #ifdef DEBUG
626 1.1 reinoud printf ( "[B%01x]", status );
627 1.1 reinoud #endif
628 1.1 reinoud
629 1.1 reinoud nintr = ag.intr;
630 1.1 reinoud narg = ag.arg;
631 1.1 reinoud ag.intr = NULL;
632 1.1 reinoud
633 1.1 reinoud xintr = ag.next_intr;
634 1.1 reinoud xarg = ag.next_arg;
635 1.1 reinoud xcur = ag.next_cur;
636 1.1 reinoud xend = ag.next_end;
637 1.1 reinoud ag.next_cur = 0;
638 1.1 reinoud ag.intr = xintr;
639 1.1 reinoud ag.arg = xarg;
640 1.1 reinoud
641 1.1 reinoud if (nintr) {
642 1.1 reinoud #ifdef DEBUG
643 1.1 reinoud printf("i");
644 1.1 reinoud #endif
645 1.1 reinoud (*nintr)(narg);
646 1.1 reinoud }
647 1.1 reinoud
648 1.1 reinoud if (xcur == 0) {
649 1.1 reinoud vidcaudio_shutdown ();
650 1.1 reinoud } else {
651 1.1 reinoud #define OVERRUN (0x04)
652 1.1 reinoud #define INTERRUPT (0x02)
653 1.1 reinoud #define BANK_A (0x00)
654 1.1 reinoud #define BANK_B (0x01)
655 1.1 reinoud switch (status & 0x7) {
656 1.1 reinoud case (INTERRUPT|BANK_A):
657 1.1 reinoud #ifdef PRINT
658 1.1 reinoud printf("B");
659 1.1 reinoud #endif
660 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0CURB, xcur);
661 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0ENDB, xend|FLAGS);
662 1.1 reinoud break;
663 1.1 reinoud
664 1.1 reinoud case (INTERRUPT|BANK_B):
665 1.1 reinoud #ifdef PRINT
666 1.1 reinoud printf("A");
667 1.1 reinoud #endif
668 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0CURA, xcur);
669 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0ENDA, xend|FLAGS);
670 1.1 reinoud break;
671 1.1 reinoud
672 1.1 reinoud case (OVERRUN|INTERRUPT|BANK_A):
673 1.1 reinoud #ifdef PRINT
674 1.1 reinoud printf("A");
675 1.1 reinoud #endif
676 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0CURA, xcur);
677 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0ENDA, xend|FLAGS);
678 1.1 reinoud break;
679 1.1 reinoud
680 1.1 reinoud case (OVERRUN|INTERRUPT|BANK_B):
681 1.1 reinoud #ifdef PRINT
682 1.1 reinoud printf("B");
683 1.1 reinoud #endif
684 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0CURB, xcur);
685 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0ENDB, xend|FLAGS);
686 1.1 reinoud break;
687 1.1 reinoud }
688 1.1 reinoud /*
689 1.1 reinoud ag.next_cur = 0;
690 1.1 reinoud ag.intr = xintr;
691 1.1 reinoud ag.arg = xarg;
692 1.1 reinoud */
693 1.1 reinoud }
694 1.1 reinoud #ifdef PRINT
695 1.1 reinoud printf ( "i" );
696 1.1 reinoud #endif
697 1.1 reinoud
698 1.1 reinoud if (ag.next_cur == 0) {
699 1.1 reinoud (*ag.intr)(ag.arg); /* Schedule the next buffer */
700 1.1 reinoud ag.intr = vidcaudio_dummy_routine; /* Already done this */
701 1.1 reinoud ag.arg = NULL;
702 1.1 reinoud }
703 1.1 reinoud return(0); /* Pass interrupt on down the chain */
704 1.1 reinoud }
705